mini_asset_loader
provides an extensible asset loading system, intended to load assets from
various sources for use in a game.
The asset types, loaded sources, caching behaviour, etc. is entirely customizable. Assets are reference-counted and thread-safe.
A simple asset type based on serde_json
and type tags is provided in the asset
module.
This example makes use of the asset
feature. This feature provides a simple Tagged JSON
asset type, which only works on nightly rust. However, substituting this for a custom asset
type will work in stable rust.
```rust use serde::{Serialize, Deserialize}; use miniassetloader::asset::{TaggedJsonAsset, TaggedJsonAssetCreationHandler}; use miniassetloader::loaders::ToCached; use miniassetloader::{TypedAssetLoader, assetloadervec}; use std::path::PathBuf;
// Creating an asset type is as easy as making a Serializable/Deserializable struct...
struct StringAsset { value: String }
// ...and then tagging it with these two lines:
impl TaggedJsonAsset for StringAsset {}
// ...Then, when we want to load assets... fn main() { // We create our loader setup as usual... let mut loader = assetloadervec![ PathBuf::from("assets/"), PathBuf::from("/globalassets/") ].tocached();
// Make a TaggedJsonAssetCreationHandler...
let mut handler = TaggedJsonAssetCreationHandler::default();
// And we can load our assets!
if let Some(my_string_asset) = loader.load_typed_asset::<StringAsset>(&mut handler, "my_string_asset.json") {
println!("String asset loaded: {}", my_string_asset.read().value);
}
} ```