tmx/
lib.rs

1#![doc = include_str!("../readme.md")]
2#![deny(missing_docs)]
3
4use std::collections::HashMap;
5use std::sync::Arc;
6
7use glam::Vec2;
8
9pub use layer::Layer;
10pub use map::Map;
11pub use property::Property;
12pub use texture::Texture;
13pub use tile_type::TileType;
14
15mod layer;
16mod loader;
17mod map;
18mod parse;
19mod property;
20mod texture;
21mod tile_type;
22
23pub use loader::load_from_file;
24
25/// Render order for tiles in layers.
26#[derive(Debug, Clone, Copy)]
27#[allow(missing_docs)]
28pub enum RenderOrder {
29    RightDown,
30    RightUp,
31    LeftDown,
32    LeftUp,
33}
34
35/// A tileset
36pub struct Tileset {
37    /// The global tile id of the first tile in this tileset.
38    pub first_gid: u32,
39    /// The source file of this tileset, or it's name if it's an embedded tileset.
40    pub source: String,
41    /// The tiles contained in this tileset.
42    pub tiles: Vec<Option<Tile>>,
43    /// The image that the tiles are taken from, or `None` if all tiles provide their own image.
44    pub image: Option<Texture>,
45    /// The size in pixels of tiles in this tileset
46    pub tile_size: Vec2,
47}
48
49/// A single tile description
50pub struct Tile {
51    /// The image that this tile was taken from
52    pub image: Option<Texture>,
53    /// The top left UV coordinates of this tile within `image.
54    pub top_left: Vec2,
55    /// The bottom right UV coordinates of this tile within `image.
56    pub bottom_right: Vec2,
57    /// The width in pixels of this tile.
58    pub width: i32,
59    /// The height in pixels of this tile.
60    pub height: i32,
61    #[allow(missing_docs)]
62    pub animation: Vec<Frame>,
63    /// Custom properties defined on this tile.
64    pub properties: HashMap<String, Property>,
65    /// ObjectGroup attached to this tile
66    pub object_group: Vec<Object>,
67}
68
69/// Animation frame within a tile
70pub struct Frame {
71    /// Global tile id of the animation frame.
72    pub tile: u32,
73    /// Duration in ms
74    pub duration: u32,
75}
76
77/// Object description
78#[derive(Clone, Debug)]
79pub struct Object {
80    /// Unique id for the object.
81    pub id: u32,
82    /// Custom properties defined on the object.
83    pub properties: HashMap<String, Property>,
84    /// Global tile id defining an optional sprite for this object.
85    pub tile: Option<u32>,
86    /// The shape of this object.
87    pub shape: Shape,
88    /// Custom name for the object
89    pub name: String,
90    /// Custom type for the object
91    pub ty: String,
92    /// left X coordinate in pixels where the object is positioned.
93    pub x: f32,
94    /// bottom Y coordinate in pixels where the object is positioned.
95    pub y: f32,
96    /// Width in pixels of the object.
97    pub width: f32,
98    /// Height in pixels of the object.
99    pub height: f32,
100    /// Rotation around (x,y) in degrees of the object.
101    pub rotation: f32,
102    /// Whether the object is visible. Invisible objects have their `Draw` component set to invisible.
103    pub visible: bool,
104}
105
106/// A shape.
107#[derive(Clone, Debug)]
108pub struct Shape {
109    /// Point defining the shape.
110    pub points: Vec<Vec2>,
111    /// Whether the last point should be connected to the first point.
112    pub closed: bool,
113}