proper scene folder discovery
This commit is contained in:
parent
c87c517217
commit
4046e757ef
7 changed files with 94 additions and 31 deletions
|
|
@ -24,7 +24,9 @@ def extract_loop_data_from_files(files_in, fout):
|
||||||
if res is not None:
|
if res is not None:
|
||||||
collect[os.path.splitext(os.path.basename(x))[0]] = res
|
collect[os.path.splitext(os.path.basename(x))[0]] = res
|
||||||
with open(fout, "w") as out:
|
with open(fout, "w") as out:
|
||||||
json.dump(collect, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
json.dump(
|
||||||
|
collect, out, ensure_ascii=False, indent="\t", sort_keys=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def extract_loop_data_from_file(file_in, fout=None):
|
def extract_loop_data_from_file(file_in, fout=None):
|
||||||
|
|
@ -46,5 +48,7 @@ def extract_loop_data_from_file(file_in, fout=None):
|
||||||
|
|
||||||
if fout is not None and res is not None:
|
if fout is not None and res is not None:
|
||||||
with open(fout, "w") as out:
|
with open(fout, "w") as out:
|
||||||
json.dump(res, out, ensure_ascii=False, indent="\t", sort_keys=True)
|
json.dump(
|
||||||
|
res, out, ensure_ascii=False, indent="\t", sort_keys=True
|
||||||
|
)
|
||||||
return res
|
return res
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class adx_file(object):
|
||||||
if self.l_start > self.sam_count or self.l_end > self.sam_count:
|
if self.l_start > self.sam_count or self.l_end > self.sam_count:
|
||||||
raise ValueError("Invalid Loop Data")
|
raise ValueError("Invalid Loop Data")
|
||||||
return None
|
return None
|
||||||
if not self.l_style in LOOP_TYPE_SUP:
|
if self.l_style not in LOOP_TYPE_SUP:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Loop Style {} Not Implemented".format(str(self.l_style))
|
"Loop Style {} Not Implemented".format(str(self.l_style))
|
||||||
)
|
)
|
||||||
|
|
@ -123,5 +123,7 @@ class adx_file(object):
|
||||||
ret["loop_end"] = {}
|
ret["loop_end"] = {}
|
||||||
ret["loop_end"]["seconds"] = self.l_end / self.sam_rate
|
ret["loop_end"]["seconds"] = self.l_end / self.sam_rate
|
||||||
ret["loop_end"]["samples_native"] = self.l_end
|
ret["loop_end"]["samples_native"] = self.l_end
|
||||||
ret["loop_end"]["samples_48k"] = dumb_round(self.l_end / self.sam_rate * 48000)
|
ret["loop_end"]["samples_48k"] = dumb_round(
|
||||||
|
self.l_end / self.sam_rate * 48000
|
||||||
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
14
db/quest.py
14
db/quest.py
|
|
@ -32,9 +32,9 @@ class QuestDB(BaseDB):
|
||||||
res = self.cursor.fetchall()
|
res = self.cursor.fetchall()
|
||||||
quests = {}
|
quests = {}
|
||||||
for quest_id, name, scenes in res:
|
for quest_id, name, scenes in res:
|
||||||
quests[quest_id] = {}
|
quests[str(quest_id)] = {}
|
||||||
quests[quest_id]["Name"] = name
|
quests[str(quest_id)]["Name"] = name
|
||||||
quests[quest_id]["Scenes"] = scenes.split(",")
|
quests[str(quest_id)]["Scenes"] = scenes.split(",")
|
||||||
return quests
|
return quests
|
||||||
|
|
||||||
def get_scenes(self):
|
def get_scenes(self):
|
||||||
|
|
@ -67,8 +67,8 @@ class QuestDB(BaseDB):
|
||||||
res = self.cursor.fetchall()
|
res = self.cursor.fetchall()
|
||||||
scenes = {}
|
scenes = {}
|
||||||
for scene_id, name, summary, parts in res:
|
for scene_id, name, summary, parts in res:
|
||||||
scenes[scene_id] = {}
|
scenes[str(scene_id)] = {}
|
||||||
scenes[scene_id]["Name"] = name
|
scenes[str(scene_id)]["Name"] = name
|
||||||
scenes[scene_id]["SummaryText"] = summary
|
scenes[str(scene_id)]["SummaryText"] = summary
|
||||||
scenes[scene_id]["Parts"] = parts.split(",")
|
scenes[str(scene_id)]["Parts"] = parts.split(",")
|
||||||
return scenes
|
return scenes
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,37 @@
|
||||||
|
import csv
|
||||||
import db
|
import db
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
|
|
||||||
def update_missions(dir_in, old_path, languages):
|
def update_missions(dir_in, old_path, languages):
|
||||||
qdb = db.QuestDB(dir_in)
|
qdb = db.QuestDB(dir_in)
|
||||||
quest_mst(qdb, old_path, languages)
|
quest_mst(qdb, old_path, languages)
|
||||||
scene_mst(qdb, old_path, languages)
|
scene_mst(qdb, old_path, dir_in, languages)
|
||||||
|
|
||||||
|
|
||||||
def scene_mst(qdb, old_path, languages):
|
def scene_mst(qdb, old_path, dir_in, languages):
|
||||||
scenes = qdb.get_scenes()
|
scenes = qdb.get_scenes()
|
||||||
|
|
||||||
|
locations = load_locations(dir_in)
|
||||||
|
|
||||||
|
for id, scene in scenes.items():
|
||||||
|
i = 0
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
scene["Folder"] = locations[scene["Parts"][i]]
|
||||||
|
except KeyError as exc:
|
||||||
|
i += 1
|
||||||
|
if i == len(scene["Parts"]):
|
||||||
|
raise KeyError(
|
||||||
|
f"Could not find folder for scene {id}"
|
||||||
|
) from exc
|
||||||
|
continue
|
||||||
|
break
|
||||||
|
|
||||||
with io.open(
|
with io.open(
|
||||||
os.path.join(old_path, "XduScene.json"), "w", newline="\n"
|
os.path.join(old_path, "XduScene.json"), "w", newline="\n"
|
||||||
) as json_file:
|
) as json_file:
|
||||||
|
|
@ -20,15 +39,13 @@ def scene_mst(qdb, old_path, languages):
|
||||||
scenes, json_file, ensure_ascii=False, indent="\t", sort_keys=True
|
scenes, json_file, ensure_ascii=False, indent="\t", sort_keys=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: reimplement folder finder
|
|
||||||
|
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
out_dict = {}
|
out_dict = {}
|
||||||
if lang == "jpn":
|
if lang == "jpn":
|
||||||
for key, value in scenes.items():
|
for key, value in scenes.items():
|
||||||
out_dict[key] = {
|
out_dict[key] = {
|
||||||
"Name": value.name,
|
"Name": value["Name"],
|
||||||
"SummaryText": value.summaryText,
|
"SummaryText": value["SummaryText"],
|
||||||
"Credits": "POKELABO",
|
"Credits": "POKELABO",
|
||||||
"Enabled": False,
|
"Enabled": False,
|
||||||
}
|
}
|
||||||
|
|
@ -71,7 +88,7 @@ def quest_mst(qdb, old_path, languages):
|
||||||
out_dict = {}
|
out_dict = {}
|
||||||
if lang == "jpn":
|
if lang == "jpn":
|
||||||
for key, value in quests.items():
|
for key, value in quests.items():
|
||||||
out_dict[key] = {"Name": value.name, "Enabled": False}
|
out_dict[key] = {"Name": value["Name"], "Enabled": False}
|
||||||
else:
|
else:
|
||||||
for key, value in quests.items():
|
for key, value in quests.items():
|
||||||
out_dict[key] = {"Name": "", "Enabled": False}
|
out_dict[key] = {"Name": "", "Enabled": False}
|
||||||
|
|
@ -92,3 +109,27 @@ def quest_mst(qdb, old_path, languages):
|
||||||
)
|
)
|
||||||
|
|
||||||
return quests
|
return quests
|
||||||
|
|
||||||
|
|
||||||
|
def load_locations(dir_in):
|
||||||
|
locations = {}
|
||||||
|
settings = glob(
|
||||||
|
os.path.join(dir_in, "Common/Asset/Utage/**/Settings/Scenario.tsv"),
|
||||||
|
recursive=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(settings) == 0:
|
||||||
|
raise FileNotFoundError("Ya didn't decrypt the files dummy")
|
||||||
|
|
||||||
|
for scenario in settings:
|
||||||
|
with open(scenario, "r") as tsv_file:
|
||||||
|
tsv = csv.DictReader(tsv_file, delimiter="\t", quotechar='"')
|
||||||
|
for row in tsv:
|
||||||
|
tokens = row["FileName"].split("/")
|
||||||
|
if len(tokens) < 3:
|
||||||
|
continue
|
||||||
|
if tokens[2] in locations:
|
||||||
|
raise ValueError("Conflicting paths for file {tokens[2]}")
|
||||||
|
locations[tokens[2]] = tokens[0]
|
||||||
|
|
||||||
|
return locations
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ def crypt_dir(dir_in, key, encrypt=False, no_compress=False):
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||||
|
|
||||||
pcrypt = partial(crypt_file, key=key, encrypt=encrypt, no_compress=no_compress)
|
pcrypt = partial(
|
||||||
|
crypt_file, key=key, encrypt=encrypt, no_compress=no_compress
|
||||||
|
)
|
||||||
with Pool() as p:
|
with Pool() as p:
|
||||||
p.map(pcrypt, files)
|
p.map(pcrypt, files)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,11 @@ def update_names(dir_in, old_path, languages):
|
||||||
langfile, "w", newline="\n"
|
langfile, "w", newline="\n"
|
||||||
) as lang_file: # you're using git right
|
) as lang_file: # you're using git right
|
||||||
json.dump(
|
json.dump(
|
||||||
out_dict, lang_file, ensure_ascii=False, indent="\t", sort_keys=True
|
out_dict,
|
||||||
|
lang_file,
|
||||||
|
ensure_ascii=False,
|
||||||
|
indent="\t",
|
||||||
|
sort_keys=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -97,6 +101,8 @@ def read_mission(tsv_path, char_names, char_sets):
|
||||||
if row["Command"] and row["Command"].startswith("//"):
|
if row["Command"] and row["Command"].startswith("//"):
|
||||||
continue
|
continue
|
||||||
if row["Text"] and row["Arg1"]:
|
if row["Text"] and row["Arg1"]:
|
||||||
if (row["Arg1"] not in char_names) and (row["Arg1"] not in char_sets):
|
if (row["Arg1"] not in char_names) and (
|
||||||
|
row["Arg1"] not in char_sets
|
||||||
|
):
|
||||||
new_names.add(row["Arg1"])
|
new_names.add(row["Arg1"])
|
||||||
return new_names
|
return new_names
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import errno
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
@ -12,17 +11,20 @@ from multiprocessing.pool import Pool
|
||||||
|
|
||||||
|
|
||||||
def translate_dir(dir_in, tsv_out_dir, json_out_dir):
|
def translate_dir(dir_in, tsv_out_dir, json_out_dir):
|
||||||
# we only want to key files that are mission ids
|
|
||||||
files = [
|
files = [
|
||||||
f
|
f
|
||||||
for f in glob(os.path.join(dir_in, "**/*.tsv"), recursive=True)
|
for f in glob(
|
||||||
if re.search(r"/[0-9]{9}\.tsv$", f)
|
os.path.join(dir_in, "**/Scenario/*.tsv"), recursive=True
|
||||||
|
)
|
||||||
|
if "{os.path.sep}Diva{os.path.sep}" not in f
|
||||||
]
|
]
|
||||||
|
|
||||||
if len(files) == 0:
|
if len(files) == 0:
|
||||||
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
raise FileNotFoundError("No valid files found in directory: " + dir_in)
|
||||||
|
|
||||||
ptrans = partial(translate_file, tsv_out_dir=tsv_out_dir, json_out_dir=json_out_dir)
|
ptrans = partial(
|
||||||
|
translate_file, tsv_out_dir=tsv_out_dir, json_out_dir=json_out_dir
|
||||||
|
)
|
||||||
with Pool() as p:
|
with Pool() as p:
|
||||||
p.map(ptrans, files)
|
p.map(ptrans, files)
|
||||||
|
|
||||||
|
|
@ -36,7 +38,7 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
||||||
# ie, Utage/>>>main01<<</Scenario/whatever.tsv
|
# ie, Utage/>>>main01<<</Scenario/whatever.tsv
|
||||||
try:
|
try:
|
||||||
event_folder = os.path.normpath(file_in).split(os.sep)[-3]
|
event_folder = os.path.normpath(file_in).split(os.sep)[-3]
|
||||||
except Exception as e:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("Error processing tsv: Please reference from Utage root")
|
print("Error processing tsv: Please reference from Utage root")
|
||||||
raise
|
raise
|
||||||
|
|
@ -47,7 +49,9 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
||||||
tsv_out_dir, event_folder, "Scenario", "{}_t.tsv".format(id_num)
|
tsv_out_dir, event_folder, "Scenario", "{}_t.tsv".format(id_num)
|
||||||
)
|
)
|
||||||
json_output_path = os.path.join(
|
json_output_path = os.path.join(
|
||||||
json_out_dir, event_folder, "{}_translations_jpn.json".format(id_num)
|
json_out_dir,
|
||||||
|
event_folder,
|
||||||
|
"{}_translations_jpn.json".format(id_num),
|
||||||
)
|
)
|
||||||
|
|
||||||
# need to create output paths and avoid races when threading
|
# need to create output paths and avoid races when threading
|
||||||
|
|
@ -86,10 +90,14 @@ def translate_file(file_in, tsv_out_dir, json_out_dir):
|
||||||
with io.open(json_output_path, "w", newline="\n") as json_out:
|
with io.open(json_output_path, "w", newline="\n") as json_out:
|
||||||
# we don't want to sort these because they're _1, ..., _10, etc
|
# we don't want to sort these because they're _1, ..., _10, etc
|
||||||
json.dump(
|
json.dump(
|
||||||
json_str, json_out, ensure_ascii=False, indent="\t", sort_keys=False
|
json_str,
|
||||||
|
json_out,
|
||||||
|
ensure_ascii=False,
|
||||||
|
indent="\t",
|
||||||
|
sort_keys=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("Error processing file: " + file_in)
|
print("Error processing file: " + file_in)
|
||||||
|
|
||||||
|
|
@ -110,7 +118,7 @@ def process_tsv(tsv, id_num):
|
||||||
row["English"] = key
|
row["English"] = key
|
||||||
key_dict[key] = row["Text"]
|
key_dict[key] = row["Text"]
|
||||||
tsv_keyed.append(row)
|
tsv_keyed.append(row)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print("Error processing tsv: " + id_num)
|
print("Error processing tsv: " + id_num)
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue