BLACKED
This commit is contained in:
parent
03e51318b0
commit
b6c3c6a454
10 changed files with 819 additions and 654 deletions
127
utage/names.py
127
utage/names.py
|
|
@ -8,74 +8,95 @@ from functools import partial
|
|||
from glob import glob
|
||||
from multiprocessing import Pool
|
||||
|
||||
|
||||
def update_names(dir_in, old_path, languages):
|
||||
names = extract_names(dir_in)
|
||||
names = extract_names(dir_in)
|
||||
|
||||
# we have to update japanese like the rest because CustomData exists
|
||||
# and POKELABO deleted the wedding gear event stuff from the game files
|
||||
for l in languages:
|
||||
if l == "jpn":
|
||||
out_dict = dict(zip(names, names))
|
||||
else:
|
||||
out_dict = dict.fromkeys(names, "")
|
||||
# we have to update japanese like the rest because CustomData exists
|
||||
# and POKELABO deleted the wedding gear event stuff from the game files
|
||||
for l in languages:
|
||||
if l == "jpn":
|
||||
out_dict = dict(zip(names, names))
|
||||
else:
|
||||
out_dict = dict.fromkeys(names, "")
|
||||
|
||||
langfile = os.path.join(old_path, "nametranslations_{}.json".format(l))
|
||||
if os.path.isfile(langfile):
|
||||
with open(langfile, "r") as lang_file:
|
||||
lang_dict = json.load(lang_file)
|
||||
out_dict.update(lang_dict)
|
||||
langfile = os.path.join(old_path, "nametranslations_{}.json".format(l))
|
||||
if os.path.isfile(langfile):
|
||||
with open(langfile, "r") as lang_file:
|
||||
lang_dict = json.load(lang_file)
|
||||
out_dict.update(lang_dict)
|
||||
|
||||
with io.open(
|
||||
langfile, "w", newline="\n"
|
||||
) as lang_file: # you're using git right
|
||||
json.dump(
|
||||
out_dict, lang_file, ensure_ascii=False, indent="\t", sort_keys=True
|
||||
)
|
||||
|
||||
with io.open(langfile, "w", newline='\n') as lang_file: # you're using git right
|
||||
json.dump(out_dict, lang_file, ensure_ascii=False, indent='\t', sort_keys=True)
|
||||
|
||||
def extract_names(dir_in):
|
||||
char_tsv_path = os.path.join(dir_in, "Diva", "Settings", "Character.tsv")
|
||||
char_tsv_path = os.path.join(dir_in, "Diva", "Settings", "Character.tsv")
|
||||
|
||||
if not os.path.isfile(char_tsv_path):
|
||||
raise FileNotFoundError("Character.tsv not found")
|
||||
if not os.path.isfile(char_tsv_path):
|
||||
raise FileNotFoundError("Character.tsv not found")
|
||||
|
||||
names, sets = read_char_tsv(char_tsv_path)
|
||||
names, sets = read_char_tsv(char_tsv_path)
|
||||
|
||||
files = [f for f in glob(os.path.join(dir_in, "**/*.tsv"), recursive=True) if re.search(r'/[0-9]{9}\.tsv$', f)]
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
files = [
|
||||
f
|
||||
for f in glob(os.path.join(dir_in, "**/*.tsv"), recursive=True)
|
||||
if re.search(r"/[0-9]{9}\.tsv$", f)
|
||||
]
|
||||
if len(files) == 0:
|
||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||
|
||||
# tfw gil
|
||||
# it's still faster on my machine so i'm keeping it
|
||||
read_partial = partial(read_mission, char_names=names, char_sets=sets)
|
||||
with Pool() as p:
|
||||
new_names = p.map(read_partial, files)
|
||||
for x in new_names:
|
||||
names.update(x)
|
||||
# tfw gil
|
||||
# it's still faster on my machine so i'm keeping it
|
||||
read_partial = partial(read_mission, char_names=names, char_sets=sets)
|
||||
with Pool() as p:
|
||||
new_names = p.map(read_partial, files)
|
||||
for x in new_names:
|
||||
names.update(x)
|
||||
|
||||
return names
|
||||
|
||||
return names
|
||||
|
||||
def read_char_tsv(char_tsv_path):
|
||||
char_names = set()
|
||||
char_sets = set()
|
||||
char_names = set()
|
||||
char_sets = set()
|
||||
|
||||
with open(char_tsv_path, "r") as char_tsv_file:
|
||||
char_tsv = csv.DictReader(char_tsv_file, delimiter="\t", quotechar="\"")
|
||||
with open(char_tsv_path, "r") as char_tsv_file:
|
||||
char_tsv = csv.DictReader(char_tsv_file, delimiter="\t", quotechar='"')
|
||||
|
||||
for row in char_tsv:
|
||||
if row['CharacterName'].startswith("//"):
|
||||
continue
|
||||
if row['CharacterName'] and row['NameText'] and row['CharacterName'].strip() and row['NameText'].strip():
|
||||
char_names.add(row['NameText'])
|
||||
char_sets.add(row['CharacterName'])
|
||||
for row in char_tsv:
|
||||
if row["CharacterName"].startswith("//"):
|
||||
continue
|
||||
if (
|
||||
row["CharacterName"]
|
||||
and row["NameText"]
|
||||
and row["CharacterName"].strip()
|
||||
and row["NameText"].strip()
|
||||
):
|
||||
char_names.add(row["NameText"])
|
||||
char_sets.add(row["CharacterName"])
|
||||
|
||||
return char_names, char_sets
|
||||
|
||||
return char_names, char_sets
|
||||
|
||||
def read_mission(tsv_path, char_names, char_sets):
|
||||
new_names = set()
|
||||
with open(tsv_path, "r") as tsv_file:
|
||||
tsv = csv.DictReader(tsv_file, delimiter="\t", quotechar="\"")
|
||||
if ('Arg1' not in tsv.fieldnames) or ('Text' not in tsv.fieldnames) or ('Command' not in tsv.fieldnames):
|
||||
return new_names
|
||||
for row in tsv:
|
||||
if row['Command'] and row['Command'].startswith("//"):
|
||||
continue
|
||||
if row['Text'] and row['Arg1']:
|
||||
if (row['Arg1'] not in char_names) and (row['Arg1'] not in char_sets):
|
||||
new_names.add(row['Arg1'])
|
||||
return new_names
|
||||
new_names = set()
|
||||
with open(tsv_path, "r") as tsv_file:
|
||||
tsv = csv.DictReader(tsv_file, delimiter="\t", quotechar='"')
|
||||
if (
|
||||
("Arg1" not in tsv.fieldnames)
|
||||
or ("Text" not in tsv.fieldnames)
|
||||
or ("Command" not in tsv.fieldnames)
|
||||
):
|
||||
return new_names
|
||||
for row in tsv:
|
||||
if row["Command"] and row["Command"].startswith("//"):
|
||||
continue
|
||||
if row["Text"] and row["Arg1"]:
|
||||
if (row["Arg1"] not in char_names) and (row["Arg1"] not in char_sets):
|
||||
new_names.add(row["Arg1"])
|
||||
return new_names
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue