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
use std::hash::Hash;
use std::path::Path;
use amethyst_config::Config;
use amethyst_core::bundle::{Result, SystemBundle};
use amethyst_core::specs::prelude::DispatcherBuilder;
use serde::Serialize;
use serde::de::DeserializeOwned;
use {Bindings, InputSystem};
#[derive(Default)]
pub struct InputBundle<AX, AC>
where
AX: Hash + Eq,
AC: Hash + Eq,
{
bindings: Option<Bindings<AX, AC>>,
}
impl<AX, AC> InputBundle<AX, AC>
where
AX: Hash + Eq + DeserializeOwned + Serialize + Default,
AC: Hash + Eq + DeserializeOwned + Serialize + Default,
{
pub fn new() -> Self {
Default::default()
}
pub fn with_bindings(mut self, bindings: Bindings<AX, AC>) -> Self {
self.bindings = Some(bindings);
self
}
pub fn with_bindings_from_file<P: AsRef<Path>>(self, file: P) -> Self {
self.with_bindings(Bindings::load(file))
}
}
impl<'a, 'b, AX, AC> SystemBundle<'a, 'b> for InputBundle<AX, AC>
where
AX: Hash + Eq + Clone + Send + Sync + 'static,
AC: Hash + Eq + Clone + Send + Sync + 'static,
{
fn build(self, builder: &mut DispatcherBuilder<'a, 'b>) -> Result<()> {
builder.add(
InputSystem::<AX, AC>::new(self.bindings),
"input_system",
&[],
);
Ok(())
}
}