From 4046e757efe63980ee1049c40a99e4a7ec3da4cc Mon Sep 17 00:00:00 2001 From: louis Date: Tue, 12 Nov 2019 18:45:11 -0500 Subject: [PATCH] proper scene folder discovery --- adx/adx.py | 8 +++++-- adx/adx_parser.py | 6 +++-- db/quest.py | 14 ++++++------ diva/quest.py | 55 ++++++++++++++++++++++++++++++++++++++++------ utage/crypt.py | 4 +++- utage/names.py | 10 +++++++-- utage/translate.py | 28 ++++++++++++++--------- 7 files changed, 94 insertions(+), 31 deletions(-) diff --git a/adx/adx.py b/adx/adx.py index e334f58..01c0eb9 100644 --- a/adx/adx.py +++ b/adx/adx.py @@ -24,7 +24,9 @@ def extract_loop_data_from_files(files_in, fout): if res is not None: collect[os.path.splitext(os.path.basename(x))[0]] = res 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): @@ -46,5 +48,7 @@ def extract_loop_data_from_file(file_in, fout=None): if fout is not None and res is not None: 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 diff --git a/adx/adx_parser.py b/adx/adx_parser.py index 28974c2..993fc3c 100644 --- a/adx/adx_parser.py +++ b/adx/adx_parser.py @@ -107,7 +107,7 @@ class adx_file(object): if self.l_start > self.sam_count or self.l_end > self.sam_count: raise ValueError("Invalid Loop Data") return None - if not self.l_style in LOOP_TYPE_SUP: + if self.l_style not in LOOP_TYPE_SUP: raise NotImplementedError( "Loop Style {} Not Implemented".format(str(self.l_style)) ) @@ -123,5 +123,7 @@ class adx_file(object): ret["loop_end"] = {} ret["loop_end"]["seconds"] = self.l_end / self.sam_rate 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 diff --git a/db/quest.py b/db/quest.py index 5464324..c4b13f8 100644 --- a/db/quest.py +++ b/db/quest.py @@ -32,9 +32,9 @@ class QuestDB(BaseDB): res = self.cursor.fetchall() quests = {} for quest_id, name, scenes in res: - quests[quest_id] = {} - quests[quest_id]["Name"] = name - quests[quest_id]["Scenes"] = scenes.split(",") + quests[str(quest_id)] = {} + quests[str(quest_id)]["Name"] = name + quests[str(quest_id)]["Scenes"] = scenes.split(",") return quests def get_scenes(self): @@ -67,8 +67,8 @@ class QuestDB(BaseDB): res = self.cursor.fetchall() scenes = {} for scene_id, name, summary, parts in res: - scenes[scene_id] = {} - scenes[scene_id]["Name"] = name - scenes[scene_id]["SummaryText"] = summary - scenes[scene_id]["Parts"] = parts.split(",") + scenes[str(scene_id)] = {} + scenes[str(scene_id)]["Name"] = name + scenes[str(scene_id)]["SummaryText"] = summary + scenes[str(scene_id)]["Parts"] = parts.split(",") return scenes diff --git a/diva/quest.py b/diva/quest.py index 4a20477..d84e3b2 100644 --- a/diva/quest.py +++ b/diva/quest.py @@ -1,18 +1,37 @@ +import csv import db import io import json import os +from glob import glob + def update_missions(dir_in, old_path, languages): qdb = db.QuestDB(dir_in) 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() + 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( os.path.join(old_path, "XduScene.json"), "w", newline="\n" ) 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 ) - # TODO: reimplement folder finder - for lang in languages: out_dict = {} if lang == "jpn": for key, value in scenes.items(): out_dict[key] = { - "Name": value.name, - "SummaryText": value.summaryText, + "Name": value["Name"], + "SummaryText": value["SummaryText"], "Credits": "POKELABO", "Enabled": False, } @@ -71,7 +88,7 @@ def quest_mst(qdb, old_path, languages): out_dict = {} if lang == "jpn": for key, value in quests.items(): - out_dict[key] = {"Name": value.name, "Enabled": False} + out_dict[key] = {"Name": value["Name"], "Enabled": False} else: for key, value in quests.items(): out_dict[key] = {"Name": "", "Enabled": False} @@ -92,3 +109,27 @@ def quest_mst(qdb, old_path, languages): ) 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 diff --git a/utage/crypt.py b/utage/crypt.py index c6459ca..a6fb424 100644 --- a/utage/crypt.py +++ b/utage/crypt.py @@ -19,7 +19,9 @@ def crypt_dir(dir_in, key, encrypt=False, no_compress=False): if len(files) == 0: 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: p.map(pcrypt, files) diff --git a/utage/names.py b/utage/names.py index 7d4504a..56ef85c 100644 --- a/utage/names.py +++ b/utage/names.py @@ -30,7 +30,11 @@ def update_names(dir_in, old_path, languages): 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 + 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("//"): continue 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"]) return new_names diff --git a/utage/translate.py b/utage/translate.py index 3853b56..6c47289 100644 --- a/utage/translate.py +++ b/utage/translate.py @@ -3,7 +3,6 @@ import errno import io import json import os -import re import traceback from functools import partial @@ -12,17 +11,20 @@ from multiprocessing.pool import Pool def translate_dir(dir_in, tsv_out_dir, json_out_dir): - # we only want to key files that are mission ids files = [ f - for f in glob(os.path.join(dir_in, "**/*.tsv"), recursive=True) - if re.search(r"/[0-9]{9}\.tsv$", f) + for f in glob( + os.path.join(dir_in, "**/Scenario/*.tsv"), recursive=True + ) + if "{os.path.sep}Diva{os.path.sep}" not in f ] if len(files) == 0: 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: p.map(ptrans, files) @@ -36,7 +38,7 @@ def translate_file(file_in, tsv_out_dir, json_out_dir): # ie, Utage/>>>main01<<