Assets are external files — JSON, images, other data — that the compiler validates and makes available at compile time.
Declare asset paths in ZithProject.toml:
[project]
name = "my_game"
version = "0.1.0"
[assets]
assets = ["assets/", "../someOtherFolder"]
The compiler verifies that every declared path exists and is readable.
import assets/data.json as Data;
import assets/sprites/player.png as PlayerSprite;
asis mandatory here, to avoid conflicts between files that share a name but differ in extension.
Imported assets are available as compile-time constants.
Combine assets with const fn to process them before the program runs:
import assets/config.json as ConfigData;
const fn parseConfig(data: []char): Config {
// parse JSON at compile time
JSON.parse(data)!
}
const CONFIG = parseConfig(ConfigData); // runs at compile time
Assets not declared in [assets] are loaded at runtime with standard file I/O:
let runtimeData = fs.read("runtime/save.json")!;
Zith Language Specification — Draft v0.9