Crates.io | tiled-json-rs |
lib.rs | tiled-json-rs |
version | 0.2.6 |
source | src |
created_at | 2019-06-26 09:51:09.398794 |
updated_at | 2019-07-06 10:35:43.91695 |
description | A crate to parse and interact with Tiled editor JSON files |
homepage | https://gitlab.com/ljcode/tiled-json-rs |
repository | https://gitlab.com/ljcode/tiled-json-rs |
max_upload_size | |
id | 143697 |
size | 52,512 |
Cargo.toml
[dependencies]
tiled-json-rs = "0.1.0"
Load from a file
let map = tiled::Map::load_from_file(PathBuf::from("assets/test.json"))
.expect("Failed to load map");
Iterating over a tileset
for tileset in &map.tile_sets {
let name = tileset.name.clone();
let mut path = PathBuf::from("assets");
path.push(tileset.image.clone());
// Do stuff
}
Iterating over layers
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);
TileSet
, and only applies to TileSet
MPL v2