Split stackable property away from the class in items.json
This commit is contained in:
72
contrib/items.py
Normal file
72
contrib/items.py
Normal file
@@ -0,0 +1,72 @@
|
||||
import json
|
||||
import csv
|
||||
|
||||
items = {}
|
||||
|
||||
item_patches = {
|
||||
"tbk": {"class": "tome"},
|
||||
"ibk": {"class": "tome"},
|
||||
}
|
||||
|
||||
# build code -> names map
|
||||
with open("item-names.json", encoding="utf-8-sig") as f:
|
||||
names = json.load(f)
|
||||
|
||||
names = []
|
||||
for entry in names:
|
||||
code = entry["Key"]
|
||||
if len(code) != 3 or not code.islower():
|
||||
continue
|
||||
name = entry["enUS"]
|
||||
names[code] = {"name": name}
|
||||
|
||||
# Extract items
|
||||
with open("armor.txt", newline="") as f:
|
||||
reader = csv.DictReader(f, delimiter="\t")
|
||||
for row in reader:
|
||||
if row["name"] == "Expansion":
|
||||
continue
|
||||
code = row["code"]
|
||||
assert code not in items
|
||||
items[code] = {
|
||||
"name": names[code] if code in names else row["name"],
|
||||
"class": "armor",
|
||||
"type": row["type"],
|
||||
"stackable": bool(row["stackable"]),
|
||||
}
|
||||
|
||||
with open("weapons.txt", newline="") as f:
|
||||
reader = csv.DictReader(f, delimiter="\t")
|
||||
for row in reader:
|
||||
if row["name"] == "Expansion":
|
||||
continue
|
||||
code = row["code"]
|
||||
if code in items:
|
||||
print("Already in", code)
|
||||
assert code not in items
|
||||
items[code] = {
|
||||
"name": names[code] if code in names else row["name"],
|
||||
"class": "weapon",
|
||||
"type": row["type"],
|
||||
"stackable": bool(row["stackable"]),
|
||||
}
|
||||
|
||||
with open("misc.txt", newline="") as f:
|
||||
reader = csv.DictReader(f, delimiter="\t")
|
||||
for row in reader:
|
||||
if row["name"] == "Expansion":
|
||||
continue
|
||||
code = row["code"]
|
||||
assert code not in items
|
||||
items[code] = {
|
||||
"name": names[code] if code in names else row["name"],
|
||||
"class": "misc",
|
||||
"type": row["type"],
|
||||
"stackable": bool(row["stackable"]),
|
||||
}
|
||||
|
||||
for code, patch in item_patches.items():
|
||||
items[code].update(patch)
|
||||
|
||||
with open("items.json", "w") as f:
|
||||
json.dump(items, f, indent=4)
|
||||
Reference in New Issue
Block a user