Skip to content

Commit

Permalink
(station) Handle defaultgraphics symmetry systematically (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahyangyi authored Jan 13, 2025
1 parent fcc63ed commit 09cd4db
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
38 changes: 21 additions & 17 deletions agrf/lib/building/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from PIL import Image
import functools
import numpy as np
from agrf.lib.building.symmetry import BuildingCylindrical, BuildingSymmetrical, BuildingRotational
from agrf.graphics import LayeredImage, SCALE_TO_ZOOM
from agrf.graphics.spritesheet import LazyAlternativeSprites
from agrf.magic import CachedFunctorMixin, TaggedCachedFunctorMixin
Expand All @@ -20,7 +21,9 @@ class DefaultGraphics:
for climate in ["temperate", "arctic", "tropical", "toyland"]
for k in [1011, 1012, 1037, 1038, 3981, 4550]
}
climate_independent_tiles = {k: load_third_party_image(f"third_party/opengfx2/{k}.png") for k in [1313, 1314, 1420]}
climate_independent_tiles = {
k: load_third_party_image(f"third_party/opengfx2/{k}.png") for k in [1313, 1314, 1320, 1321, 1420]
}

def graphics(self, scale, bpp, climate="temperate", subclimate="default"):
# FIXME handle flags correctly
Expand All @@ -47,20 +50,6 @@ def to_spriteref(self, sprite_list):
def to_action2_semidict(self, sprite_list):
return {"sprite": grf.SpriteRef(self.sprite_id, is_global=True)}

@property
def M(self):
if self.sprite_id in [1011, 1012, 1037, 1038, 1313, 1314]:
return replace(self, sprite_id=self.sprite_id - 1 if self.sprite_id % 2 == 0 else self.sprite_id + 1)
return self

@property
def R(self):
return self

@property
def T(self):
return self

@property
def sprites(self):
return ()
Expand All @@ -72,6 +61,21 @@ def get_resource_files(self):
return ()


DEFAULT_GRAPHICS = {}
for x in [1420, 3872, 3981, 4550]:
DEFAULT_GRAPHICS[x] = BuildingCylindrical.create_variants([DefaultGraphics(x)])
for x in [1011, 1037, 1313]:
DEFAULT_GRAPHICS[x] = BuildingSymmetrical.create_variants([DefaultGraphics(x), DefaultGraphics(x + 1)])
DEFAULT_GRAPHICS[x + 1] = DEFAULT_GRAPHICS[x].M
for x in [1320]:
DEFAULT_GRAPHICS[x + 1] = BuildingRotational.create_variants(
[DefaultGraphics(x + 1), DefaultGraphics(x), DefaultGraphics(x + 2), DefaultGraphics(x + 3)]
)
DEFAULT_GRAPHICS[x] = DEFAULT_GRAPHICS[x + 1].R
DEFAULT_GRAPHICS[x + 2] = DEFAULT_GRAPHICS[x + 1].T
DEFAULT_GRAPHICS[x + 3] = DEFAULT_GRAPHICS[x + 1].T.R


@dataclass
class NewGraphics(CachedFunctorMixin):
sprite: grf.ResourceAction
Expand Down Expand Up @@ -337,7 +341,7 @@ def get_resource_files(self):


def ADefaultGroundSprite(sprite, flags=None):
return NewGeneralSprite(sprite=DefaultGraphics(sprite), position=GroundPosition(), child_sprites=[], flags=flags)
return NewGeneralSprite(sprite=DEFAULT_GRAPHICS[sprite], position=GroundPosition(), child_sprites=[], flags=flags)


def AGroundSprite(sprite, flags=None):
Expand All @@ -346,7 +350,7 @@ def AGroundSprite(sprite, flags=None):

def ADefaultParentSprite(sprite, extent, offset, child_sprites=None, flags=None):
return NewGeneralSprite(
sprite=DefaultGraphics(sprite),
sprite=DEFAULT_GRAPHICS[sprite],
position=BBoxPosition(extent=extent, offset=offset),
child_sprites=child_sprites,
flags=flags,
Expand Down
1 change: 1 addition & 0 deletions agrf/lib/building/symmetry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class BuildingSymmetryMixin:
@classmethod
def create_variants(classobj, variants):
assert len(variants) == len(classobj.render_indices())
for i, v in enumerate(variants):
cls = v.__class__
v.__class__ = type(f"{cls.__name__}+{classobj.__name__}", (classobj, cls), {})
Expand Down
Binary file added agrf/third_party/opengfx2/1322.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added agrf/third_party/opengfx2/1323.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 09cd4db

Please sign in to comment.