tmx

Crates.iotmx
lib.rstmx
version0.3.1
sourcesrc
created_at2020-04-29 20:44:17.089841
updated_at2020-05-28 17:51:00.56634
descriptionTMX is a library for loading [Tiled](https://mapeditor.org) maps in Rust
homepage
repositoryhttps://github.com/adtennant/rust-tmx.git
max_upload_size
id235540
size71,918
Alex Tennant (adtennant)

documentation

README

TMX

Build Status Crates.io Docs License

TMX is a library for loading Tiled (XML and JSON) maps in Rust.

Usage

cargo add tmx

Examples

Loading a Map

use tmx::Map;

fn main() -> Result<(), Box<dyn Error>> {
    let map = r##"
    <?xml version="1.0" encoding="UTF-8"?>
    <map version="1.2" tiledversion="1.3.3" orientation="isometric" renderorder="right-down" width="4" height="4" tilewidth="16" tileheight="16" infinite="0" nextlayerid="2" nextobjectid="1">
     <tileset firstgid="1" name="test" tilewidth="16" tileheight="16" tilecount="256" columns="16">
      <image source="tiles16.png" width="256" height="256"/>
     </tileset>
     <layer id="1" name="Tile Layer 1" width="4" height="4">
      <data encoding="csv">
    1,2684354561,1,2147483649,
    1610612737,3221225473,1073741825,3221225473,
    2147483649,3758096385,1073741825,536870913,
    536870913,1073741825,3758096385,2147483649
    </data>
     </layer>
    </map>
    "##;

    let map = Map::from_xml(map)?;
    println!("{:?}", map);

    Ok(())
}

Loading a Tileset

use tmx::Tileset;

fn main() -> Result<(), Box<dyn Error>> {
    let tileset = r##"
    <?xml version="1.0" encoding="UTF-8" ?>
<tileset version="1.2" tiledversion="1.3.3" name="tiles16" tilewidth="16" tileheight="16" tilecount="256" columns="16">
    <image source="tiles16.png" width="256" height="256" />
    <tile id="0" type="Solid" />
    <tile id="1" type="Solid" />
    <tile id="2" type="Solid" />
    <tile id="3" type="OneWay" />
</tileset>
    "##;

    let tileset = Tileset::from_xml(tileset)?;
    println!("{:?}", tileset);

    Ok(())
}

See the docs for more information.

TMX Map Format Support

Element Support
<map> ✅ Full
<editorsettings> 🛑 None
- <chunksize> 🛑 None
- <export> 🛑 None
<tileset> ⚠️ Partial
- <tileoffset> 🛑 None
- <grid> 🛑 None
- <image> ✅ Full
- <terraintypes> 🛑 None
- - <terrain> 🛑 None
- <tile> ✅ Full
- - <animation> ✅ Full
- <wangsets> 🛑 None
- - <wangset> 🛑 None
<layer> ✅ Full
- <data> ✅ Full
- <chunk> ✅ Full
- <tile> ✅ Full
<objectgroup> 🛑 None
- <object> 🛑 None
- <ellipse> 🛑 None
- <point> 🛑 None
- <polygon> 🛑 None
- <polyline> 🛑 None
- <text> 🛑 None
<imagelayer> 🛑 None
<group> 🛑 None
<properties> 🛑 None
- <property> 🛑 None

Features

The following features are available and enabled by default.

Feature Description
xml Allows loading XML maps.
base64-data Allows loading maps where the Tile Layer Format is Base64 (uncompressed).
gzip-data Allows loading maps where the Tile Layer Format is Base64 (gzip compressed).
zlib-data Allows loading maps where the Tile Layer Format is Base64 (zlib compressed).
zstd-data Allows loading maps where the Tile Layer Format is Base64 (Zstandard compressed).

License

MIT

Commit count: 15

cargo fmt