mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-02-23 15:49:52 +01:00
fix: changes to support animated tile with collision shapes casting based on test files generated from Tiled as it seems the documentation was wrong about that.
This commit is contained in:
@@ -6,8 +6,8 @@ import attr
|
|||||||
from typing_extensions import TypedDict
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
from . import properties as properties_
|
from . import properties as properties_
|
||||||
|
from . import tiled_object
|
||||||
from .common_types import Color, OrderedPair
|
from .common_types import Color, OrderedPair
|
||||||
from .tiled_object import TiledObject
|
|
||||||
|
|
||||||
|
|
||||||
class Grid(NamedTuple):
|
class Grid(NamedTuple):
|
||||||
@@ -92,11 +92,12 @@ class Tile:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
id: int
|
id: int
|
||||||
|
opacity: int = 1
|
||||||
type: Optional[str] = None
|
type: Optional[str] = None
|
||||||
terrain: Optional[TileTerrain] = None
|
terrain: Optional[TileTerrain] = None
|
||||||
animation: Optional[List[Frame]] = None
|
animation: Optional[List[Frame]] = None
|
||||||
objectgroup: Optional[List[TiledObject]] = None
|
objects: Optional[List[tiled_object.TiledObject]] = None
|
||||||
image: Optional[str] = None
|
image: Optional[Path] = None
|
||||||
image_width: Optional[int] = None
|
image_width: Optional[int] = None
|
||||||
image_height: Optional[int] = None
|
image_height: Optional[int] = None
|
||||||
properties: Optional[properties_.Properties] = None
|
properties: Optional[properties_.Properties] = None
|
||||||
@@ -139,10 +140,6 @@ class TileSet:
|
|||||||
tile_width: int
|
tile_width: int
|
||||||
tile_height: int
|
tile_height: int
|
||||||
|
|
||||||
image: Path
|
|
||||||
image_width: int
|
|
||||||
image_height: int
|
|
||||||
|
|
||||||
tile_count: int
|
tile_count: int
|
||||||
columns: int
|
columns: int
|
||||||
|
|
||||||
@@ -152,6 +149,11 @@ class TileSet:
|
|||||||
spacing: int = 0
|
spacing: int = 0
|
||||||
margin: int = 0
|
margin: int = 0
|
||||||
|
|
||||||
|
image: Optional[Path] = None
|
||||||
|
image_width: Optional[int] = None
|
||||||
|
image_height: Optional[int] = None
|
||||||
|
|
||||||
|
type: Optional[str] = None
|
||||||
firstgid: Optional[int] = None
|
firstgid: Optional[int] = None
|
||||||
background_color: Optional[Color] = None
|
background_color: Optional[Color] = None
|
||||||
tile_offset: Optional[OrderedPair] = None
|
tile_offset: Optional[OrderedPair] = None
|
||||||
@@ -160,7 +162,6 @@ class TileSet:
|
|||||||
properties: Optional[properties_.Properties] = None
|
properties: Optional[properties_.Properties] = None
|
||||||
terrain_types: Optional[List[Terrain]] = None
|
terrain_types: Optional[List[Terrain]] = None
|
||||||
tiles: Optional[List[Tile]] = None
|
tiles: Optional[List[Tile]] = None
|
||||||
source_file: Optional[Path] = None
|
|
||||||
|
|
||||||
|
|
||||||
class RawFrame(TypedDict):
|
class RawFrame(TypedDict):
|
||||||
@@ -195,8 +196,9 @@ class RawTile(TypedDict):
|
|||||||
image: str
|
image: str
|
||||||
imageheight: int
|
imageheight: int
|
||||||
imagewidth: int
|
imagewidth: int
|
||||||
probability: float
|
opacity: float
|
||||||
properties: List[properties_.RawProperty]
|
properties: List[properties_.RawProperty]
|
||||||
|
objects: List[tiled_object.RawTiledObject]
|
||||||
terrain: List[int]
|
terrain: List[int]
|
||||||
type: str
|
type: str
|
||||||
|
|
||||||
@@ -300,11 +302,16 @@ def _cast_tile(raw_tile: RawTile) -> Tile:
|
|||||||
for frame in raw_tile["animation"]:
|
for frame in raw_tile["animation"]:
|
||||||
tile.animation.append(_cast_frame(frame))
|
tile.animation.append(_cast_frame(frame))
|
||||||
|
|
||||||
|
if raw_tile.get("objects") is not None:
|
||||||
|
tile.objects = []
|
||||||
|
for object_ in raw_tile["objects"]:
|
||||||
|
tile.objects.append(tiled_object.cast(object_))
|
||||||
|
|
||||||
if raw_tile.get("properties") is not None:
|
if raw_tile.get("properties") is not None:
|
||||||
tile.properties = properties_.cast(raw_tile["properties"])
|
tile.properties = properties_.cast(raw_tile["properties"])
|
||||||
|
|
||||||
if raw_tile.get("image") is not None:
|
if raw_tile.get("image") is not None:
|
||||||
tile.image = raw_tile["image"]
|
tile.image = Path(raw_tile["image"])
|
||||||
|
|
||||||
if raw_tile.get("imagewidth") is not None:
|
if raw_tile.get("imagewidth") is not None:
|
||||||
tile.image_width = raw_tile["imagewidth"]
|
tile.image_width = raw_tile["imagewidth"]
|
||||||
@@ -365,11 +372,17 @@ def cast(raw_tileset: RawTileSet) -> TileSet:
|
|||||||
margin=raw_tileset["margin"],
|
margin=raw_tileset["margin"],
|
||||||
version=raw_tileset["version"],
|
version=raw_tileset["version"],
|
||||||
tiled_version=raw_tileset["tiledversion"],
|
tiled_version=raw_tileset["tiledversion"],
|
||||||
image=Path(raw_tileset["image"]),
|
|
||||||
image_width=raw_tileset["imagewidth"],
|
|
||||||
image_height=raw_tileset["imageheight"],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if raw_tileset.get("image") is not None:
|
||||||
|
tileset.image = Path(raw_tileset["image"])
|
||||||
|
|
||||||
|
if raw_tileset.get("imagewidth") is not None:
|
||||||
|
tileset.image_width = raw_tileset["imagewidth"]
|
||||||
|
|
||||||
|
if raw_tileset.get("imageheight") is not None:
|
||||||
|
tileset.image_height = raw_tileset["imageheight"]
|
||||||
|
|
||||||
if raw_tileset.get("firstgid") is not None:
|
if raw_tileset.get("firstgid") is not None:
|
||||||
tileset.firstgid = raw_tileset["firstgid"]
|
tileset.firstgid = raw_tileset["firstgid"]
|
||||||
|
|
||||||
@@ -382,6 +395,9 @@ def cast(raw_tileset: RawTileSet) -> TileSet:
|
|||||||
if raw_tileset.get("transparentcolor") is not None:
|
if raw_tileset.get("transparentcolor") is not None:
|
||||||
tileset.transparent_color = raw_tileset["transparentcolor"]
|
tileset.transparent_color = raw_tileset["transparentcolor"]
|
||||||
|
|
||||||
|
if raw_tileset.get("type") is not None:
|
||||||
|
tileset.type = raw_tileset["type"]
|
||||||
|
|
||||||
if raw_tileset.get("grid") is not None:
|
if raw_tileset.get("grid") is not None:
|
||||||
tileset.grid = _cast_grid(raw_tileset["grid"])
|
tileset.grid = _cast_grid(raw_tileset["grid"])
|
||||||
|
|
||||||
@@ -400,7 +416,4 @@ def cast(raw_tileset: RawTileSet) -> TileSet:
|
|||||||
tiles.append(_cast_tile(raw_tile))
|
tiles.append(_cast_tile(raw_tile))
|
||||||
tileset.tiles = tiles
|
tileset.tiles = tiles
|
||||||
|
|
||||||
if raw_tileset.get("source") is not None:
|
|
||||||
tileset.source_file = Path(raw_tileset["source"])
|
|
||||||
|
|
||||||
return tileset
|
return tileset
|
||||||
|
|||||||
Reference in New Issue
Block a user