#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

#272 in Data structures

Download history 2/week @ 2019-07-24 29/week @ 2019-07-31 43/week @ 2019-08-07 29/week @ 2019-08-21 28/week @ 2019-08-28 34/week @ 2019-09-04 11/week @ 2019-09-11 128/week @ 2019-09-18 9/week @ 2019-09-25 25/week @ 2019-10-02 2/week @ 2019-10-09 18/week @ 2019-10-16 9/week @ 2019-10-23 16/week @ 2019-10-30

71 downloads per month

MPL-2.0 license

35KB
740 lines

Build Status

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.2–1.8MB
~39K SLoC