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
// publics
pub use self::
{
    input_map::InputMap,

    axis::MouseAxis,
    axis::GamepadAxis,
    
    bindings::Bindings,
    
    event_phase::EventPhase,
    
    action_event::OnActionBegin,
    action_event::OnActionActive,
    action_event::OnActionProgress,
    action_event::OnActionEnd,
};

// crates
mod axis;
mod util;
mod stack;
mod bindings;
mod input_map;
mod event_phase;
mod action_event;

mod action;
mod gamepad;
mod keyboard;
mod mouse;
mod serde;

use bevy::app::prelude::*;
use bevy::ecs::IntoQuerySystem;

/// Adds input mapping (via code or json/ron) to an App
#[derive(Default)]
pub struct InputMapPlugin;

impl Plugin for InputMapPlugin {
    fn build(&self, app: &mut AppBuilder) {
        app
            // input map
            .init_resource::<InputMap>()
            // events
            .add_event::<OnActionActive>()
            .add_event::<OnActionBegin>()
            .add_event::<OnActionProgress>()
            .add_event::<OnActionEnd>()
            .add_system_to_stage(stage::EVENT, InputMap::action_event_producer.system())
            // reset
            .add_system_to_stage(stage::PRE_UPDATE, InputMap::action_reset_system.system())
            // joystick
            .add_system_to_stage(
                stage::UPDATE,
                InputMap::gamepad_connection_event_system.system(),
            )
            .add_system_to_stage(
                stage::UPDATE,
                InputMap::gamepad_button_press_input_system.system(),
            )
            .add_system_to_stage(stage::UPDATE, InputMap::gamepad_axis_system.system())
            // keyboard
            .add_system_to_stage(stage::UPDATE, InputMap::kb_key_press_input_system.system())
            // mouse
            .add_system_to_stage(
                stage::UPDATE,
                InputMap::mouse_button_press_input_system.system(),
            )
            .add_system_to_stage(stage::UPDATE, InputMap::mouse_move_event_system.system());
    }
}