@@ -46,6 +46,27 @@ class Frame(NamedTuple):
4646 duration : int
4747
4848
49+ @attr .s (auto_attribs = True , kw_only = True )
50+ class Transformations :
51+ """Transformations Object.
52+
53+ This is used to store what transformations may be performed on Tiles
54+ within a tileset. (This is primarily used with wang sets, however could
55+ be used for any means a game wants really.)
56+
57+ Args:
58+ hflip: Allow horizontal flip?
59+ vflip: Allow vertical flip?
60+ rotate: Allow rotation?
61+ prefer_untransformed: Should untransformed tiles be preferred?
62+ """
63+
64+ hflip : Optional [bool ] = None
65+ vflip : Optional [bool ] = None
66+ rotate : Optional [bool ] = None
67+ prefer_untransformed : Optional [bool ] = None
68+
69+
4970@attr .s (auto_attribs = True , kw_only = True )
5071class Tile :
5172 # FIXME: args
@@ -121,6 +142,8 @@ class Tileset:
121142 image_width : Optional [int ] = None
122143 image_height : Optional [int ] = None
123144
145+ transformations : Optional [Transformations ] = None
146+
124147 firstgid : Optional [int ] = None
125148 background_color : Optional [Color ] = None
126149 tile_offset : Optional [OrderedPair ] = None
@@ -145,6 +168,15 @@ class RawTileOffset(TypedDict):
145168 y : int
146169
147170
171+ class RawTransformations (TypedDict ):
172+ """ The keys and their types that appear in a Transformations JSON Object."""
173+
174+ hflip : bool
175+ vflip : bool
176+ rotate : bool
177+ preferuntransformed : bool
178+
179+
148180class RawTile (TypedDict ):
149181 """ The keys and their types that appear in a Tile JSON Object."""
150182
@@ -189,7 +221,7 @@ class RawTileSet(TypedDict):
189221 tiles : List [RawTile ]
190222 tilewidth : int
191223 transparentcolor : str
192- type : str
224+ transformations : RawTransformations
193225 version : Union [str , float ]
194226 wangsets : List [RawWangSet ]
195227
@@ -262,6 +294,24 @@ def _cast_tile(raw_tile: RawTile, external_path: Optional[Path] = None) -> Tile:
262294 return tile
263295
264296
297+ def _cast_transformations (raw_transformations : RawTransformations ) -> Transformations :
298+ """Cast the raw_transformations to a Transformations object.
299+
300+ Args:
301+ raw_transformations: RawTransformations to be casted to a Transformations
302+
303+ Returns:
304+ Transformations: The Transformations created from the raw_transformations
305+ """
306+
307+ return Transformations (
308+ hflip = raw_transformations ["hflip" ],
309+ vflip = raw_transformations ["vflip" ],
310+ rotate = raw_transformations ["rotate" ],
311+ prefer_untransformed = raw_transformations ["preferuntransformed" ],
312+ )
313+
314+
265315def _cast_grid (raw_grid : RawGrid ) -> Grid :
266316 """Cast the raw_grid to a Grid object.
267317
@@ -356,4 +406,7 @@ def cast(raw_tileset: RawTileSet, external_path: Optional[Path] = None) -> Tiles
356406 wangsets .append (cast_wangset (raw_wangset ))
357407 tileset .wang_sets = wangsets
358408
409+ if raw_tileset .get ("transformations" ) is not None :
410+ tileset .transformations = _cast_transformations (raw_tileset ["transformations" ])
411+
359412 return tileset
0 commit comments