Crate ldtk2[−][src]
Expand description
A thin crate for people who just want to use ldtk files freely.
Why did I create this nonsense?
- LDtk-rs uses code generation, it does not get autocomplete support from rust-analyzer. Also, there are special license restrictions on using that crate.
- ldtk_rust uses
.except()
inside the crate, you can’t handle errors.
Supported LDtk file versions
^0.9.3
Usage
cargo add ldtk2
use std::{error::Error, path::Path, convert::TryInto};
fn main() -> Result<(), Box<dyn Error>> {
use ldtk2::Ldtk;
let map = Ldtk::from_path("tests/example.ldtk")?;
// or
let map: Ldtk = Path::new("tests/example.ldtk").try_into()?;
// or
let map = Ldtk::from_str(include_str!("../tests/example.ldtk"))?;
// or
let map: Ldtk = include_str!("../tests/example.ldtk").try_into()?;
Ok(())
}
Re-exports
pub use anyhow;
pub use serde_json;
Structs
This complex section isn’t meant to be used by game devs at all, as these rules are completely resolved internally by the editor before any saving. You should just ignore this part.
This file is a JSON schema of files created by LDtk level editor (https://ldtk.io).
A structure containing all the definitions of this project
Tile data in an Entity instance
This section is mostly only intended for the LDtk editor app itself. You can safely ignore it.
IntGrid value definition
IntGrid value instance
This section contains all the level data. It can be found in 2 distinct forms, depending
on Project current settings: - If “Separate level files” is disabled (default):
full level data is embedded inside the main Project JSON file, - If “Separate level
files” is enabled: level data is stored in separate standalone .ldtkl
files (one
per level). In this case, the main Project JSON file will still contain most level data,
except heavy sections, like the layerInstances
array (which will be null). The
externalRelPath
string points to the ldtkl
file. A ldtkl
file is just a JSON file
containing exactly what is described below.
Level background image position info
Nearby level info
This structure represents a single tile from a given Tileset.
The Tileset
definition is the most important part among project definitions. It
contains some extra informations about each integrated tileset. If you only had to parse
one definition section, that would be the one.
Enums
Checker mode Possible values: None
, Horizontal
, Vertical
Possible values: Hidden
, ValueOnly
, NameAndValue
, EntityTile
, Points
,
PointStar
, PointPath
, PointPathLoop
, RadiusPx
, RadiusGrid
Possible values: Above
, Center
, Beneath
“Image export” option when saving project. Possible values: None
, OneImagePerLayer
,
OneImagePerLevel
Possible values: DiscardOldOnes
, PreventAdding
, MoveLastOne
If TRUE, the maxCount is a “per world” limit, if FALSE, it’s a “per level”. Possible
values: PerLayer
, PerLevel
, PerWorld
Possible values: Rectangle
, Ellipse
, Tile
, Cross
Defines how tileIds array is used Possible values: Single
, Stamp
Possible values: Cover
, FitInside
, Repeat
, Stretch
Type of the layer as Haxe Enum Possible values: IntGrid
, Entities
, Tiles
,
AutoLayer
An enum that describes how levels are organized in this project (ie. linearly or in a 2D
space). Possible values: Free
, GridVania
, LinearHorizontal
, LinearVertical