Add raw_version to the item so we can keep it in the database
This commit is contained in:
@@ -16,4 +16,5 @@
|
||||
# Mercator. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
STASH_TAB_MAGIC = b"\x55\xAA\x55\xAA"
|
||||
STASH_TAB_VERSION = 99
|
||||
ITEM_DATA_MAGIC = b"JM"
|
||||
|
||||
@@ -22,7 +22,7 @@ from bitarray import bitarray
|
||||
from bitarray.util import int2ba
|
||||
from dataclasses import dataclass
|
||||
from enum import IntEnum
|
||||
|
||||
from d2warehouse.fileformat import STASH_TAB_VERSION
|
||||
from d2warehouse.db import get_db
|
||||
|
||||
_data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data")
|
||||
@@ -90,6 +90,7 @@ def txtbits(bits: bitarray) -> str:
|
||||
@dataclass
|
||||
class Item:
|
||||
raw_data: bytes
|
||||
raw_version: int
|
||||
is_identified: bool
|
||||
is_socketed: bool
|
||||
is_beginner: bool
|
||||
@@ -221,19 +222,20 @@ class Item:
|
||||
cur = db.cursor()
|
||||
cur.execute(
|
||||
"""INSERT INTO item (itembase_name, item_name,
|
||||
set_name, socketed_into, raw_data, is_identified, is_socketed,
|
||||
set_name, socketed_into, raw_data, raw_version, is_identified, is_socketed,
|
||||
is_beginner, is_simple, is_ethereal, is_personalized, is_runeword,
|
||||
code, uid, lvl, quality, graphic, implicit, low_quality, set_id,
|
||||
unique_id, nameword1, nameword2, runeword_id, personal_name,
|
||||
defense, durability, max_durability, quantity)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?)""",
|
||||
?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(
|
||||
lookup_basetype(self.code)["name"],
|
||||
name,
|
||||
set_name,
|
||||
socketed_into,
|
||||
self.raw_data,
|
||||
self.raw_version,
|
||||
self.is_identified,
|
||||
self.is_socketed,
|
||||
self.is_beginner,
|
||||
@@ -299,7 +301,7 @@ class Item:
|
||||
def load_from_db(id: int) -> "Item":
|
||||
db = get_db()
|
||||
row = db.execute(
|
||||
"""SELECT raw_data, is_identified, is_socketed,
|
||||
"""SELECT raw_data, raw_version, is_identified, is_socketed,
|
||||
is_beginner, is_simple, is_ethereal, is_personalized, is_runeword, code,
|
||||
uid, lvl, quality, graphic, implicit, low_quality, set_id, unique_id,
|
||||
nameword1, nameword2, runeword_id, personal_name, defense, durability,
|
||||
@@ -307,9 +309,12 @@ class Item:
|
||||
FROM item WHERE id = ?""",
|
||||
(id,),
|
||||
).fetchone()
|
||||
if row["raw_version"] != STASH_TAB_VERSION:
|
||||
raise RuntimeError("Can not load item, the raw version is not supported")
|
||||
|
||||
item = Item(
|
||||
raw_data=row["raw_data"],
|
||||
raw_version=row["raw_version"],
|
||||
is_identified=bool(row["is_identified"]),
|
||||
is_socketed=bool(row["is_socketed"]),
|
||||
is_beginner=bool(row["is_beginner"]),
|
||||
|
||||
@@ -27,7 +27,7 @@ from d2warehouse.item import (
|
||||
lookup_stat,
|
||||
)
|
||||
import d2warehouse.huffman as huffman
|
||||
from d2warehouse.fileformat import STASH_TAB_MAGIC, ITEM_DATA_MAGIC
|
||||
from d2warehouse.fileformat import STASH_TAB_MAGIC, STASH_TAB_VERSION, ITEM_DATA_MAGIC
|
||||
|
||||
|
||||
class ParseError(RuntimeError):
|
||||
@@ -82,7 +82,7 @@ def parse_stash_tab(data: bytes) -> tuple[bytes, StashTab]:
|
||||
|
||||
if unknown != 1:
|
||||
ParseError("Unknown stash tab field is not 1")
|
||||
if version != 99:
|
||||
if version != STASH_TAB_VERSION:
|
||||
ParseError(f"Unsupported stash tab version ({version} instead of 99)")
|
||||
|
||||
tab = StashTab()
|
||||
@@ -133,6 +133,7 @@ def parse_item(data: bytes) -> tuple[bytes, Item]:
|
||||
simple_byte_sz = int((sockets_end + 7) / 8)
|
||||
item = Item(
|
||||
data[:simple_byte_sz],
|
||||
STASH_TAB_VERSION,
|
||||
is_identified,
|
||||
is_socketed,
|
||||
is_beginner,
|
||||
|
||||
@@ -14,6 +14,7 @@ CREATE TABLE item (
|
||||
|
||||
-- The following fields match the fields of the item object in item.py
|
||||
raw_data BLOB NOT NULL,
|
||||
raw_version INTEGER NOT NULL,
|
||||
is_identified BOOLEAN NOT NULL,
|
||||
is_socketed BOOLEAN NOT NULL,
|
||||
is_beginner BOOLEAN NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user