From f63a7abeaa7c4c8c040ae56297921ca7076db445 Mon Sep 17 00:00:00 2001 From: "Yi Yang @ Anteros" Date: Wed, 6 Dec 2023 02:44:57 +0800 Subject: [PATCH] (bridge) new interface (but leaves TODO) --- bridge/bridges/dovemere/test.py | 3 --- bridge/lib/__init__.py | 36 ++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/bridge/bridges/dovemere/test.py b/bridge/bridges/dovemere/test.py index b396cecc..018a038d 100644 --- a/bridge/bridges/dovemere/test.py +++ b/bridge/bridges/dovemere/test.py @@ -16,9 +16,6 @@ the_bridge = ABridge( id=0x01, name="Test Bridge", - front=None, - back=None, - pillar=None, intro_year_since_1920=0, min_length=4, max_length=32, diff --git a/bridge/lib/__init__.py b/bridge/lib/__init__.py index f29d65ed..b1383826 100644 --- a/bridge/lib/__init__.py +++ b/bridge/lib/__init__.py @@ -17,17 +17,26 @@ class ASingleTypeBridgeLayout: flat: Tuple[SpritePair, SpritePair] ramp: Tuple[SpritePair, SpritePair] + @staticmethod + def one_grid_layout(back, front, pillars, flat, ramp): + return ASingleTypeBridgeLayout((back,) * 6, (front,) * 6, (pillars,) * 6, flat, ramp) + @dataclass class ABridgeLayout: - railX: ASingleTypeBridgeLayout - railY: ASingleTypeBridgeLayout - roadX: ASingleTypeBridgeLayout - roadY: ASingleTypeBridgeLayout - monoX: ASingleTypeBridgeLayout - monoY: ASingleTypeBridgeLayout - mlevX: ASingleTypeBridgeLayout - mlevY: ASingleTypeBridgeLayout + rail: ASingleTypeBridgeLayout + road: ASingleTypeBridgeLayout + mono: ASingleTypeBridgeLayout + mlev: ASingleTypeBridgeLayout + + @staticmethod + def make_universal(single_layout): + return ABridgeLayout( + rail=single_layout, + road=single_layout, + mono=single_layout, + mlev=single_layout, + ) class ABridge(grf.SpriteGenerator): @@ -36,9 +45,7 @@ def __init__( *, id, name, - back, - front, - pillar, + layout: ABridgeLayout, purchase_text=None, description_rail=None, description_road=None, @@ -47,14 +54,15 @@ def __init__( super().__init__() self.id = id self.name = name - self.back = back - self.front = front - self.pillar = pillar + self.layout = layout self.purchase_text = purchase_text self.description_rail = description_rail self.description_road = description_road self._props = props + # FIXME: supprt new layout abstraction + self._props["layout"] = layout + def get_sprites(self, g): extra_props = {} if self.purchase_text: