-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_script_auto.py
82 lines (62 loc) · 2.35 KB
/
write_script_auto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import os
import json
from module.font_table import check_file, FontTable
from module.script import write_scripts
from check_script import check_script, diff_address
def main():
src_path = "../workspace/Macross2_jpn"
dst_path = "../workspace/Macross2_final"
script_path = "../workspace/script"
dst_font_table_path = "font_table/font_table-jin.json"
# ===================================================================
files = os.listdir(src_path)
for file in files:
src_data_path = f"{src_path}/{file}"
dst_data_path = f"{dst_path}/{file}"
if not os.path.isfile(src_data_path):
continue
print(f"{file} ===========================================")
tag = file
src_script_path = f"{script_path}/{tag}_jpn.json"
dst_script_path = f"{script_path}/{tag}_kor.json"
if not os.path.isfile(src_script_path):
continue
if not os.path.isfile(dst_script_path):
continue
# read scripts
print(src_script_path)
with open(src_script_path, "r") as f:
src_scripts = json.load(f)
print(dst_script_path)
with open(dst_script_path, "r") as f:
dst_scripts = json.load(f)
# read a font table
if not check_file(dst_font_table_path):
return
font_table = FontTable(dst_font_table_path)
# check address
count_diff = diff_address(src_scripts, dst_scripts)
if count_diff:
return
# check scripts
count_false_length, count_false_letters = check_script(dst_scripts, font_table)
print(
f"False sentence length and letter count: {count_false_length}, {count_false_letters}"
)
if count_false_length or count_false_letters:
print("False sentence length or letters should be fixed.")
return
# read the target (jpn) data
if not check_file(src_data_path):
return
with open(src_data_path, "rb") as f:
data = f.read()
data = bytearray(data)
print(f"Data size: {src_data_path}({len(data):,} bytes)")
# write scripts
data = write_scripts(data, font_table, dst_scripts)
# save data
with open(dst_data_path, "wb") as f:
f.write(data)
if __name__ == "__main__":
main()