This commit is contained in:
drmext 2026-03-24 22:50:16 +00:00
parent cb98a20d22
commit 57d050273e
No known key found for this signature in database
GPG Key ID: F1ED48FFE79A6961
6 changed files with 78 additions and 38 deletions

5
activate-venv.bat Normal file
View File

@ -0,0 +1,5 @@
@echo off
cd /d %~dp0
start .venv\Scripts\activate.bat

View File

@ -233,7 +233,7 @@ async def playdata_3_playerdata_load(request: Request):
difficulty = int(record["difficulty"])
score = int(record["score"])
flare = int(record.get("flare_force", 0))
if flare == 0:
if flare in (-1, 0):
for k, v in flares:
if score >= k:
flare = v
@ -644,7 +644,10 @@ async def playdata_3_playerdata_save(request: Request):
& (where("difficulty") == difficulty)
& (where("score") == max(score, best.get("score", score)))
)
best_score_data["ghostid"] = ghostid.doc_id
if ghostid == None:
best_score_data["ghostid"] = -1
else:
best_score_data["ghostid"] = ghostid.doc_id
db.table("ddr_scores_best").upsert(
best_score_data,

View File

@ -58,6 +58,8 @@ async def playerdata_usergamedata_advanced(request: Request):
if "ddr_id" not in all_profiles_for_card:
ddr_id = random.randint(10000000, 99999999)
all_profiles_for_card["ddr_id"] = ddr_id
else:
ddr_id = all_profiles_for_card["ddr_id"]
all_profiles_for_card["version"][str(game_version)] = {
"game_version": game_version,

View File

@ -58,6 +58,8 @@ async def playerdata_2_usergamedata_advanced(request: Request):
if "ddr_id" not in all_profiles_for_card:
ddr_id = random.randint(10000000, 99999999)
all_profiles_for_card["ddr_id"] = ddr_id
else:
ddr_id = all_profiles_for_card["ddr_id"]
all_profiles_for_card["version"][str(game_version)] = {
"game_version": game_version,

View File

@ -29,9 +29,9 @@ Instructions:
### [import_ddr_spice_automap.py](import_ddr_spice_automap.py)
Example: `python utils\db\import_ddr_spice_automap.py --automap_xml automap_0.xml --version 19 --monkey_db db.json --ddr_id 12345678`
Example: `python utils\db\import_ddr_spice_automap.py --automap_xml automap_0.xml --version 3 --monkey_db db.json --ddr_id 12345678`
- `--version` 19 for A20P or 20 for A3
- `--version` 1 for A20P, 2 for A3, 3 for WORLD (automap source version, not destination)
- `--ddr_id` destination profile in db.json

View File

@ -24,43 +24,72 @@ def main(automap_xml, version, monkey_db, ddr_id):
if profile == None:
raise SystemExit(f"ERROR: DDR profile {ddr_id} not in {monkey_db}")
game_version = 19
if profile["version"].get(str(game_version), None) == None:
raise SystemExit(
f"ERROR: DDR profile {ddr_id} version {game_version} not in {monkey_db}"
)
scores = []
with open(automap_xml, "rb") as fp:
automap_0 = fp.read().split(b"\n\n")
if version == 19:
playerdata = "playerdata"
else:
if version == 3:
playerdata = "playdata_3"
game_version = 20
elif version == 2:
playerdata = "playerdata_2"
game_version = 19
elif version == 1:
playerdata = "playerdata"
game_version = 19
scores = []
scores_xml = False
for xml in automap_0:
tree = ET.ElementTree(ET.fromstring(xml.decode(encoding="shift-jis")))
root = tree.getroot()
if scores_xml:
for music in root.findall(f"{playerdata}/music"):
mcode = int(music.find("mcode").text)
for difficulty, chart in enumerate(music.findall("note")):
if int(chart.find("count").text) > 0:
rank = int(chart.find("rank").text)
clearkind = int(chart.find("clearkind").text)
score = int(chart.find("score").text)
try:
tree = ET.ElementTree(ET.fromstring(xml.decode(encoding="shift-jis")))
root = tree.getroot()
except:
continue
if version in (1, 2):
if scores_xml:
for music in root.findall(f"{playerdata}/music"):
mcode = int(music.find("mcode").text)
for difficulty, chart in enumerate(music.findall("note")):
c = chart.find("count")
if c == None:
continue
if int(c.text) > 0:
rank = int(chart.find("rank").text)
clearkind = int(chart.find("clearkind").text)
score = int(chart.find("score").text)
scores.append([mcode, difficulty, rank, clearkind, score, -1])
break
else:
try:
if root.find(f"{playerdata}/data/mode").text == "userload":
if len(root.find(f"{playerdata}/data/refid").text) == 16:
scores_xml = True
except AttributeError:
continue
elif version == 3:
if scores_xml:
for music in root.findall(f"{playerdata}/score"):
mcode = int(music.find("mcode").text)
for x in music.findall("score_single") + music.findall("score_double"):
s = x.find("score_str").text.split(",")
s = [int(val) for val in s]
difficulty = s[0] + 4 if x.tag == "score_double" else s[0]
rank = s[2]
clearkind = s[3]
score = s[4]
# flare = s[6]
scores.append([mcode, difficulty, rank, clearkind, score])
break
else:
try:
if root.find(f"{playerdata}/data/mode").text == "userload":
if len(root.find(f"{playerdata}/data/refid").text) == 16:
scores_xml = True
except AttributeError:
continue
break
else:
try:
a = root.find(f"{playerdata}")
if "method" in a.attrib:
if a.attrib["method"] == "playerdata_load":
if len(root.find(f"{playerdata}/data/refid").text) == 16:
scores_xml = True
except AttributeError:
continue
total_count = len(scores)
@ -73,6 +102,7 @@ def main(automap_xml, version, monkey_db, ddr_id):
rank = s[2]
lamp = s[3]
score = s[4]
# flare = s[5]
exscore = 0
print(
@ -81,7 +111,6 @@ def main(automap_xml, version, monkey_db, ddr_id):
best = db.table("ddr_scores_best").get(
(where("ddr_id") == ddr_id)
& (where("game_version") == game_version)
& (where("mcode") == mcode)
& (where("difficulty") == difficulty)
)
@ -97,14 +126,14 @@ def main(automap_xml, version, monkey_db, ddr_id):
"lamp": max(lamp, best.get("lamp", lamp)),
"score": max(score, best.get("score", score)),
"exscore": max(exscore, best.get("exscore", exscore)),
# "flare_force": max(flare, best.get("flare_force", flare)),
}
ghostid = db.table("ddr_scores").get(
(where("ddr_id") == ddr_id)
& (where("game_version") == game_version)
& (where("mcode") == mcode)
& (where("difficulty") == difficulty)
& (where("exscore") == best.get("exscore", exscore))
& (where("score") == max(score, best.get("score", score)))
)
if ghostid:
best_score_data["ghostid"] = ghostid.doc_id
@ -114,7 +143,6 @@ def main(automap_xml, version, monkey_db, ddr_id):
db.table("ddr_scores_best").upsert(
best_score_data,
(where("ddr_id") == ddr_id)
& (where("game_version") == game_version)
& (where("mcode") == mcode)
& (where("difficulty") == difficulty),
)
@ -129,8 +157,8 @@ if __name__ == "__main__":
parser.add_argument("--automap_xml", help="Input xml file", required=True)
parser.add_argument(
"--version",
help="19 is A20P, 20 is A3",
default=19,
help="1=A20P, 2=A3, 3=WORLD (automap_xml source version, not destination)",
default=3,
type=int,
)
parser.add_argument("--monkey_db", help="Output json file", required=True)