1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
use crate::{
layer::ObjectGroup,
parsers::{parse_color, parse_path, parse_property},
wangs::WangSet,
Color, TiledValue, Vec2,
};
use serde::Deserialize;
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Deserialize, Debug, PartialEq, Clone)]
pub struct TileSet {
pub columns: u32,
#[serde(rename(deserialize = "firstgid"))]
pub first_gid: u32,
#[serde(deserialize_with = "parse_path")]
pub image: PathBuf,
#[serde(rename(deserialize = "imagewidth"))]
pub image_width: u32,
#[serde(rename(deserialize = "imageheight"))]
pub image_height: u32,
pub margin: u32,
pub spacing: u32,
pub name: String,
#[serde(deserialize_with = "parse_property", default)]
pub properties: HashMap<String, TiledValue>,
pub terrains: Option<Vec<Terrain>>,
#[serde(rename(deserialize = "tilecount"))]
pub tile_count: u32,
#[serde(rename(deserialize = "tileheight"))]
pub tile_height: u32,
#[serde(rename(deserialize = "tilewidth"))]
pub tile_width: u32,
#[serde(rename(deserialize = "tileoffset"))]
pub tile_offset: Option<Vec2<i32>>,
pub tiles: Option<Vec<Tile>>,
#[serde(
rename(deserialize = "transparentcolor"),
deserialize_with = "parse_color",
default
)]
pub transparent_color: Color,
#[serde(rename(deserialize = "wangsets"))]
pub wang_sets: Option<Vec<WangSet>>,
}
#[derive(Deserialize, Debug, PartialEq, Clone)]
pub struct Tile {
pub animation: Option<Vec<Frame>>,
pub id: u32,
pub image: Option<String>,
#[serde(rename(deserialize = "imagewidth"), default)]
pub image_width: u32,
#[serde(rename(deserialize = "imageheight"), default)]
pub image_height: u32,
#[serde(rename(deserialize = "objectgroup"))]
pub object_group: Option<ObjectGroup>,
#[serde(deserialize_with = "parse_property", default)]
pub properties: HashMap<String, TiledValue>,
pub terrain: Option<[i8; 4]>,
#[serde(rename(deserialize = "type"))]
pub tile_type: Option<String>,
}
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Frame {
pub duration: u32,
#[serde(rename(deserialize = "tileid"))]
pub tile_id: u32,
}
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
#[serde(rename_all(deserialize = "lowercase"))]
pub enum Orientation {
Orthogonal,
Isometric,
}
#[derive(Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Terrain {
pub name: String,
pub tile: u32,
}