Add automatic mining and ticket resource stages
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
"""Build the small resource-stage index from already verified local static data."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
|
||||
from ranch_assistant.game_data import load_progression_data
|
||||
from ranch_assistant.model import Catalog
|
||||
from ranch_assistant.resource_stages import ORIGINAL_APK_SHA256
|
||||
|
||||
|
||||
|
||||
|
||||
def build(output):
|
||||
data = load_progression_data()
|
||||
names = Catalog().data["item_names"]
|
||||
mine = data.mines["mine1"]
|
||||
mines = {str(obj["stageId"]) for layer in mine["layers"] for obj in layer.get("objs") or []
|
||||
if obj.get("type") == "stage" and obj.get("stageId")}
|
||||
sp_children = {str(obj["stageId"]) for key, sp in data.stage_sp.items()
|
||||
if not sp.get("tag") and not data.stages.get(key, {}).get("special")
|
||||
for obj in sp.get("stages") or [] if obj.get("stageId")}
|
||||
ids = mines | {key for key in sp_children | set(data.stage_sp) if data.stages.get(key, {}).get("special")
|
||||
and not data.stages[key].get("posmode") and (data.stages[key].get("cost") or {}).get("items")
|
||||
and all("券" in names.get(str(item.get("typeId")), "") or "门票" in names.get(str(item.get("typeId")), "")
|
||||
for item in data.stages[key]["cost"]["items"])}
|
||||
ids |= {key for key, sp in data.stage_sp.items() if any(obj.get("stageId") in ids for obj in sp.get("stages") or [])}
|
||||
needed = sorted({str(item["typeId"]) for key in ids for item in (data.stages.get(key, {}).get("cost") or {}).get("items", [])})
|
||||
result = {"schema": 1, "apk_sha256": ORIGINAL_APK_SHA256,
|
||||
"progression_sha256": hashlib.sha256((data.directory / "progression.json.gz").read_bytes()).hexdigest(),
|
||||
"mine": mine,
|
||||
"stage_info": {key: data.stages[key] for key in sorted(ids) if key in data.stages},
|
||||
"stage_sp": data.stage_sp,
|
||||
"item_names": {key: names.get(key, key) for key in needed},
|
||||
"game_setting": {"cityInfo": data.game_setting.get("cityInfo", {})}}
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(json.dumps(result, ensure_ascii=False, separators=(",", ":")), encoding="utf-8")
|
||||
return len(mines), len(ids)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--output", type=Path, default=ROOT / "ranch_assistant/data/resource_stages.json")
|
||||
args = parser.parse_args()
|
||||
print("Resource mines/stages:", *build(args.output))
|
||||
Reference in New Issue
Block a user