Skip to main content

Crate lunar_gamedata_build

Crate lunar_gamedata_build 

Source
Expand description

build-time TOML compiler for lunar game data tables.

call from your crate’s build.rs to compile TOML source files into binary blobs that can be loaded at runtime by lunar_gamedata::GameData.

§build.rs example

fn main() {
    let src = std::fs::read_to_string("assets/data/enemies.toml").unwrap();
    let blob = lunar_gamedata_build::compile_toml(&src).unwrap();
    let out = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap());
    std::fs::write(out.join("gamedata.bin"), blob).unwrap();
    println!("cargo:rerun-if-changed=assets/data/enemies.toml");
}

§TOML format

use array-of-tables syntax. every record must contain an id string field. duplicate ids within a table are compile errors.

[[enemies]]
id = "goblin"
health = 100
speed = 2.5
sprite = "goblin.png"
boss = false

[[enemies]]
id = "orc"
health = 250
speed = 1.5

supported TOML value types: String, Integer, Float, Boolean. arrays, inline tables, and datetimes are not supported.

Functions§

compile_scene
compile a RON scene source string into the compact binary format.
compile_scene_file
compile a RON scene file into the compact binary format.
compile_toml
compile a TOML source string into a binary blob.
compile_toml_file
compile a TOML file to a binary blob.
compile_world_manifest
compile a world manifest XML source string into the compact binary format.
compile_world_manifest_file
compile a world manifest XML file into the compact binary format.