Make set/unique extract script use item-names.json
This commit is contained in:
@@ -1,21 +1,36 @@
|
|||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import os
|
import argparse
|
||||||
import sys
|
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"
|
category = "Base"
|
||||||
setitems = {}
|
setitems = {}
|
||||||
with open(os.path.join(path, "setitems.txt")) as f:
|
with (excelpath / "setitems.txt").open() as f:
|
||||||
dr = csv.DictReader(f, delimiter="\t")
|
dr = csv.DictReader(f, delimiter="\t")
|
||||||
for row in dr:
|
for row in dr:
|
||||||
if row["index"] == "Expansion":
|
if row["index"] == "Expansion":
|
||||||
category = row["index"]
|
category = row["index"]
|
||||||
continue
|
continue
|
||||||
setitems[row["*ID"]] = {
|
setitems[row["*ID"]] = {
|
||||||
"name": row["index"],
|
"name": names[row["index"]],
|
||||||
"set": row["set"],
|
"set": names[row["set"]],
|
||||||
"itembase": row["item"],
|
"itembase": row["item"],
|
||||||
"req_lvl": int(row["lvl req"]),
|
"req_lvl": int(row["lvl req"]),
|
||||||
"ilvl": int(row["lvl"]),
|
"ilvl": int(row["lvl"]),
|
||||||
@@ -25,7 +40,7 @@ with open(os.path.join(path, "setitems.txt")) as f:
|
|||||||
|
|
||||||
category = "Base"
|
category = "Base"
|
||||||
uniqueitems = {}
|
uniqueitems = {}
|
||||||
with open(os.path.join(path, "uniqueitems.txt")) as f:
|
with (excelpath / "uniqueitems.txt").open() as f:
|
||||||
dr = csv.DictReader(f, delimiter="\t")
|
dr = csv.DictReader(f, delimiter="\t")
|
||||||
for row in dr:
|
for row in dr:
|
||||||
if row["index"] in [
|
if row["index"] in [
|
||||||
@@ -42,7 +57,7 @@ with open(os.path.join(path, "uniqueitems.txt")) as f:
|
|||||||
if len(row["lvl req"]) == 0:
|
if len(row["lvl req"]) == 0:
|
||||||
continue # deleted uniques
|
continue # deleted uniques
|
||||||
uniqueitems[row["*ID"]] = {
|
uniqueitems[row["*ID"]] = {
|
||||||
"name": row["index"],
|
"name": names[row["index"]],
|
||||||
"itembase": row["code"],
|
"itembase": row["code"],
|
||||||
"req_lvl": int(row["lvl req"]),
|
"req_lvl": int(row["lvl req"]),
|
||||||
"ilvl": int(row["lvl"]),
|
"ilvl": int(row["lvl"]),
|
||||||
@@ -50,10 +65,10 @@ with open(os.path.join(path, "uniqueitems.txt")) as f:
|
|||||||
"category": category,
|
"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)
|
json.dump(uniqueitems, f, indent=4)
|
||||||
f.write("\n")
|
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)
|
json.dump(setitems, f, indent=4)
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
|
|||||||
Reference in New Issue
Block a user