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
use crate::Kurinji;
use bevy::app::Events;
use bevy::ecs::{
Res,
ResMut,
};
pub struct OnActionActive
{
pub action: String,
pub strength: f32,
}
pub struct OnActionBegin
{
pub action: String,
pub strength: f32,
}
pub struct OnActionProgress
{
pub action: String,
pub strength: f32,
}
pub struct OnActionEnd
{
pub action: String,
}
impl Kurinji
{
pub(crate) fn action_event_producer(input_map: Res<Kurinji>,
mut on_active_event: ResMut<Events<OnActionActive>>,
mut on_begin_event: ResMut<Events<OnActionBegin>>,
mut on_progress_event: ResMut<Events<OnActionProgress>>,
mut on_end_event: ResMut<Events<OnActionEnd>>)
{
let mut _actions = input_map.action_raw_strength.clone();
for (a, s) in input_map.action_prev_strength.iter()
{
if !_actions.contains_key(a)
{
_actions.insert(a.clone(), s.clone());
}
}
for (action, strength) in _actions
{
if input_map.is_action_active(&action)
{
on_active_event.send(OnActionActive { action: action.clone(),
strength: strength, });
}
if input_map.did_action_just_began(&action)
{
on_begin_event.send(OnActionBegin { action: action.clone(),
strength: strength, });
}
if input_map.is_action_in_progress(&action)
{
on_progress_event.send(OnActionProgress {
action: action.clone(),
strength: strength,
});
}
if input_map.did_action_just_end(&action)
{
on_end_event.send(OnActionEnd { action: action.clone(), });
}
}
}
}