Switch from affixes.json to stats.json
This commit is contained in:
@@ -16,13 +16,14 @@
|
||||
# Mercator. If not, see <https://www.gnu.org/licenses/>.
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
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
|
||||
_affix_map = None
|
||||
_stats_map = None
|
||||
|
||||
|
||||
class Quality(Enum):
|
||||
@@ -50,22 +51,19 @@ class LowQualityType(Enum):
|
||||
|
||||
|
||||
@dataclass
|
||||
class Affix:
|
||||
name_id: int
|
||||
stat_id: int | None = None # TODO: These 3 should probably not be optional
|
||||
stat_values: list[int] | None = None
|
||||
stat_text: str | None = None
|
||||
class Stat:
|
||||
id: int | None = None # TODO: These 3 should probably not be optional
|
||||
values: list[int] | None = None
|
||||
parameter: int | None = None
|
||||
text: str | None = None
|
||||
|
||||
def print(self, indent=5):
|
||||
# TODO: name lookup
|
||||
if self.stat_text:
|
||||
subst_text = self.stat_text
|
||||
for i, val in enumerate(self.stat_values):
|
||||
replace = "{" + str(i) + "}"
|
||||
subst_text = subst_text.replace(replace, str(val))
|
||||
else:
|
||||
subst_text = "<No text>"
|
||||
print(" " * indent, f"{hex(self.name_id)}: {subst_text}")
|
||||
subst_text = self.text
|
||||
for val in self.values:
|
||||
subst_text = subst_text.replace("#", str(val), 1)
|
||||
if self.parameter:
|
||||
subst_text = re.sub("\[[^\]]*\]", str(self.parameter), subst_text, 1)
|
||||
print(" " * indent, subst_text)
|
||||
|
||||
|
||||
def txtbits(bits: bitarray) -> str:
|
||||
@@ -93,8 +91,8 @@ class Item:
|
||||
graphic: int | None = None
|
||||
inherent: int | None = None
|
||||
low_quality: LowQualityType | None = None
|
||||
prefixes: list[Affix] | None = None
|
||||
suffixes: list[Affix] | None = None
|
||||
prefixes: list[int] | None = None
|
||||
suffixes: list[int] | None = None
|
||||
set_id: int | None = None
|
||||
unique_id: int | None = None
|
||||
nameword1: int | None = None
|
||||
@@ -106,6 +104,7 @@ class Item:
|
||||
max_durability: int | None = None
|
||||
sockets: int | None = None
|
||||
quantity: int | None = None
|
||||
stats: list[Stat] | None = None
|
||||
|
||||
def print(self, indent=5, with_raw=False):
|
||||
properties = []
|
||||
@@ -129,13 +128,9 @@ class Item:
|
||||
if self.quality:
|
||||
print(" " * indent, self.quality)
|
||||
if self.prefixes:
|
||||
print(" " * indent, "Prefixes:")
|
||||
for prefix in self.prefixes:
|
||||
prefix.print(indent + 4)
|
||||
print(" " * indent, "Prefixes:", self.prefixes)
|
||||
if self.suffixes:
|
||||
print(" " * indent, "Suffixes:")
|
||||
for suffix in self.suffixes:
|
||||
suffix.print(indent + 4)
|
||||
print(" " * indent, "Suffixes:", self.suffixes)
|
||||
if self.set_id:
|
||||
print(" " * indent, f"Set Id: {self.set_id}") # TODO: name lookup
|
||||
if self.unique_id:
|
||||
@@ -155,6 +150,10 @@ class Item:
|
||||
print(" " * indent, f"Num Sockets: {self.sockets}")
|
||||
if self.quantity:
|
||||
print(" " * indent, f"Quantity: {self.quantity}")
|
||||
if self.stats:
|
||||
print(" " * indent, "Stats:")
|
||||
for stat in self.stats:
|
||||
stat.print(indent + 4)
|
||||
if with_raw:
|
||||
print(" " * indent, "Raw Item Data:")
|
||||
bits = bitarray(endian="little")
|
||||
@@ -172,9 +171,9 @@ def lookup_basetype(code: str) -> dict:
|
||||
return _basetype_map[code]
|
||||
|
||||
|
||||
def lookup_affix(code: int) -> dict:
|
||||
global _affix_map
|
||||
if _affix_map is None:
|
||||
with open(os.path.join(_data_path, "affixes.json")) as f:
|
||||
_affix_map = json.load(f)
|
||||
return _affix_map[str(code)]
|
||||
def lookup_stat(id: int) -> dict:
|
||||
global _stats_map
|
||||
if _stats_map is None:
|
||||
with open(os.path.join(_data_path, "stats.json")) as f:
|
||||
_stats_map = json.load(f)
|
||||
return _stats_map[str(id)]
|
||||
|
||||
Reference in New Issue
Block a user