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
use crate::Kurinji;

use bevy::app::Events;
use bevy::ecs::{Res, ResMut};

/// Event that is fired when action is active.
/// This depends on what event phase is set to
/// the action by default it will be OnProgress.
pub struct OnActionActive
{
    pub action: String,
    pub strength: f32
}

/// Event that gets fired at the beginning
/// of an action
pub struct OnActionBegin
{
    pub action: String,
    pub strength: f32
}

/// Event that gets fired during
/// an action
pub struct OnActionProgress
{
    pub action: String,
    pub strength: f32
}

/// Event that gets fired at the end
/// of an action
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>>,
    )
    {
        for (action, strength) in input_map.action_raw_strength.clone()
        {
            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() });
            }
        }
    }
}