proper scene folder discovery

This commit is contained in:
louis 2019-11-12 18:45:11 -05:00
parent c87c517217
commit 4046e757ef
7 changed files with 94 additions and 31 deletions

View file

@ -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