Allows for static and dynamic file hierarchies loading, integrity checking, reloading and more with minimal runtime logic using the rust type system.
Also supports #[no_std] environments and provide the ability to define custom asset tree loaders (for virtual file systems/embedded platforms...).
- Easy to use macro to statically define asset trees
StdOsLoaderfor loading assets from the file system + ability to define custom asset loaders- Support for
#[no_std]environment. (withallocdependency) - Ability to load/reload any part of the asset tree when needed
- Ability to check the integrity of the asset tree when needed
- Runtime asset tree data/bound representation
- Error handling and unused assets logging for easier debugging (can be disabled using the
no_logfeature) - Custom file types with loader independent logic
- Minimal runtime logic
- Add the dependency to your
Cargo.tomlfile:
[dependencies]
asset_tree = { git = "https://github.com/Swiiz/asset_tree" }- Define your file types (This will implement the Asset trait for each file type)
β For this to work you need to implementFrom<Vec<u8>>orTryFrom<Vec<u8>>for each file type.
asset_files! {
Texture : "png",
Blueprint : "bp",
}- Define your asset tree (This generates a AssetsFolder, TexturesFolder and BlueprintsFolder types with their respective fields)
βΉ Thebuiltin::Foldertype will automatically collect all assets in the subfolder matching the generic asset.
asset_tree! {
assets {
textures {
house : Texture,
garden : Texture,
},
blueprints : builtin::Folder<Blueprint>,
},
}- You can now check the integrity of the asset tree / load it using the root struct (AssetsFolder).
// Checks the integrity of the asset tree
let missing = check_integrity(&AssetsFolder::asset_tree(), ctx).unwrap();
if !missing.is_empty() {
panic!("Missing assets: {:?}", missing);
}
// Loads the asset tree
let assets = AssetsFolder::load().unwrap();- You can also reload the asset tree at any time
assets.reload().unwrap();- Lastly you can access the assets in the tree safely and easily
let house_texture = assets.textures.house;
let blueprint = assets.blueprints.iter_nodes(); //or <&_ as IntoIterator>::into_iter() to only get values-
The main features showcased in a single example.
Run the example:
cargo run --example fullSee the generated code documentation:
cargo doc --example full --no-deps --open
Note
This is a work in progress. Documentation needs to be written/improved.
Feel free to open an issue or contribute! Any help is appreciated π