Giter VIP home page Giter VIP logo

tiled-json's Introduction

tiled-json

Build Status

Under development

Read maps from the Tiled Map Editor into rust. Only json files with ebedded tilesets are supported, use rs-tiled to read xml files.

Inspired by rs-tiled crate.

Example

use std::path::Path;

use tiled_json::parse;

fn main() {
    let file = File::open(&Path::new("assets/map.json")).unwrap();
    println!("Opened file");
    let reader = BufReader::new(file);
    let map = parse(reader).unwrap();
    println!("{:?}", map);
}

Amethyst example

Enable json feature with --features.

use amethyst::{
    assets::{AssetStorage, Asset, Handle, ProcessableAsset, ProcessingState, JsonFormat},
    ecs::{VecStorage, World},
    error::Error,
};

use tiled_json::Map;

#[derive(Clone, Debug)]
struct Tilemap(pub Map);

impl Asset for Tilemap {
    const NAME: &'static str = "tiled_json::Map";
    type Data = Map;
    type HandleStorage = VecStorage<Handle<Tilemap>>;
}

impl ProcessableAsset for Tilemap {
    fn process(data: Map) -> Result<ProcessingState<Tilemap>, Error> {
        Ok(ProcessingState::Loaded(Tilemap { 0: data }))
    }
}

fn load_tilemap(world: &mut World) -> Handle<Tilemap> {
	let loader = world.read_resource::<Loader>();
	let tilemap_store = world.read_resource::<AssetStorage<Tilemap>>();

	loader.load("assets/map.json", JsonFormat, (), &tilemap_store)
}

Licences

Licenced under MIT.

Assets

assets/tilesheet.png by Andre Mari Coppola

tiled-json's People

Contributors

hyrsky avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.