mirror of
https://github.com/Steffo99/lihzahrd.git
synced 2024-11-21 15:44:24 +00:00
Optimize a few functions... I think.
This commit is contained in:
parent
af58d2e911
commit
7f229490b8
6 changed files with 32 additions and 9 deletions
|
@ -4,6 +4,7 @@ from .itemtype import ItemType
|
||||||
from .liquidtype import LiquidType
|
from .liquidtype import LiquidType
|
||||||
from .walltype import WallType
|
from .walltype import WallType
|
||||||
from .prefixtype import PrefixType
|
from .prefixtype import PrefixType
|
||||||
|
from .rleencoding import RLEEncoding
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"BlockType",
|
"BlockType",
|
||||||
|
@ -12,4 +13,5 @@ __all__ = [
|
||||||
"LiquidType",
|
"LiquidType",
|
||||||
"WallType",
|
"WallType",
|
||||||
"PrefixType",
|
"PrefixType",
|
||||||
|
"RLEEncoding",
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import enum
|
import enum
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class LiquidType(enum.IntEnum):
|
class LiquidType(enum.IntEnum):
|
||||||
|
@ -10,11 +11,16 @@ class LiquidType(enum.IntEnum):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_flags(cls, flags1):
|
def from_flags(cls, flags1):
|
||||||
if flags1[3] and flags1[4]:
|
return cls._from_flags(flags1[3], flags1[4])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@functools.lru_cache(4)
|
||||||
|
def _from_flags(cls, flags13, flags14):
|
||||||
|
if flags13 and flags14:
|
||||||
return cls.HONEY
|
return cls.HONEY
|
||||||
if flags1[4]:
|
if flags14:
|
||||||
return cls.LAVA
|
return cls.LAVA
|
||||||
if flags1[3]:
|
if flags13:
|
||||||
return cls.WATER
|
return cls.WATER
|
||||||
return cls.NO_LIQUID
|
return cls.NO_LIQUID
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from typing import *
|
from typing import *
|
||||||
import enum
|
import enum
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class PrefixType(enum.IntEnum):
|
class PrefixType(enum.IntEnum):
|
||||||
|
@ -89,6 +90,7 @@ class PrefixType(enum.IntEnum):
|
||||||
Legendary2 = 84
|
Legendary2 = 84
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@functools.lru_cache(85)
|
||||||
def get(cls, i: int) -> Optional["PrefixType"]:
|
def get(cls, i: int) -> Optional["PrefixType"]:
|
||||||
if i == 0:
|
if i == 0:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import enum
|
import enum
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class RLEEncoding(enum.IntEnum):
|
class RLEEncoding(enum.IntEnum):
|
||||||
|
@ -15,4 +16,9 @@ class RLEEncoding(enum.IntEnum):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_flags(cls, flags1):
|
def from_flags(cls, flags1):
|
||||||
return cls(flags1[7] * 2 + flags1[6])
|
return cls._from_flags(flags1[6], flags1[7])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@functools.lru_cache(3)
|
||||||
|
def _from_flags(cls, flags16, flags17):
|
||||||
|
return cls(flags17 * 2 + flags16)
|
|
@ -1,4 +1,3 @@
|
||||||
from .rleencoding import RLEEncoding
|
|
||||||
from .shape import Shape
|
from .shape import Shape
|
||||||
from .wiring import Wiring
|
from .wiring import Wiring
|
||||||
from .frameimportantdata import FrameImportantData
|
from .frameimportantdata import FrameImportantData
|
||||||
|
@ -8,5 +7,5 @@ from .liquid import Liquid
|
||||||
from .tile import Tile
|
from .tile import Tile
|
||||||
from .tilematrix import TileMatrix
|
from .tilematrix import TileMatrix
|
||||||
|
|
||||||
__all__ = ["RLEEncoding", "Shape", "Wiring", "FrameImportantData", "Block",
|
__all__ = ["Shape", "Wiring", "FrameImportantData", "Block",
|
||||||
"Wall", "Liquid", "Tile", "TileMatrix"]
|
"Wall", "Liquid", "Tile", "TileMatrix"]
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
import functools
|
||||||
|
|
||||||
|
|
||||||
class Wiring:
|
class Wiring:
|
||||||
"""Wiring data for a certain tile."""
|
"""Wiring data for a certain tile."""
|
||||||
|
|
||||||
|
@ -35,6 +38,11 @@ class Wiring:
|
||||||
def from_flags(cls, flags2=None, flags3=None):
|
def from_flags(cls, flags2=None, flags3=None):
|
||||||
if flags2 is not None:
|
if flags2 is not None:
|
||||||
if flags3 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._from_flags(flags2[1], flags2[2], flags2[3], flags3[1], flags3[5])
|
||||||
return cls(red=flags2[1], green=flags2[2], blue=flags2[3])
|
return cls._from_flags(flags2[1], flags2[2], flags2[3], False, False)
|
||||||
return cls()
|
return cls._from_flags(False, False, False, False, False)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@functools.lru_cache(32)
|
||||||
|
def _from_flags(cls, flags21, flags22, flags23, flags31, flags35):
|
||||||
|
return cls(red=flags21, green=flags22, blue=flags23, yellow=flags35, actuator=flags31)
|
||||||
|
|
Loading…
Reference in a new issue