Skip to main content

macroquad_tiled/tiled/
layer.rs

1use nanoserde::DeJson;
2
3use std::collections::HashMap;
4
5/// https://doc.mapeditor.org/en/stable/reference/json-map-format/#json-chunk
6#[derive(Clone, Debug, Default, DeJson)]
7#[nserde(default)]
8pub struct Chunk {
9    /// Array of unsigned int (GIDs) or base64-encoded data
10    pub data: Vec<u32>,
11    /// Height in tiles
12    pub height: usize,
13    /// Width in tiles
14    pub width: usize,
15    /// X coordinate in tiles
16    pub x: i32,
17    /// Y coordinate in tiles
18    pub y: i32,
19}
20
21#[derive(Clone, Debug, Default, DeJson)]
22#[nserde(default)]
23pub struct Layer {
24    /// Array of chunks (optional). tilelayer only.
25    pub chunks: Option<Vec<Chunk>>,
26    pub name: String,
27    pub opacity: f32,
28    pub properties: Option<HashMap<String, String>>,
29    pub visible: bool,
30    pub width: u32,
31    pub height: u32,
32    #[nserde(rename = "type")]
33    pub ty: String,
34
35    /// for type = "tilelayer"
36    pub data: Vec<u32>,
37
38    /// for type = "objectlayer"
39    pub draworder: Option<String>,
40    #[nserde(default)]
41    pub objects: Vec<Object>,
42    /// Horizontal layer offset in pixels (default: 0)
43    pub offsetx: Option<i32>,
44    /// Vertical layer offset in pixels (default: 0)
45    pub offsety: Option<i32>,
46    /// Horizontal layer offset in tiles. Always 0.
47    pub x: Option<f32>,
48    /// Vertical layer offset in tiles. Always 0.
49    pub y: Option<f32>,
50
51    /// for type = "imagelayer"
52    pub image: Option<String>,
53}
54
55#[derive(Clone, Debug, Default, DeJson)]
56#[nserde(default)]
57pub struct Property {
58    pub name: String,
59    #[nserde(rename = "type")]
60    pub ty: String,
61    pub value: String,
62}
63
64#[derive(Clone, Debug, Default, DeJson)]
65#[nserde(default)]
66pub struct Object {
67    pub id: u32,
68    pub name: String,
69
70    #[nserde(rename = "type")]
71    pub ty: String,
72    pub gid: Option<u32>,
73    pub ellipse: Option<bool>,
74    pub polygon: Option<Vec<PolyPoint>>,
75
76    pub properties: Vec<Property>,
77    pub rotation: f32,
78    pub visible: bool,
79
80    pub height: f32,
81    pub width: f32,
82
83    pub x: f32,
84    pub y: f32,
85}
86
87#[derive(Copy, Clone, Debug, DeJson)]
88pub struct PolyPoint {
89    pub x: f32,
90    pub y: f32,
91}