Skip to content

Commit 54ad832

Browse files
committed
Tiled 1.9 Compatibility Update
1 parent ddf314e commit 54ad832

File tree

107 files changed

+564
-440
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+564
-440
lines changed

pytiled_parser/layer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Layer:
4343
size: Ordered pair of size of map in tiles.
4444
properties: Properties for the layer.
4545
tint_color: Tint color that is multiplied with any graphics in this layer.
46+
class_: The Tiled class of this Layer.
4647
"""
4748

4849
name: str
@@ -54,6 +55,7 @@ class Layer:
5455
offset: OrderedPair = OrderedPair(0, 0)
5556

5657
id: Optional[int] = None
58+
class_: Optional[str] = None
5759
size: Optional[Size] = None
5860
properties: Optional[Properties] = None
5961
tint_color: Optional[Color] = None

pytiled_parser/parsers/json/layer.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -40,51 +40,55 @@
4040
zstd = None
4141

4242

43-
class RawChunk(TypedDict):
44-
"""The keys and their types that appear in a Tiled JSON Chunk Object.
43+
RawChunk = TypedDict("RawChunk", {
44+
"data": Union[List[int], str],
45+
"height": int,
46+
"width": int,
47+
"x": int,
48+
"y": int
49+
})
50+
RawChunk.__doc__ = """
51+
The keys and their types that appear in a Tiled JSON Chunk Object.
4552
4653
Tiled Doc: https://doc.mapeditor.org/en/stable/reference/json-map-format/#chunk
47-
"""
54+
"""
4855

49-
data: Union[List[int], str]
50-
height: int
51-
width: int
52-
x: int
53-
y: int
5456

5557

56-
class RawLayer(TypedDict):
57-
"""The keys and their types that appear in a Tiled JSON Layer Object.
58+
RawLayer = TypedDict("RawLayer", {
59+
"chunks": List[RawChunk],
60+
"compression": str,
61+
"data": Union[List[int], str],
62+
"draworder": str,
63+
"encoding": str,
64+
"height": int,
65+
"id": int,
66+
"image": str,
67+
"layers": List[Any],
68+
"name": str,
69+
"objects": List[RawObject],
70+
"offsetx": float,
71+
"offsety": float,
72+
"parallaxx": float,
73+
"parallaxy": float,
74+
"opacity": float,
75+
"properties": List[RawProperty],
76+
"startx": int,
77+
"starty": int,
78+
"tintcolor": str,
79+
"transparentcolor": str,
80+
"class": str,
81+
"type": str,
82+
"visible": bool,
83+
"width": int,
84+
"x": int,
85+
"y": int
86+
})
87+
RawLayer.__doc__ = """
88+
The keys and their types that appear in a Tiled JSON Layer Object.
5889
5990
Tiled Doc: https://doc.mapeditor.org/en/stable/reference/json-map-format/#layer
60-
"""
61-
62-
chunks: List[RawChunk]
63-
compression: str
64-
data: Union[List[int], str]
65-
draworder: str
66-
encoding: str
67-
height: int
68-
id: int
69-
image: str
70-
layers: List[Any]
71-
name: str
72-
objects: List[RawObject]
73-
offsetx: float
74-
offsety: float
75-
parallaxx: float
76-
parallaxy: float
77-
opacity: float
78-
properties: List[RawProperty]
79-
startx: int
80-
starty: int
81-
tintcolor: str
82-
transparentcolor: str
83-
type: str
84-
visible: bool
85-
width: int
86-
x: int
87-
y: int
91+
"""
8892

8993

9094
def _convert_raw_tile_layer_data(data: List[int], layer_width: int) -> List[List[int]]:
@@ -229,6 +233,9 @@ def _parse_common(raw_layer: RawLayer) -> Layer:
229233
if raw_layer.get("properties") is not None:
230234
common.properties = parse_properties(raw_layer["properties"])
231235

236+
if raw_layer.get("class") is not None:
237+
common.class_ = raw_layer["class"]
238+
232239
parallax = [1.0, 1.0]
233240

234241
if raw_layer.get("parallaxx") is not None:

pytiled_parser/parsers/json/tiled_map.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,40 @@
1717
from pytiled_parser.tiled_map import TiledMap, TilesetDict
1818
from pytiled_parser.util import check_format, parse_color
1919

20-
21-
class RawTilesetMapping(TypedDict):
22-
23-
firstgid: int
24-
source: str
25-
26-
27-
class RawTiledMap(TypedDict):
28-
"""The keys and their types that appear in a Tiled JSON Map Object.
20+
RawTilesetMapping = TypedDict("RawTilesetMapping", {
21+
"firstgid": int,
22+
"source": str
23+
})
24+
25+
26+
RawTiledMap = TypedDict("RawTiledMap", {
27+
"backgroundcolor": str,
28+
"compressionlevel": int,
29+
"height": int,
30+
"hexsidelength": int,
31+
"infinite": bool,
32+
"layers": List[RawLayer],
33+
"nextlayerid": int,
34+
"nextobjectid": int,
35+
"orientation": str,
36+
"properties": List[RawProperty],
37+
"renderorder": str,
38+
"staggeraxis": str,
39+
"staggerindex": str,
40+
"tiledversion": str,
41+
"tileheight": int,
42+
"tilesets": List[RawTilesetMapping],
43+
"tilewidth": int,
44+
"class": str,
45+
"type": str,
46+
"version": Union[str, float],
47+
"width": int
48+
})
49+
RawTiledMap.__doc__ = """
50+
The keys and their types that appear in a Tiled JSON Map Object.
2951
3052
Tiled Docs: https://doc.mapeditor.org/en/stable/reference/json-map-format/#map
31-
"""
32-
33-
backgroundcolor: str
34-
compressionlevel: int
35-
height: int
36-
hexsidelength: int
37-
infinite: bool
38-
layers: List[RawLayer]
39-
nextlayerid: int
40-
nextobjectid: int
41-
orientation: str
42-
properties: List[RawProperty]
43-
renderorder: str
44-
staggeraxis: str
45-
staggerindex: str
46-
tiledversion: str
47-
tileheight: int
48-
tilesets: List[RawTilesetMapping]
49-
tilewidth: int
50-
type: str
51-
version: Union[str, float]
52-
width: int
53+
"""
5354

5455

5556
def parse(file: Path) -> TiledMap:
@@ -152,6 +153,9 @@ def parse(file: Path) -> TiledMap:
152153
tiled_object.new_tileset = None
153154
tiled_object.new_tileset_path = None
154155

156+
if raw_tiled_map.get("class") is not None:
157+
map_.class_ = raw_tiled_map["class"]
158+
155159
if raw_tiled_map.get("backgroundcolor") is not None:
156160
map_.background_color = parse_color(raw_tiled_map["backgroundcolor"])
157161

pytiled_parser/parsers/json/tiled_object.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,52 @@
2222
)
2323
from pytiled_parser.util import load_object_template, parse_color
2424

25-
26-
class RawText(TypedDict):
27-
"""The keys and their types that appear in a Tiled JSON Text Object.
25+
RawText = TypedDict("RawText", {
26+
"text": str,
27+
"color": str,
28+
"fontfamily": str,
29+
"pixelsize": float, # this is `font_size` in Text
30+
"bold": bool,
31+
"italic": bool,
32+
"strikeout": bool,
33+
"underline": bool,
34+
"kerning": bool,
35+
"halign": str,
36+
"valign": str,
37+
"wrap": bool
38+
})
39+
RawText.__doc__ = """
40+
The keys and their types that appear in a Tiled JSON Text Object.
2841
2942
Tiled Doc: https://doc.mapeditor.org/en/stable/reference/json-map-format/#text-example
30-
"""
31-
32-
text: str
33-
color: str
34-
35-
fontfamily: str
36-
pixelsize: float # this is `font_size` in Text
37-
38-
bold: bool
39-
italic: bool
40-
strikeout: bool
41-
underline: bool
42-
kerning: bool
43-
44-
halign: str
45-
valign: str
46-
wrap: bool
43+
"""
4744

4845

49-
class RawObject(TypedDict):
50-
"""The keys and their types that appear in a Tiled JSON Object.
46+
RawObject = TypedDict("RawObject", {
47+
"id": int,
48+
"gid": int,
49+
"template": str,
50+
"x": float,
51+
"y": float,
52+
"width": float,
53+
"height": float,
54+
"rotation": float,
55+
"visible": bool,
56+
"name": str,
57+
"class": str,
58+
"type": str,
59+
"properties": List[RawProperty],
60+
"ellipse": bool,
61+
"point": bool,
62+
"polygon": List[Dict[str, float]],
63+
"polyline": List[Dict[str, float]],
64+
"text": RawText
65+
})
66+
RawObject.__doc__ = """
67+
The keys and their types that appear in a Tiled JSON Object.
5168
5269
Tiled Doc: https://doc.mapeditor.org/en/stable/reference/json-map-format/#object
53-
"""
54-
55-
id: int
56-
gid: int
57-
template: str
58-
x: float
59-
y: float
60-
width: float
61-
height: float
62-
rotation: float
63-
visible: bool
64-
name: str
65-
type: str
66-
properties: List[RawProperty]
67-
ellipse: bool
68-
point: bool
69-
polygon: List[Dict[str, float]]
70-
polyline: List[Dict[str, float]]
71-
text: RawText
70+
"""
7271

7372

7473
def _parse_common(raw_object: RawObject) -> TiledObject:
@@ -88,9 +87,14 @@ def _parse_common(raw_object: RawObject) -> TiledObject:
8887
size=Size(raw_object["width"], raw_object["height"]),
8988
rotation=raw_object["rotation"],
9089
name=raw_object["name"],
91-
type=raw_object["type"],
9290
)
9391

92+
if raw_object.get("type") is not None:
93+
common.class_ = raw_object["type"]
94+
95+
if raw_object.get("class") is not None:
96+
common.class_ = raw_object["class"]
97+
9498
if raw_object.get("properties") is not None:
9599
common.properties = parse_properties(raw_object["properties"])
96100

0 commit comments

Comments
 (0)