114 lines
4.5 KiB
Python
114 lines
4.5 KiB
Python
import db
|
|
import io
|
|
import json
|
|
import os
|
|
|
|
from sqlalchemy.orm import contains_eager
|
|
|
|
def update_missions(dir_in, old_path, languages):
|
|
db.init(dir_in)
|
|
quest_mst(old_path, languages)
|
|
scene_mst(old_path, languages)
|
|
|
|
def scene_mst(old_path, languages):
|
|
result = (db.session.query(db.QuestScene)
|
|
.join(db.QuestScene.parts)
|
|
.options(contains_eager(db.QuestScene.parts))
|
|
.filter((db.QuestPart.beforeTalkName != "") | (db.QuestPart.afterTalkName != ""))
|
|
.filter(db.QuestScene.parts.any())
|
|
.all())
|
|
|
|
scenes = {}
|
|
for x in result:
|
|
scenes[str(x.questSceneMstId)] = { "Name": x.name,
|
|
"SummaryText": x.summaryText,
|
|
"Parts": [],
|
|
"Folder": "" }
|
|
|
|
id_num = ""
|
|
# this is slow as balls but i'm way too tired to figure out how to optimize it
|
|
for y in x.parts:
|
|
if y.beforeTalkName:
|
|
id_num = y.beforeTalkName
|
|
scenes[str(x.questSceneMstId)]["Parts"].append(y.beforeTalkName)
|
|
if y.afterTalkName:
|
|
id_num = y.afterTalkName
|
|
scenes[str(x.questSceneMstId)]["Parts"].append(y.afterTalkName)
|
|
|
|
# i checked every entry, moving it to do once for speed
|
|
if not scenes[str(x.questSceneMstId)]["Folder"] and id_num:
|
|
path = (db.session.query(db.ResourceEntry)
|
|
.filter(db.ResourceEntry.path.like("%/Scenario/{}.tsv.utage".format(id_num)))
|
|
.filter(db.ResourceEntry.path.notlike("%Utage/side03/%.tsv.utage")) # dead folder with dupes too lazy to parse settings tsv
|
|
.one())
|
|
folder = path.path.split("/")[2]
|
|
if scenes[str(x.questSceneMstId)]["Folder"] and scenes[str(x.questSceneMstId)]["Folder"] != folder:
|
|
raise KeyError("Internal path inconsitency, bailing out {}".format(id_num))
|
|
scenes[str(x.questSceneMstId)]["Folder"] = folder
|
|
|
|
with io.open(os.path.join(old_path, "XduScene.json"), "w", newline='\n') as json_file:
|
|
json.dump(scenes, json_file, ensure_ascii=False, indent='\t', sort_keys=True)
|
|
|
|
for l in languages:
|
|
out_dict = {}
|
|
if l == "jpn":
|
|
for x in result:
|
|
out_dict[str(x.questSceneMstId)] = { "Name": x.name,
|
|
"SummaryText": x.summaryText,
|
|
"Credits": "POKELABO",
|
|
"Enabled": False }
|
|
else:
|
|
for x in result:
|
|
out_dict[str(x.questSceneMstId)] = { "Name": "",
|
|
"SummaryText": "",
|
|
"Credits": "",
|
|
"Enabled": False }
|
|
|
|
langfile = os.path.join(old_path, "XduSceneNames_{}.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)
|
|
|
|
def quest_mst(old_path, languages):
|
|
# i regret my life choices
|
|
result = (db.session.query(db.Quest)
|
|
.filter(db.Quest.baseQuestMstId == 0)
|
|
.join(db.Quest.scenes)
|
|
.join(db.QuestScene.parts)
|
|
.options(contains_eager(db.Quest.scenes).
|
|
contains_eager(db.QuestScene.parts))
|
|
.filter(db.QuestPart.beforeTalkName != "" or db.QuestPart.afterTalkName != "")
|
|
.filter(db.QuestScene.parts.any())
|
|
.filter(db.Quest.scenes.any())
|
|
.all())
|
|
quests = {}
|
|
for x in result:
|
|
quests[str(x.questMstId)] = { "Name": x.name, "Scenes": [d.questSceneMstId for d in x.scenes] }
|
|
|
|
with io.open(os.path.join(old_path, "XduQuest.json"), "w", newline='\n') as json_file:
|
|
json.dump(quests, json_file, ensure_ascii=False, indent='\t', sort_keys=True)
|
|
|
|
for l in languages:
|
|
out_dict = {}
|
|
if l == "jpn":
|
|
for x in result:
|
|
out_dict[str(x.questMstId)] = { "Name": x.name, "Enabled": False }
|
|
else:
|
|
for x in result:
|
|
out_dict[str(x.questMstId)] = { "Name": "", "Enabled": False }
|
|
|
|
langfile = os.path.join(old_path, "XduQuestNames_{}.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)
|
|
|
|
|
|
return quests
|