use anput::bundle::DynamicBundle;
use keket::{
database::{AssetDatabase, path::AssetPath},
fetch::{AssetBytesAreReadyToProcess, AssetFetch},
protocol::text::TextAssetProtocol,
};
use std::error::Error;
fn main() -> Result<(), Box<dyn Error>> {
let mut database = AssetDatabase::default()
.with_protocol(TextAssetProtocol)
.with_fetch(CustomAssetFetch([(
"lorem.txt",
include_bytes!("../../../resources/lorem.txt"),
)]));
let handle = database.ensure("text://lorem.txt")?;
println!("Lorem Ipsum: {}", handle.access::<&String>(&database));
Ok(())
}
struct AssetFromCustomSource;
struct CustomAssetFetch<const N: usize>([(&'static str, &'static [u8]); N]);
impl<const N: usize> AssetFetch for CustomAssetFetch<N> {
fn load_bytes(&self, path: AssetPath) -> Result<DynamicBundle, Box<dyn Error>> {
for (name, bytes) in self.0 {
if path.path() == name {
let mut bundle = DynamicBundle::default();
bundle
.add_component(AssetBytesAreReadyToProcess(bytes.to_vec()))
.ok()
.unwrap();
bundle.add_component(AssetFromCustomSource).ok().unwrap();
return Ok(bundle);
}
}
Err(format!("Missing asset: `{path}`").into())
}
}