#tiled #tiled-json

tiled-json-rs

A crate to parse and interact with Tiled editor JSON files

8 releases

✓ Uses Rust 2018 edition

0.2.6 Jul 6, 2019
0.2.5 Jul 6, 2019
0.2.4 Jun 27, 2019
0.1.0 Jun 26, 2019

#326 in Data structures

Download history 10/week @ 2020-01-11 17/week @ 2020-01-18 2/week @ 2020-01-25 9/week @ 2020-02-08 24/week @ 2020-02-22 16/week @ 2020-02-29 17/week @ 2020-03-07 11/week @ 2020-03-14 26/week @ 2020-03-21 8/week @ 2020-03-28 17/week @ 2020-04-04 48/week @ 2020-04-11 2/week @ 2020-04-18 1/week @ 2020-04-25

59 downloads per month

MPL-2.0 license

35KB
740 lines

Parser for Tiled Editor JSON

Documentation

Usage

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);

Notes:

  • GID for tiles starts at 1 with 0 reserved for empty tile
  • Local Id starts at 0 for TileSet, and only applies to TileSet
  • The tileset must be included in the JSON (this is temporary until parsing the path is done)
  • Doc comments are only provided where clarification may be useful. In general things should be named well enough that intention is self-describing.

License

MPL v2

Dependencies

~1.1–1.7MB
~30K SLoC