diff --git a/agrf/lib/building/layout_test.py b/agrf/lib/building/layout_test.py index d02ef287..91b09b09 100644 --- a/agrf/lib/building/layout_test.py +++ b/agrf/lib/building/layout_test.py @@ -1,4 +1,5 @@ from agrf.lib.building.layout import ADefaultGroundSprite, ALayout +from agrf.lib.building.symmetry import BuildingSymmetrical def test_default_groundsprite(): @@ -12,6 +13,14 @@ def test_default_groundsprite(): assert m_graphics.shape == (127, 256, 4) assert m_graphics[64, 128, 1] == 72 + r_graphics = gs1012.R.graphics(4, 32).to_image() + assert r_graphics.shape == (127, 256, 4) + assert r_graphics[64, 128, 1] == 67 + + t_graphics = gs1012.T.graphics(4, 32).to_image() + assert t_graphics.shape == (127, 256, 4) + assert t_graphics[64, 128, 1] == 67 + def test_layout(): gs1012 = ADefaultGroundSprite(1012) @@ -24,3 +33,21 @@ def test_layout(): m_graphics = l.M.graphics(4, 32).to_image() assert m_graphics.shape == (127, 256, 4) assert m_graphics[64, 128, 1] == 72 + + r_graphics = l.R.graphics(4, 32).to_image() + assert r_graphics.shape == (127, 256, 4) + assert r_graphics[64, 128, 1] == 67 + + t_graphics = l.T.graphics(4, 32).to_image() + assert t_graphics.shape == (127, 256, 4) + assert t_graphics[64, 128, 1] == 67 + + +def test_symmetry(): + gs1012 = ADefaultGroundSprite(1012) + gs1011 = ADefaultGroundSprite(1011) + + g = BuildingSymmetrical.create_variants([gs1012, gs1011]) + assert g is g.R + assert g is g.T + assert g is g.M.M diff --git a/agrf/lib/building/symmetry.py b/agrf/lib/building/symmetry.py index e6088db1..f6d15457 100644 --- a/agrf/lib/building/symmetry.py +++ b/agrf/lib/building/symmetry.py @@ -3,19 +3,31 @@ class BuildingSymmetryMixin: def create_variants(classobj, variants): for i, v in enumerate(variants): cls = v.__class__ - v.__class__ = type(cls.__name__, (cls, classobj), {}) + v.__class__ = type(cls.__name__, (classobj, cls), {}) idx = classobj.render_indices()[i] - v.M = variants[classobj._symmetry_descriptor[idx ^ 1]] + v._M = variants[classobj._symmetry_descriptor[idx ^ 1]] if idx % 2 == 0: - v.R = variants[classobj._symmetry_descriptor[idx ^ 2]] - v.T = variants[classobj._symmetry_descriptor[idx ^ 4]] + v._R = variants[classobj._symmetry_descriptor[idx ^ 2]] + v._T = variants[classobj._symmetry_descriptor[idx ^ 4]] else: - v.R = variants[classobj._symmetry_descriptor[idx ^ 4]] - v.T = variants[classobj._symmetry_descriptor[idx ^ 2]] + v._R = variants[classobj._symmetry_descriptor[idx ^ 4]] + v._T = variants[classobj._symmetry_descriptor[idx ^ 2]] v.symmetry = classobj return variants[0] + @property + def M(self): + return self._M + + @property + def R(self): + return self._R + + @property + def T(self): + return self._T + @classmethod def get_all_variants(cls, thing): return [cls.symmetry_index(thing, i) for i in cls.render_indices()] @@ -189,72 +201,42 @@ def compose_symmetry_indices(a, b): class BuildingFull(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 2, 3, 4, 5, 6, 7) class BuildingSymmetricalX(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 0, 1, 2, 3, 2, 3) class BuildingSymmetricalY(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 2, 3, 0, 1, 2, 3) class BuildingSymmetrical(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 0, 1, 0, 1, 0, 1) class BuildingRotational(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 2, 3, 2, 3, 0, 1) class BuildingRotational4(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 1, 0, 1, 0, 0, 1) class BuildingDiagonal(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 0, 1, 2, 2, 1, 3, 3) class BuildingDiagonalAlt(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 1, 2, 2, 3, 3, 1, 0) class BuildingDiamond(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 0, 1, 1, 1, 1, 0, 0) class BuildingCylindrical(BuildingSymmetryMixin): - def __init__(self, obj): - super().__init__(obj) - _symmetry_descriptor = (0, 0, 0, 0, 0, 0, 0, 0)