fuck orm
This commit is contained in:
parent
d75fcf3507
commit
c87c517217
5 changed files with 140 additions and 213 deletions
151
diva/quest.py
151
diva/quest.py
|
|
@ -3,153 +3,92 @@ 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)
|
||||
qdb = db.QuestDB(dir_in)
|
||||
quest_mst(qdb, old_path, languages)
|
||||
scene_mst(qdb, 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
|
||||
def scene_mst(qdb, old_path, languages):
|
||||
scenes = qdb.get_scenes()
|
||||
|
||||
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)
|
||||
json.dump(
|
||||
scenes, json_file, ensure_ascii=False, indent="\t", sort_keys=True
|
||||
)
|
||||
|
||||
for l in languages:
|
||||
# TODO: reimplement folder finder
|
||||
|
||||
for lang in languages:
|
||||
out_dict = {}
|
||||
if l == "jpn":
|
||||
for x in result:
|
||||
out_dict[str(x.questSceneMstId)] = {
|
||||
"Name": x.name,
|
||||
"SummaryText": x.summaryText,
|
||||
if lang == "jpn":
|
||||
for key, value in scenes.items():
|
||||
out_dict[key] = {
|
||||
"Name": value.name,
|
||||
"SummaryText": value.summaryText,
|
||||
"Credits": "POKELABO",
|
||||
"Enabled": False,
|
||||
}
|
||||
else:
|
||||
for x in result:
|
||||
out_dict[str(x.questSceneMstId)] = {
|
||||
for key in scenes.keys():
|
||||
out_dict[key] = {
|
||||
"Name": "",
|
||||
"SummaryText": "",
|
||||
"Credits": "",
|
||||
"Enabled": False,
|
||||
}
|
||||
|
||||
langfile = os.path.join(old_path, "XduSceneNames_{}.json".format(l))
|
||||
langfile = os.path.join(old_path, f"XduSceneNames_{lang}.json")
|
||||
if os.path.isfile(langfile):
|
||||
with open(langfile, "r") as lang_file:
|
||||
lang_dict = json.load(lang_file)
|
||||
out_dict.update(lang_dict)
|
||||
out_dict.update(lang_dict)
|
||||
|
||||
with io.open(
|
||||
langfile, "w", newline="\n"
|
||||
) as lang_file: # you're using git right
|
||||
with io.open(langfile, "w", newline="\n") as lang_file:
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
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],
|
||||
}
|
||||
def quest_mst(qdb, old_path, languages):
|
||||
quests = qdb.get_quests()
|
||||
|
||||
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)
|
||||
json.dump(
|
||||
quests, json_file, ensure_ascii=False, indent="\t", sort_keys=True
|
||||
)
|
||||
|
||||
for l in languages:
|
||||
for lang in languages:
|
||||
out_dict = {}
|
||||
if l == "jpn":
|
||||
for x in result:
|
||||
out_dict[str(x.questMstId)] = {"Name": x.name, "Enabled": False}
|
||||
if lang == "jpn":
|
||||
for key, value in quests.items():
|
||||
out_dict[key] = {"Name": value.name, "Enabled": False}
|
||||
else:
|
||||
for x in result:
|
||||
out_dict[str(x.questMstId)] = {"Name": "", "Enabled": False}
|
||||
for key, value in quests.items():
|
||||
out_dict[key] = {"Name": "", "Enabled": False}
|
||||
|
||||
langfile = os.path.join(old_path, "XduQuestNames_{}.json".format(l))
|
||||
langfile = os.path.join(old_path, f"XduQuestNames_{lang}.json")
|
||||
if os.path.isfile(langfile):
|
||||
with open(langfile, "r") as lang_file:
|
||||
lang_dict = json.load(lang_file)
|
||||
out_dict.update(lang_dict)
|
||||
out_dict.update(lang_dict)
|
||||
|
||||
with io.open(
|
||||
langfile, "w", newline="\n"
|
||||
) as lang_file: # you're using git right
|
||||
with io.open(langfile, "w", newline="\n") as lang_file:
|
||||
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,
|
||||
)
|
||||
|
||||
return quests
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue