mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-21 15:44:24 +00:00
Parse chests data
This commit is contained in:
parent
b34ed326d0
commit
d677fb18de
8 changed files with 4060 additions and 27 deletions
|
@ -0,0 +1,5 @@
|
||||||
|
from .itemtype import ItemType
|
||||||
|
from .itemstack import ItemStack
|
||||||
|
from .chest import Chest
|
||||||
|
|
||||||
|
__all__ = ["ItemType", "ItemStack", "Chest"]
|
14
lihzahrd/chests/chest.py
Normal file
14
lihzahrd/chests/chest.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import typing
|
||||||
|
from .itemstack import ItemStack
|
||||||
|
from ..fileutils import Coordinates
|
||||||
|
|
||||||
|
|
||||||
|
class Chest:
|
||||||
|
"""A chest with its contents."""
|
||||||
|
def __init__(self, position: Coordinates, name: str, contents: typing.List[ItemStack]):
|
||||||
|
self.position: Coordinates = position
|
||||||
|
self.name: str = name
|
||||||
|
self.contents: typing.List[ItemStack] = contents
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<Chest '{self.name}' at {self.position}>"
|
21
lihzahrd/chests/itemstack.py
Normal file
21
lihzahrd/chests/itemstack.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from .itemtype import ItemType
|
||||||
|
|
||||||
|
|
||||||
|
class ItemStack:
|
||||||
|
"""A stack of a certain item."""
|
||||||
|
def __init__(self,
|
||||||
|
type_: ItemType,
|
||||||
|
quantity: int = 1,
|
||||||
|
modifier: int = 0):
|
||||||
|
|
||||||
|
self.type: ItemType = type_
|
||||||
|
"""The type of item represented in this stack."""
|
||||||
|
|
||||||
|
self.quantity: int = quantity
|
||||||
|
"""A number from 1 to 999 representing the number of items inside this stack."""
|
||||||
|
|
||||||
|
self.modifier: int = modifier
|
||||||
|
"""The modifier of the item in this stack. Should be set only when quantity is 1."""
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"<ItemStack of {self.quantity}x {repr(self.type)} ({self.modifier})>"
|
3989
lihzahrd/chests/itemtype.py
Normal file
3989
lihzahrd/chests/itemtype.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,5 +1,6 @@
|
||||||
from .filereader import FileReader
|
from .filereader import FileReader
|
||||||
from .rect import Rect
|
from .rect import Rect
|
||||||
from .pointers import Pointers
|
from .pointers import Pointers
|
||||||
|
from .coordinates import Coordinates
|
||||||
|
|
||||||
__all__ = ["FileReader", "Rect", "Pointers"]
|
__all__ = ["FileReader", "Rect", "Pointers", "Coordinates"]
|
||||||
|
|
|
@ -4,7 +4,6 @@ from .anglerquestfish import AnglerQuestFish
|
||||||
from .backgrounds import Backgrounds
|
from .backgrounds import Backgrounds
|
||||||
from .bossesdefeated import BossesDefeated
|
from .bossesdefeated import BossesDefeated
|
||||||
from .clouds import Clouds
|
from .clouds import Clouds
|
||||||
from .coordinates import Coordinates
|
|
||||||
from .events import Events
|
from .events import Events
|
||||||
from .fourpartsplit import FourPartSplit
|
from .fourpartsplit import FourPartSplit
|
||||||
from .generatorinfo import GeneratorInfo
|
from .generatorinfo import GeneratorInfo
|
||||||
|
@ -33,7 +32,6 @@ __all__ = [
|
||||||
"Backgrounds",
|
"Backgrounds",
|
||||||
"BossesDefeated",
|
"BossesDefeated",
|
||||||
"Clouds",
|
"Clouds",
|
||||||
"Coordinates",
|
|
||||||
"Events",
|
"Events",
|
||||||
"FourPartSplit",
|
"FourPartSplit",
|
||||||
"GeneratorInfo",
|
"GeneratorInfo",
|
||||||
|
@ -57,17 +55,3 @@ __all__ = [
|
||||||
"Version",
|
"Version",
|
||||||
"WorldEvilType"
|
"WorldEvilType"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,11 @@ class World:
|
||||||
clouds: Clouds,
|
clouds: Clouds,
|
||||||
cultist_delay: int,
|
cultist_delay: int,
|
||||||
tiles: typing.List[typing.List[Tile]],
|
tiles: typing.List[typing.List[Tile]],
|
||||||
|
chests: typing.List[Chest],
|
||||||
unknown_file_format_data: bytearray,
|
unknown_file_format_data: bytearray,
|
||||||
unknown_world_header_data: bytearray,
|
unknown_world_header_data: bytearray,
|
||||||
unknown_world_tiles_data: bytearray):
|
unknown_world_tiles_data: bytearray,
|
||||||
|
unknown_chests_data: bytearray):
|
||||||
|
|
||||||
self.version: Version = version
|
self.version: Version = version
|
||||||
"""The game version when this savefile was last saved."""
|
"""The game version when this savefile was last saved."""
|
||||||
|
@ -127,6 +129,8 @@ class World:
|
||||||
self.anglers_quest: AnglerQuest = anglers_quest
|
self.anglers_quest: AnglerQuest = anglers_quest
|
||||||
"""Information about today's Angler's Quest."""
|
"""Information about today's Angler's Quest."""
|
||||||
|
|
||||||
|
self.chests: typing.List[Chest] = chests
|
||||||
|
|
||||||
self.tiles: typing.List[typing.List[Tile]] = tiles
|
self.tiles: typing.List[typing.List[Tile]] = tiles
|
||||||
|
|
||||||
self.clouds: Clouds = clouds
|
self.clouds: Clouds = clouds
|
||||||
|
@ -134,6 +138,7 @@ class World:
|
||||||
self.unknown_file_format_data: bytearray = unknown_file_format_data
|
self.unknown_file_format_data: bytearray = unknown_file_format_data
|
||||||
self.unknown_world_header_data: bytearray = unknown_world_header_data
|
self.unknown_world_header_data: bytearray = unknown_world_header_data
|
||||||
self.unknown_world_tiles_data: bytearray = unknown_world_tiles_data
|
self.unknown_world_tiles_data: bytearray = unknown_world_tiles_data
|
||||||
|
self.unknown_chests_data: bytearray = unknown_chests_data
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f'<World "{self.name}">'
|
return f'<World "{self.name}">'
|
||||||
|
@ -490,15 +495,28 @@ class World:
|
||||||
chests_count = f.int2()
|
chests_count = f.int2()
|
||||||
chests_max_items = f.int2()
|
chests_max_items = f.int2()
|
||||||
|
|
||||||
for _ in range(chests_max_items):
|
for _ in range(chests_count):
|
||||||
chest_x = f.int4()
|
chest_position = Coordinates(x=f.int4(), y=f.int4())
|
||||||
chest_y = f.int4()
|
|
||||||
chest_name = f.string()
|
chest_name = f.string()
|
||||||
|
chest_contents = []
|
||||||
|
|
||||||
item_count = f.int2()
|
for _ in range(chests_max_items):
|
||||||
if item_count > 0:
|
item_quantity = f.int2()
|
||||||
item_id = f.int4()
|
if item_quantity > 0:
|
||||||
item_prefix = f.uint1()
|
item_type = ItemType(f.int4())
|
||||||
|
item_modifier = f.uint1()
|
||||||
|
item = ItemStack(quantity=item_quantity,
|
||||||
|
type_=item_type,
|
||||||
|
modifier=item_modifier)
|
||||||
|
else:
|
||||||
|
item = None
|
||||||
|
chest_contents.append(item)
|
||||||
|
chest = Chest(position=chest_position,
|
||||||
|
name=chest_name,
|
||||||
|
contents=chest_contents)
|
||||||
|
chests.append(chest)
|
||||||
|
|
||||||
|
unknown_chests_data = f.read_until(pointers.signs)
|
||||||
|
|
||||||
breakpoint()
|
breakpoint()
|
||||||
|
|
||||||
|
@ -509,8 +527,9 @@ class World:
|
||||||
time=time, events=events, dungeon_point=dungeon_point, world_evil=world_evil,
|
time=time, events=events, dungeon_point=dungeon_point, world_evil=world_evil,
|
||||||
saved_npcs=saved_npcs, altars_smashed=altars_smashed, is_hardmode=is_hardmode,
|
saved_npcs=saved_npcs, altars_smashed=altars_smashed, is_hardmode=is_hardmode,
|
||||||
shadow_orbs=shadow_orbs, bosses_defeated=bosses_defeated, anglers_quest=anglers_quest,
|
shadow_orbs=shadow_orbs, bosses_defeated=bosses_defeated, anglers_quest=anglers_quest,
|
||||||
clouds=clouds, cultist_delay=cultist_delay, tiles=tiles,
|
clouds=clouds, cultist_delay=cultist_delay, tiles=tiles, chests=chests,
|
||||||
unknown_file_format_data=unknown_file_format_data,
|
unknown_file_format_data=unknown_file_format_data,
|
||||||
unknown_world_header_data=unknown_world_header_data,
|
unknown_world_header_data=unknown_world_header_data,
|
||||||
unknown_world_tiles_data=unknown_world_tiles_data)
|
unknown_world_tiles_data=unknown_world_tiles_data,
|
||||||
|
unknown_chests_data=unknown_chests_data)
|
||||||
return world
|
return world
|
||||||
|
|
Loading…
Reference in a new issue