mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-21 15:44:24 +00:00
Small changes
This commit is contained in:
parent
e504bb9802
commit
a8e483e5af
3 changed files with 33 additions and 27 deletions
|
@ -14,14 +14,14 @@ class Tile:
|
|||
block: typing.Optional[Block] = None,
|
||||
wall: typing.Optional[Wall] = None,
|
||||
liquid: typing.Optional[Liquid] = None,
|
||||
wiring: Wiring = None):
|
||||
wiring: typing.Optional[Wiring] = None):
|
||||
if wiring is None:
|
||||
wiring = Wiring()
|
||||
|
||||
self.block: typing.Optional[Block] = block
|
||||
self.wall: typing.Optional[Wall] = wall
|
||||
self.liquid: typing.Optional[Liquid] = liquid
|
||||
self.wiring: Wiring = wiring
|
||||
self.wiring: typing.Optional[Wiring] = wiring
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Tile {'B' if self.block else '_'}{'W' if self.wall else '_'}{'L' if self.liquid else '_'}>"
|
||||
return f"<Tile {'B' if self.block else '_'}{'W' if self.wall else '_'}{'L' if self.liquid else '_'}{'W' if self.wiring else '_'}>"
|
||||
|
|
|
@ -27,3 +27,14 @@ class Wiring:
|
|||
def __repr__(self):
|
||||
return f"Wires(red={self.red}, green={self.green}, blue={self.blue}, yellow={self.yellow}," \
|
||||
f" actuator={self.actuator})"
|
||||
|
||||
def __bool__(self):
|
||||
return self.red or self.green or self.blue or self.yellow or self.actuator
|
||||
|
||||
@classmethod
|
||||
def from_flags(cls, flags2=None, flags3=None):
|
||||
if flags2 is not None:
|
||||
if flags3 is not None:
|
||||
return cls(red=flags2[1], green=flags2[2], blue=flags2[3], yellow=flags3[5], actuator=flags3[1])
|
||||
return cls(red=flags2[1], green=flags2[2], blue=flags2[3])
|
||||
return None
|
||||
|
|
|
@ -152,7 +152,7 @@ class World:
|
|||
self.shadow_orbs = value
|
||||
|
||||
@staticmethod
|
||||
def _read_tiles(fr: FileReader, tileframeimportant) -> typing.List:
|
||||
def _read_tile_block(fr: FileReader, tileframeimportant) -> typing.List:
|
||||
# Once again, this code is a mess
|
||||
flags1 = fr.bits()
|
||||
has_block = flags1[1]
|
||||
|
@ -162,44 +162,42 @@ class World:
|
|||
rle_compression = RLEEncoding.from_flags(flags1)
|
||||
if flags1[0]:
|
||||
flags2 = fr.bits()
|
||||
shape = Shape.from_flags(flags2)
|
||||
block_shape = Shape.from_flags(flags2)
|
||||
if flags2[0]:
|
||||
flags3 = fr.bits()
|
||||
is_active = not flags3[2]
|
||||
wiring = Wiring(red=flags2[1], green=flags2[2], blue=flags2[3], yellow=flags3[5], actuator=flags3[1])
|
||||
is_block_active = not flags3[2]
|
||||
wiring = Wiring.from_flags(flags2, flags3)
|
||||
is_block_painted = flags3[3]
|
||||
is_wall_painted = flags3[4]
|
||||
else:
|
||||
is_active = True
|
||||
wiring = Wiring(red=flags2[1], green=flags2[2], blue=flags2[3])
|
||||
is_block_active = True
|
||||
wiring = Wiring.from_flags(flags2)
|
||||
is_block_painted = False
|
||||
is_wall_painted = False
|
||||
else:
|
||||
shape = Shape.NORMAL
|
||||
is_active = True
|
||||
wiring = Wiring()
|
||||
block_shape = Shape.NORMAL
|
||||
is_block_active = True
|
||||
wiring = None
|
||||
is_block_painted = False
|
||||
is_wall_painted = False
|
||||
if has_block:
|
||||
if has_extended_block_id:
|
||||
block_id = BlockType(fr.uint2())
|
||||
block_type = BlockType(fr.uint2())
|
||||
else:
|
||||
block_id = BlockType(fr.uint1())
|
||||
if tileframeimportant[block_id]:
|
||||
frame_x = fr.uint2()
|
||||
frame_y = fr.uint2()
|
||||
block_type = BlockType(fr.uint1())
|
||||
if tileframeimportant[block_type]:
|
||||
frame = FrameImportantData(fr.uint2(), fr.uint2())
|
||||
else:
|
||||
frame_x = None
|
||||
frame_y = None
|
||||
frame = None
|
||||
if is_block_painted:
|
||||
block_paint = fr.uint1()
|
||||
else:
|
||||
block_paint = None
|
||||
block = Block(type_=block_id,
|
||||
frame=FrameImportantData(frame_x, frame_y),
|
||||
block = Block(type_=block_type,
|
||||
frame=frame,
|
||||
paint=block_paint,
|
||||
is_active=is_active,
|
||||
shape=shape)
|
||||
is_active=is_block_active,
|
||||
shape=block_shape)
|
||||
else:
|
||||
block = None
|
||||
if has_wall:
|
||||
|
@ -480,10 +478,9 @@ class World:
|
|||
with Timer("World Tiles", display=True):
|
||||
tiles = []
|
||||
while len(tiles) < world_size.x:
|
||||
# Read a column
|
||||
column = []
|
||||
while len(column) < world_size.y:
|
||||
readtiles = cls._read_tiles(f, tileframeimportant)
|
||||
readtiles = cls._read_tile_block(f, tileframeimportant)
|
||||
column = [*column, *readtiles]
|
||||
tiles.append(column)
|
||||
|
||||
|
@ -518,8 +515,6 @@ class World:
|
|||
|
||||
unknown_chests_data = f.read_until(pointers.signs)
|
||||
|
||||
breakpoint()
|
||||
|
||||
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