mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-21 15:44:24 +00:00
Parse NPC data
This commit is contained in:
parent
ff982e207c
commit
d9f7afe199
4 changed files with 43 additions and 0 deletions
|
@ -80,5 +80,8 @@ class FileReader:
|
|||
data += self.file.read(1)
|
||||
return data
|
||||
|
||||
def skip_until(self, address: int) -> None:
|
||||
self.file.seek(address)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<FileReader at {hex(self.file.tell())}>"
|
||||
|
|
3
lihzahrd/npcs/__init__.py
Normal file
3
lihzahrd/npcs/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from .npc import NPC
|
||||
|
||||
__all__ = ["NPC"]
|
18
lihzahrd/npcs/npc.py
Normal file
18
lihzahrd/npcs/npc.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import typing
|
||||
from ..fileutils import Coordinates
|
||||
|
||||
|
||||
class NPC:
|
||||
"""A NPC somewhere in the world."""
|
||||
def __init__(self,
|
||||
sprite_id: int,
|
||||
name: str,
|
||||
position: Coordinates,
|
||||
home: typing.Optional[Coordinates] = None):
|
||||
self.sprite_id: int = sprite_id
|
||||
self.name: str = name
|
||||
self.position: Coordinates = position
|
||||
self.home: typing.Optional[Coordinates] = home
|
||||
|
||||
def __repr__(self):
|
||||
return f"<NPC {self.name if self.name else '_'} at {self.position}>"
|
|
@ -6,6 +6,7 @@ from .header import *
|
|||
from .tiles import *
|
||||
from .chests import *
|
||||
from .signs import *
|
||||
from .npcs import *
|
||||
from .timer import Timer
|
||||
|
||||
|
||||
|
@ -527,6 +528,24 @@ class World:
|
|||
|
||||
unknown_signs_data = f.read_until(pointers.npcs)
|
||||
|
||||
with Timer("NPCs", display=True):
|
||||
npcs = []
|
||||
|
||||
while f.bool():
|
||||
npc_sprite_id = f.int4()
|
||||
npc_name = f.string()
|
||||
npc_position = Coordinates(f.single(), f.single())
|
||||
is_homeless = f.bool()
|
||||
npc_home = Coordinates(f.int4(), f.int4())
|
||||
if is_homeless:
|
||||
npc_home = None
|
||||
|
||||
npc = NPC(sprite_id=npc_sprite_id,
|
||||
name=npc_name,
|
||||
position=npc_position,
|
||||
home=npc_home)
|
||||
npcs.append(npc)
|
||||
|
||||
world = World(version=version, savefile_type=savefile_type, revision=revision, is_favorite=is_favorite,
|
||||
name=name, generator=generator, uuid_=uuid_, id_=id_, bounds=bounds, size=world_size,
|
||||
is_expert=is_expert, created_on=created_on, styles=world_styles, backgrounds=backgrounds,
|
||||
|
|
Loading…
Reference in a new issue