Expand description
A handy crate for parsing the Tiled JSON data in to a usable structure.
The crate includes a few small helper functions on Map
, TileSet
, and
TileLayer
. These functions are for common tasks such as generating a
cloumn/row location (tiles are stored in a 1D array), a located box on an
image for helping with tile-to-tilesheet image picking, and loading files
(or strings).
§Examples
use tiled_json_rs as tiled;
let map = tiled::Map::load_from_file(&PathBuf::from("tests/data/csv.json"))
.expect("Failed to load map");
for tileset in &map.tile_sets {
let name = tileset.name.clone();
let mut path = PathBuf::from("assets");
path.push(tileset.image.clone());
// Do stuff
}
use tiled::Layer;
fn render_layers(layers: &Vec<Layer>) {
for layer in layers {
match &layer.layer_type {
tiled::LayerType::TileLayer(tiles) => {
//do_something(tiles);
}
tiled::LayerType::Group { layers } => {
&mut render_layers(layers);
}
tiled::LayerType::ImageLayer(image) => {
//do_something_else(image);
}
tiled::LayerType::ObjectGroup(objects) => {
//and_another_thing(objects);
}
}
}
}
render_layers(&map.layers);
§Info
Tiled can export maps as JSON files. To do so, simply select “File > Export As”
and select the JSON file type. You can export json from the command line with
the --export-map
option.
Notes:
- GID for tiles starts at 1 with 0 reserved for empty tile
- Local Id starts at 0 for
TileSet
, and only applies toTileSet
- Doc comments are only provided where clarification may be useful. In general things should be named well enough that intention is self-describing.
Structs§
- Chunks are used to store the tile layer data for infinite maps
- An RGBA representation of colours
- Data for an individual frame of animation
- Used to group layers if required
- Contains a file path to an image plus a mix colour
- A map can contain any number of layers.
- The base structure which contains all data - as in the root of a tree
- Contains all possible data for a tile including an optional
ObjectGroup
- Used to provide the location and dimensions of the required tile on the tiles tileset image.
- A tileset that associates information with each tile.
- A simple representation of a 2d Vector to pass coords around
- Data set for
Wang
tiles
Enums§
- Can be
TopDown
(default) orIndex
. Applies toObjectGroup
only. - Contains the data for this variant of layer
- Contains data for the object sub-types
- The orientation of the
Map
- Rendering direction. Applies only to orthogonal maps
- Applies only to staggered or hexagonal maps
- Applies only to staggered or hexagonal maps
- A
TiledValue
is similar to JSON values.