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
68
69
70
71
72
73
74
75
76
77
78
79
use std::{borrow::Borrow, hash::Hash};
use amethyst_core::ecs::{
shred::{ResourceId, SystemData},
Read, ReadExpect, World,
};
use crate::{Asset, AssetStorage, Format, Handle, Loader, Progress};
#[derive(SystemData)]
pub struct AssetLoaderSystemData<'a, A>
where
A: Asset,
{
loader: ReadExpect<'a, Loader>,
storage: Read<'a, AssetStorage<A>>,
}
impl<'a, A> AssetLoaderSystemData<'a, A>
where
A: Asset,
{
pub fn load<F, N, P>(&self, name: N, format: F, progress: P) -> Handle<A>
where
F: Format<A::Data>,
N: Into<String>,
P: Progress,
{
self.loader.load(name, format, progress, &*self.storage)
}
pub fn load_from<F, N, P, S>(&self, name: N, format: F, source: &S, progress: P) -> Handle<A>
where
F: Format<A::Data>,
N: Into<String>,
P: Progress,
S: AsRef<str> + Eq + Hash + ?Sized,
String: Borrow<S>,
{
self.loader
.load_from(name, format, source, progress, &*self.storage)
}
pub fn load_from_data<P>(&self, data: A::Data, progress: P) -> Handle<A>
where
A: Asset,
P: Progress,
{
self.loader.load_from_data(data, progress, &*self.storage)
}
pub fn load_from_data_async<P, F>(&self, data: F, progress: P) -> Handle<A>
where
A: Asset,
P: Progress,
F: FnOnce() -> A::Data + Send + Sync + 'static,
{
self.loader
.load_from_data_async(data, progress, &*self.storage)
}
}