mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-24 00:54:23 +00:00
Refactor _read_tile_block
and implement Coatings
This commit is contained in:
parent
5137edf63f
commit
e62d6fb24f
4 changed files with 66 additions and 37 deletions
|
@ -1,6 +1,6 @@
|
||||||
from .filereader import FileReader
|
from .filereader import FileReader, INT_TO_BITS_CACHE
|
||||||
from .rect import Rect
|
from .rect import Rect
|
||||||
from .pointers import Pointers
|
from .pointers import Pointers
|
||||||
from .coordinates import Coordinates
|
from .coordinates import Coordinates
|
||||||
|
|
||||||
__all__ = ["FileReader", "Rect", "Pointers", "Coordinates"]
|
__all__ = ["FileReader", "INT_TO_BITS_CACHE", "Rect", "Pointers", "Coordinates"]
|
||||||
|
|
|
@ -7,7 +7,7 @@ from .shape import Shape
|
||||||
class Block:
|
class Block:
|
||||||
"""A block that has been placed in the world."""
|
"""A block that has been placed in the world."""
|
||||||
|
|
||||||
__slots__ = "type", "frame", "shape", "paint", "is_active"
|
__slots__ = "type", "frame", "shape", "paint", "is_active", "is_illuminant", "is_echo"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -16,6 +16,8 @@ class Block:
|
||||||
frame: typing.Optional[FrameImportantData] = None,
|
frame: typing.Optional[FrameImportantData] = None,
|
||||||
paint: typing.Optional[int] = None,
|
paint: typing.Optional[int] = None,
|
||||||
is_active: bool = True,
|
is_active: bool = True,
|
||||||
|
is_illuminant: bool = False,
|
||||||
|
is_echo: bool = False,
|
||||||
):
|
):
|
||||||
self.type: BlockType = type_
|
self.type: BlockType = type_
|
||||||
"""The type of the block (dirt, stone, ...)."""
|
"""The type of the block (dirt, stone, ...)."""
|
||||||
|
@ -32,5 +34,11 @@ class Block:
|
||||||
self.is_active: bool = is_active
|
self.is_active: bool = is_active
|
||||||
"""If the block is solid or can be passed through because of an Actuator."""
|
"""If the block is solid or can be passed through because of an Actuator."""
|
||||||
|
|
||||||
|
self.is_illuminant: bool = is_illuminant
|
||||||
|
"""If the block had Illuminant Coating applied, and is unaffected by lighting."""
|
||||||
|
|
||||||
|
self.is_echo: bool = is_echo
|
||||||
|
"""If the block had Echo Coating applied, and is invisible."""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Block(type_={repr(self.type)}, frame={self.frame}, paint={self.paint}, is_active={self.is_active})"
|
return f"Block(type_={repr(self.type)}, frame={self.frame}, shape={self.shape}, paint={self.paint}, is_active={self.is_active}, is_illuminant={self.is_illuminant}, is_echo={self.is_echo})"
|
||||||
|
|
|
@ -5,11 +5,23 @@ from ..enums import WallType
|
||||||
class Wall:
|
class Wall:
|
||||||
"""A wall that has been placed in the world."""
|
"""A wall that has been placed in the world."""
|
||||||
|
|
||||||
__slots__ = "type", "paint"
|
__slots__ = "type", "paint", "is_illuminant", "is_echo"
|
||||||
|
|
||||||
def __init__(self, type_: WallType, paint: typing.Optional[int] = None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
type_: WallType,
|
||||||
|
paint: typing.Optional[int] = None,
|
||||||
|
is_illuminant: bool = False,
|
||||||
|
is_echo: bool = False,
|
||||||
|
):
|
||||||
self.type: WallType = type_
|
self.type: WallType = type_
|
||||||
self.paint: typing.Optional[int] = paint
|
self.paint: typing.Optional[int] = paint
|
||||||
|
|
||||||
|
self.is_illuminant: bool = is_illuminant
|
||||||
|
"""If the wall had Illuminant Coating applied, and is unaffected by lighting."""
|
||||||
|
|
||||||
|
self.is_echo: bool = is_echo
|
||||||
|
"""If the wall had Echo Coating applied, and is invisible."""
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Wall(type_={repr(self.type)}, paint={self.paint})"
|
return f"Wall(type_={repr(self.type)}, paint={self.paint}, is_illuminant={self.is_illuminant}, is_echo={self.is_echo})"
|
||||||
|
|
|
@ -248,39 +248,33 @@ class World:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read_tile_block(fr: FileReader, tileframeimportant) -> Tuple[Tile, int]:
|
def _read_tile_block(fr: FileReader, tileframeimportant) -> Tuple[Tile, int]:
|
||||||
# Once again, this code is a mess
|
|
||||||
flags1 = fr.bits()
|
flags1 = fr.bits()
|
||||||
|
has_flags2 = flags1[0]
|
||||||
|
flags2 = fr.bits() if has_flags2 else INT_TO_BITS_CACHE[0]
|
||||||
|
has_flags3 = flags2[0]
|
||||||
|
flags3 = fr.bits() if has_flags3 else INT_TO_BITS_CACHE[0]
|
||||||
|
has_flags4 = flags3[0]
|
||||||
|
flags4 = fr.bits() if has_flags4 else INT_TO_BITS_CACHE[0]
|
||||||
|
|
||||||
has_block = flags1[1]
|
has_block = flags1[1]
|
||||||
has_wall = flags1[2]
|
has_wall = flags1[2]
|
||||||
|
|
||||||
has_extended_block_id = flags1[5]
|
has_extended_block_id = flags1[5]
|
||||||
|
has_extended_wall_id = flags3[6]
|
||||||
|
|
||||||
|
is_block_active = not flags3[2]
|
||||||
|
is_block_painted = flags3[3]
|
||||||
|
is_wall_painted = flags3[4]
|
||||||
|
is_block_echo = flags4[1]
|
||||||
|
is_wall_echo = flags4[2]
|
||||||
|
is_block_illuminant = flags4[3]
|
||||||
|
is_wall_illuminant = flags4[4]
|
||||||
|
|
||||||
|
liquid_type = LiquidType.from_flags(flags1, flags3)
|
||||||
rle_compression = RLEEncoding.from_flags(flags1)
|
rle_compression = RLEEncoding.from_flags(flags1)
|
||||||
# Parse flags
|
block_shape = Shape.from_flags(flags2)
|
||||||
if flags1[0]:
|
wiring = Wiring.from_flags(flags2, flags3)
|
||||||
flags2 = fr.bits()
|
|
||||||
block_shape = Shape.from_flags(flags2)
|
|
||||||
if flags2[0]:
|
|
||||||
flags3 = fr.bits()
|
|
||||||
liquid_type = LiquidType.from_flags(flags1)
|
|
||||||
is_block_active = not flags3[2]
|
|
||||||
wiring = Wiring.from_flags(flags2, flags3)
|
|
||||||
is_block_painted = flags3[3]
|
|
||||||
is_wall_painted = flags3[4]
|
|
||||||
has_extended_wall_id = flags3[6]
|
|
||||||
else:
|
|
||||||
is_block_active = True
|
|
||||||
liquid_type = LiquidType.from_flags(flags1)
|
|
||||||
wiring = Wiring.from_flags(flags2)
|
|
||||||
is_block_painted = False
|
|
||||||
is_wall_painted = False
|
|
||||||
has_extended_wall_id = False
|
|
||||||
else:
|
|
||||||
liquid_type = LiquidType.from_flags(flags1)
|
|
||||||
block_shape = Shape.NORMAL
|
|
||||||
is_block_active = True
|
|
||||||
wiring = None
|
|
||||||
is_block_painted = False
|
|
||||||
is_wall_painted = False
|
|
||||||
has_extended_wall_id = False
|
|
||||||
# Parse block
|
# Parse block
|
||||||
if has_block:
|
if has_block:
|
||||||
if has_extended_block_id:
|
if has_extended_block_id:
|
||||||
|
@ -296,10 +290,17 @@ class World:
|
||||||
else:
|
else:
|
||||||
block_paint = None
|
block_paint = None
|
||||||
block = Block(
|
block = Block(
|
||||||
type_=block_type, frame=frame, paint=block_paint, is_active=is_block_active, shape=block_shape
|
type_=block_type,
|
||||||
|
frame=frame,
|
||||||
|
paint=block_paint,
|
||||||
|
is_active=is_block_active,
|
||||||
|
shape=block_shape,
|
||||||
|
is_illuminant=is_block_illuminant,
|
||||||
|
is_echo=is_block_echo,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
block = None
|
block = None
|
||||||
|
|
||||||
# Parse wall
|
# Parse wall
|
||||||
if has_wall:
|
if has_wall:
|
||||||
if has_extended_wall_id:
|
if has_extended_wall_id:
|
||||||
|
@ -310,14 +311,21 @@ class World:
|
||||||
wall_paint = fr.uint1()
|
wall_paint = fr.uint1()
|
||||||
else:
|
else:
|
||||||
wall_paint = None
|
wall_paint = None
|
||||||
wall = Wall(type_=wall_type, paint=wall_paint)
|
wall = Wall(
|
||||||
|
type_=wall_type,
|
||||||
|
paint=wall_paint,
|
||||||
|
is_illuminant=is_wall_illuminant,
|
||||||
|
is_echo=is_wall_echo,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
wall = None
|
wall = None
|
||||||
|
|
||||||
# Parse liquid
|
# Parse liquid
|
||||||
if liquid_type != LiquidType.NO_LIQUID:
|
if liquid_type != LiquidType.NO_LIQUID:
|
||||||
liquid = Liquid(type_=liquid_type, volume=fr.uint1())
|
liquid = Liquid(type_=liquid_type, volume=fr.uint1())
|
||||||
else:
|
else:
|
||||||
liquid = None
|
liquid = None
|
||||||
|
|
||||||
# Find RLE Compression multiplier
|
# Find RLE Compression multiplier
|
||||||
if rle_compression == RLEEncoding.DOUBLE_BYTE:
|
if rle_compression == RLEEncoding.DOUBLE_BYTE:
|
||||||
multiply_by = fr.uint2() + 1
|
multiply_by = fr.uint2() + 1
|
||||||
|
@ -325,6 +333,7 @@ class World:
|
||||||
multiply_by = fr.uint1() + 1
|
multiply_by = fr.uint1() + 1
|
||||||
else:
|
else:
|
||||||
multiply_by = 1
|
multiply_by = 1
|
||||||
|
|
||||||
# Create tile
|
# Create tile
|
||||||
tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring)
|
tile = Tile(block=block, wall=wall, liquid=liquid, wiring=wiring)
|
||||||
return tile, multiply_by
|
return tile, multiply_by
|
||||||
|
|
Loading…
Reference in a new issue