tego

Crates.iotego
lib.rstego
version0.5.0
sourcesrc
created_at2021-10-06 18:42:52.353967
updated_at2021-11-27 17:21:03.182856
descriptionCrate for loading Tiled maps
homepage
repositoryhttps://github.com/texel-sensei/tego
max_upload_size
id461306
size79,020
(texel-sensei)

documentation

README

tego

Documentation Crates.io License

tego is a library for parsing and loading Tiled maps.

Goals

The main goal of tego is to provide a foundation for loading tmx maps, independent of game engine or storage medium. It should not matter if the map is stored as a file on disk, or loaded on the fly from an asset bundle.

Furthermore common operations should be made easy with sane defaults, but not at the expense of flexibility.

Example

Load a map and pretty print the layers included in it:

use std::path::Path;
extern crate tego;

fn main() -> tego::Result<()> {
    // Load a tmx file.
    // Map::from_file() is the easiest, but least flexible method for loading a map.
    // Images referenced by the map are not loaded, instead only the path is returned as string.
    let map = tego::Map::from_file(Path::new("example-maps/default/groups.tmx"))?;

    // Keep track how much we need to indent for some nice pretty printing
    let mut indent = 0;

    for (layer, groups_left) in map.iter_layers() {
        // Reduce indentation by the amount of groups left
        indent -= groups_left;

        // print indentation to highlight hierarchy
        print!("{}", "  ".repeat(indent));

        use tego::Layer::*;
        match layer {
            Tile(layer) => {
                println!("Layer '{}' with {}x{} tiles", layer.name, layer.size.x, layer.size.y);
            },
            Group(layer) => {
                println!("Group layer '{}' with {} sub-layers", layer.name, layer.content.len());

                // increase indentation for all layers part of this group
                indent += 1;
            },
            Object(layer) => {
                println!("Layer '{}' containing {} objects", layer.name, layer.content.len());
            },
        }
    }
    Ok(())
}

You can run this example with cargo run -q --example layer_printer.

Feature support

The following TMX features are implemented βœ…, partially supported 🚧 or missing ❌ in tego. This is not an exhaustive list.

  • 🚧 Loading of maps with metadata:

    • βœ… Orthogonal & Isometric maps
    • ❌ Hexagonal & staggered maps
    • ❌ Editor related metadata
    • βœ… Color information
  • 🚧 Tile Sets

    • βœ… Metadata
    • βœ… Sprite Sheet lookup with spacing/margin
    • βœ… External tile set files (*.tsx)
    • ❌ Image collection Tile Sets
    • ❌ Object Alignment information
  • 🚧 Tile layers

    • βœ… uncompressed/zlib/gzip base64 data
    • ❌ csv loading
    • ❌ <tile> loading
    • βœ…Tile flipping
  • ❌ Infinite maps

  • 🚧 Object layers

    • βœ… Basic Rect/Ellipse/Point object
    • βœ… Polygons & Polylines
    • 🚧 Text (Some metadata is still not supported, e.g. haling/valign)
    • βœ… Object Templates
  • ❌ Image layers

  • βœ… Properties

Commit count: 85

cargo fmt