Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#[cfg(feature = "json_loader")]
mod json {
use bevy::asset::{AssetLoader, BoxedFuture, Error, LoadContext, LoadedAsset};
use crate::definitions::AnimationSet;
pub struct AnimationSetJsonLoader;
impl AssetLoader for AnimationSetJsonLoader {
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<(), Error>> {
Box::pin(async move {
let value: AnimationSet = serde_json::from_slice(bytes)?;
load_context.set_default_asset(LoadedAsset::new(value));
Ok(())
})
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["anim.json"];
EXTENSIONS
}
}
}
#[cfg(feature = "toml_loader")]
mod toml {
use bevy::asset::{AssetLoader, BoxedFuture, Error, LoadContext, LoadedAsset};
use crate::definitions::AnimationSet;
pub struct AnimationSetTomlLoader;
impl AssetLoader for AnimationSetTomlLoader {
fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, anyhow::Result<(), Error>> {
Box::pin(async move {
let value: AnimationSet = toml::from_slice(bytes)?;
load_context.set_default_asset(LoadedAsset::new(value));
Ok(())
})
}
fn extensions(&self) -> &[&str] {
static EXTENSIONS: &[&str] = &["anim.toml"];
EXTENSIONS
}
}
}
use bevy::app::App;
use bevy::prelude::{AddAsset, Plugin};
pub struct AnimationLoadersPlugin;
impl Plugin for AnimationLoadersPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<crate::definitions::AnimationSet>();
#[cfg(feature = "json_loader")]
app.add_asset_loader(json::AnimationSetJsonLoader);
#[cfg(feature = "toml_loader")]
app.add_asset_loader(self::toml::AnimationSetTomlLoader);
}
}