Add item basetype parsing
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import json
|
||||
import os
|
||||
from bitarray import bitarray
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
|
||||
_data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
|
||||
_basetype_map = None
|
||||
|
||||
|
||||
class Quality(Enum):
|
||||
LOW = 1
|
||||
@@ -73,10 +78,16 @@ class Item:
|
||||
nameword2: int | None = None
|
||||
runeword_id: int | None = None
|
||||
personal_name: str | None = None
|
||||
defense: int | None = None
|
||||
durability: int | None = None
|
||||
max_durability: int | None = None
|
||||
sockets: int | None = None
|
||||
quantity: int | None = None
|
||||
|
||||
def print(self, indent=5, with_raw=False):
|
||||
properties = []
|
||||
print(" " * indent, self.kind)
|
||||
kind_name = lookup_basetype(self.kind)["name"]
|
||||
print(" " * indent, f"{kind_name} ({self.kind})")
|
||||
if self.lvl:
|
||||
print(" " * indent, f"ilvl {self.lvl}")
|
||||
if self.is_simple:
|
||||
@@ -117,3 +128,11 @@ class Item:
|
||||
print(" " * indent, txtbits(bits))
|
||||
print("")
|
||||
print("")
|
||||
|
||||
|
||||
def lookup_basetype(code: str) -> dict:
|
||||
global _basetype_map
|
||||
if _basetype_map is None:
|
||||
with open(os.path.join(_data_path, "items.json")) as f:
|
||||
_basetype_map = json.load(f)
|
||||
return _basetype_map[code]
|
||||
|
||||
Reference in New Issue
Block a user