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

Optimize a few functions... I think.

This commit is contained in:
Steffo 2020-06-08 03:15:23 +02:00
parent f8dd891538
commit b6ef29fb78
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
6 changed files with 32 additions and 9 deletions

View file

@ -4,6 +4,7 @@ from .itemtype import ItemType
from .liquidtype import LiquidType
from .walltype import WallType
from .prefixtype import PrefixType
from .rleencoding import RLEEncoding
__all__ = [
"BlockType",
@ -12,4 +13,5 @@ __all__ = [
"LiquidType",
"WallType",
"PrefixType",
"RLEEncoding",
]

View file

@ -1,4 +1,5 @@
import enum
import functools
class LiquidType(enum.IntEnum):
@ -10,11 +11,16 @@ class LiquidType(enum.IntEnum):
@classmethod
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
if flags1[4]:
if flags14:
return cls.LAVA
if flags1[3]:
if flags13:
return cls.WATER
return cls.NO_LIQUID

View file

@ -1,5 +1,6 @@
from typing import *
import enum
import functools
class PrefixType(enum.IntEnum):
@ -89,6 +90,7 @@ class PrefixType(enum.IntEnum):
Legendary2 = 84
@classmethod
@functools.lru_cache(85)
def get(cls, i: int) -> Optional["PrefixType"]:
if i == 0:
return None

View file

@ -1,4 +1,5 @@
import enum
import functools
class RLEEncoding(enum.IntEnum):
@ -15,4 +16,9 @@ class RLEEncoding(enum.IntEnum):
@classmethod
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)

View file

@ -1,4 +1,3 @@
from .rleencoding import RLEEncoding
from .shape import Shape
from .wiring import Wiring
from .frameimportantdata import FrameImportantData
@ -8,5 +7,5 @@ from .liquid import Liquid
from .tile import Tile
from .tilematrix import TileMatrix
__all__ = ["RLEEncoding", "Shape", "Wiring", "FrameImportantData", "Block",
__all__ = ["Shape", "Wiring", "FrameImportantData", "Block",
"Wall", "Liquid", "Tile", "TileMatrix"]

View file

@ -1,3 +1,6 @@
import functools
class Wiring:
"""Wiring data for a certain tile."""
@ -35,6 +38,11 @@ class Wiring:
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 cls()
return cls._from_flags(flags2[1], flags2[2], flags2[3], flags3[1], flags3[5])
return cls._from_flags(flags2[1], flags2[2], flags2[3], False, False)
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)