75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
import csv
|
|
import json
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
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 (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": names[row["index"]],
|
|
"set": names[row["set"]],
|
|
"itembase": row["item"],
|
|
"req_lvl": int(row["lvl req"]),
|
|
"ilvl": int(row["lvl"]),
|
|
"rarity": int(row["rarity"]),
|
|
"category": category,
|
|
}
|
|
|
|
category = "Base"
|
|
uniqueitems = {}
|
|
with (excelpath / "uniqueitems.txt").open() as f:
|
|
dr = csv.DictReader(f, delimiter="\t")
|
|
for row in dr:
|
|
if row["index"] in [
|
|
"Expansion",
|
|
"Armor",
|
|
"Elite Uniques",
|
|
"Rings",
|
|
"Class Specific",
|
|
]:
|
|
category = row["index"]
|
|
continue
|
|
if row["*ID"] == "288":
|
|
category = "Patch 1.10+"
|
|
if len(row["lvl req"]) == 0:
|
|
continue # deleted uniques
|
|
uniqueitems[row["*ID"]] = {
|
|
"name": names[row["index"]],
|
|
"itembase": row["code"],
|
|
"req_lvl": int(row["lvl req"]),
|
|
"ilvl": int(row["lvl"]),
|
|
"rarity": int(row["rarity"]),
|
|
"category": category,
|
|
}
|
|
|
|
with (outputpath / "uniques.json").open("w", newline="\n") as f:
|
|
json.dump(uniqueitems, f, indent=4)
|
|
f.write("\n")
|
|
|
|
with (outputpath / "sets.json").open("w", newline="\n") as f:
|
|
json.dump(setitems, f, indent=4)
|
|
f.write("\n")
|