1
Fork 0
mirror of https://github.com/Steffo99/lihzahrd.git synced 2024-11-25 01:24:21 +00:00

Small changes

This commit is contained in:
Steffo 2019-08-12 16:15:12 +02:00
parent e504bb9802
commit a8e483e5af
3 changed files with 33 additions and 27 deletions

View file

@ -14,14 +14,14 @@ class Tile:
block: typing.Optional[Block] = None, block: typing.Optional[Block] = None,
wall: typing.Optional[Wall] = None, wall: typing.Optional[Wall] = None,
liquid: typing.Optional[Liquid] = None, liquid: typing.Optional[Liquid] = None,
wiring: Wiring = None): wiring: typing.Optional[Wiring] = None):
if wiring is None: if wiring is None:
wiring = Wiring() wiring = Wiring()
self.block: typing.Optional[Block] = block self.block: typing.Optional[Block] = block
self.wall: typing.Optional[Wall] = wall self.wall: typing.Optional[Wall] = wall
self.liquid: typing.Optional[Liquid] = liquid self.liquid: typing.Optional[Liquid] = liquid
self.wiring: Wiring = wiring self.wiring: typing.Optional[Wiring] = wiring
def __repr__(self): 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 '_'}>"

View file

@ -27,3 +27,14 @@ class Wiring:
def __repr__(self): def __repr__(self):
return f"Wires(red={self.red}, green={self.green}, blue={self.blue}, yellow={self.yellow}," \ return f"Wires(red={self.red}, green={self.green}, blue={self.blue}, yellow={self.yellow}," \
f" actuator={self.actuator})" 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

View file

@ -152,7 +152,7 @@ class World:
self.shadow_orbs = value self.shadow_orbs = value
@staticmethod @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 # Once again, this code is a mess
flags1 = fr.bits() flags1 = fr.bits()
has_block = flags1[1] has_block = flags1[1]
@ -162,44 +162,42 @@ class World:
rle_compression = RLEEncoding.from_flags(flags1) rle_compression = RLEEncoding.from_flags(flags1)
if flags1[0]: if flags1[0]:
flags2 = fr.bits() flags2 = fr.bits()
shape = Shape.from_flags(flags2) block_shape = Shape.from_flags(flags2)
if flags2[0]: if flags2[0]:
flags3 = fr.bits() flags3 = fr.bits()
is_active = not flags3[2] is_block_active = not flags3[2]
wiring = Wiring(red=flags2[1], green=flags2[2], blue=flags2[3], yellow=flags3[5], actuator=flags3[1]) wiring = Wiring.from_flags(flags2, flags3)
is_block_painted = flags3[3] is_block_painted = flags3[3]
is_wall_painted = flags3[4] is_wall_painted = flags3[4]
else: else:
is_active = True is_block_active = True
wiring = Wiring(red=flags2[1], green=flags2[2], blue=flags2[3]) wiring = Wiring.from_flags(flags2)
is_block_painted = False is_block_painted = False
is_wall_painted = False is_wall_painted = False
else: else:
shape = Shape.NORMAL block_shape = Shape.NORMAL
is_active = True is_block_active = True
wiring = Wiring() wiring = None
is_block_painted = False is_block_painted = False
is_wall_painted = False is_wall_painted = False
if has_block: if has_block:
if has_extended_block_id: if has_extended_block_id:
block_id = BlockType(fr.uint2()) block_type = BlockType(fr.uint2())
else: else:
block_id = BlockType(fr.uint1()) block_type = BlockType(fr.uint1())
if tileframeimportant[block_id]: if tileframeimportant[block_type]:
frame_x = fr.uint2() frame = FrameImportantData(fr.uint2(), fr.uint2())
frame_y = fr.uint2()
else: else:
frame_x = None frame = None
frame_y = None
if is_block_painted: if is_block_painted:
block_paint = fr.uint1() block_paint = fr.uint1()
else: else:
block_paint = None block_paint = None
block = Block(type_=block_id, block = Block(type_=block_type,
frame=FrameImportantData(frame_x, frame_y), frame=frame,
paint=block_paint, paint=block_paint,
is_active=is_active, is_active=is_block_active,
shape=shape) shape=block_shape)
else: else:
block = None block = None
if has_wall: if has_wall:
@ -480,10 +478,9 @@ class World:
with Timer("World Tiles", display=True): with Timer("World Tiles", display=True):
tiles = [] tiles = []
while len(tiles) < world_size.x: while len(tiles) < world_size.x:
# Read a column
column = [] column = []
while len(column) < world_size.y: while len(column) < world_size.y:
readtiles = cls._read_tiles(f, tileframeimportant) readtiles = cls._read_tile_block(f, tileframeimportant)
column = [*column, *readtiles] column = [*column, *readtiles]
tiles.append(column) tiles.append(column)
@ -518,8 +515,6 @@ class World:
unknown_chests_data = f.read_until(pointers.signs) unknown_chests_data = f.read_until(pointers.signs)
breakpoint()
world = World(version=version, savefile_type=savefile_type, revision=revision, is_favorite=is_favorite, 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, 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, is_expert=is_expert, created_on=created_on, styles=world_styles, backgrounds=backgrounds,