From 813e875cdf1e5b8abf95f0f5d801461d675eb67a Mon Sep 17 00:00:00 2001 From: omicron Date: Tue, 30 Sep 2025 11:10:26 +0200 Subject: [PATCH] Make set/unique extract script use item-names.json --- contrib/uniques.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/contrib/uniques.py b/contrib/uniques.py index c2e41b8..c77353e 100644 --- a/contrib/uniques.py +++ b/contrib/uniques.py @@ -1,21 +1,36 @@ import csv import json -import os -import sys +import argparse +from pathlib import Path -path = sys.argv[1] if len(sys.argv) >= 2 else "." +parser = argparse.ArgumentParser( + description="Process unique and set items from game data" +) +parser.add_argument( + "DATA_DIR", help="Path to d2 data dir containing local/ and global/" +) +parser.add_argument("OUTPUT_DIR", help="Path to destination directory") +args = parser.parse_args() + +excelpath = Path(args.DATA_DIR) / "global/excel" +outputpath = Path(args.OUTPUT_DIR) +namespath = Path(args.DATA_DIR) / "local/lng/strings/item-names.json" + +with namespath.open(encoding="utf-8-sig") as f: + names = json.load(f) +names = {name["Key"]: name["enUS"] for name in names} category = "Base" setitems = {} -with open(os.path.join(path, "setitems.txt")) as f: +with (excelpath / "setitems.txt").open() as f: dr = csv.DictReader(f, delimiter="\t") for row in dr: if row["index"] == "Expansion": category = row["index"] continue setitems[row["*ID"]] = { - "name": row["index"], - "set": row["set"], + "name": names[row["index"]], + "set": names[row["set"]], "itembase": row["item"], "req_lvl": int(row["lvl req"]), "ilvl": int(row["lvl"]), @@ -25,7 +40,7 @@ with open(os.path.join(path, "setitems.txt")) as f: category = "Base" uniqueitems = {} -with open(os.path.join(path, "uniqueitems.txt")) as f: +with (excelpath / "uniqueitems.txt").open() as f: dr = csv.DictReader(f, delimiter="\t") for row in dr: if row["index"] in [ @@ -42,7 +57,7 @@ with open(os.path.join(path, "uniqueitems.txt")) as f: if len(row["lvl req"]) == 0: continue # deleted uniques uniqueitems[row["*ID"]] = { - "name": row["index"], + "name": names[row["index"]], "itembase": row["code"], "req_lvl": int(row["lvl req"]), "ilvl": int(row["lvl"]), @@ -50,10 +65,10 @@ with open(os.path.join(path, "uniqueitems.txt")) as f: "category": category, } -with open("uniques.json", "w", newline="\n") as f: +with (outputpath / "uniques.json").open("w", newline="\n") as f: json.dump(uniqueitems, f, indent=4) f.write("\n") -with open("sets.json", "w", newline="\n") as f: +with (outputpath / "sets.json").open("w", newline="\n") as f: json.dump(setitems, f, indent=4) f.write("\n")