1use std::collections::HashMap;
6use std::hash::Hash;
7
8use repame_sim::bevy_ecs::prelude::*;
9use repose_core::input::GamepadAxis;
10
11mod binding;
12mod map;
13mod state;
14
15pub use binding::Binding;
16pub use map::ActionMap;
17pub use state::ActionState;
18
19pub trait ActionLike: Clone + Eq + Hash + Send + Sync + 'static {}
22
23impl<T: Clone + Eq + Hash + Send + Sync + 'static> ActionLike for T {}
24
25pub fn init_state<A: ActionLike + std::fmt::Debug>(sim: &mut repame_sim::Sim, map: ActionMap<A>) {
27 sim.world.insert_resource(ActionState::new(map));
28}
29
30pub fn end_tick_system<A: ActionLike + std::fmt::Debug>(mut state: ResMut<ActionState<A>>) {
34 state.end_tick();
35}
36
37pub fn stick_pair(state_axes: &HashMap<GamepadAxis, f32>) -> (f32, f32) {
39 let x = state_axes
40 .get(&GamepadAxis::LeftStickX)
41 .copied()
42 .unwrap_or(0.0);
43 let y = state_axes
44 .get(&GamepadAxis::LeftStickY)
45 .copied()
46 .unwrap_or(0.0);
47 (x, y)
48}
49
50pub use repose_core::input::PointerButton as MouseButton;
51pub use repose_core::input::{GamepadAxis as Axis, GamepadButton as PadButton};
52pub use repose_core::shortcuts::KeyChord as Chord;