1use std::collections::HashMap;
5use std::hash::Hash;
6
7use repame_sim::bevy_ecs::prelude::*;
8use repose_core::input::GamepadAxis;
9
10mod aim;
11mod binding;
12mod held;
13mod keymap;
14mod map;
15mod remap;
16mod snapshot;
17mod state;
18
19pub use aim::{AimTracker, StagedClick};
20pub use binding::Binding;
21pub use held::reconcile_held;
22pub use keymap::{
23 Keymap, KeymapCapture, KeymapDevice, KeymapEntry, KeymapRow, chord_for_physical,
24 decode_keymap_entry, encode_keymap_entry, glyph_for_physical,
25};
26pub use map::ActionMap;
27pub use remap::RemapSession;
28pub use snapshot::{GamepadState, MouseState, TouchContact, apply_stick, dead_zone};
29pub use state::ActionState;
30
31pub trait ActionLike: Clone + Eq + Hash + Send + Sync + 'static {}
34
35impl<T: Clone + Eq + Hash + Send + Sync + 'static> ActionLike for T {}
36
37pub fn init_state<A: ActionLike + std::fmt::Debug>(sim: &mut repame_sim::Sim, map: ActionMap<A>) {
39 sim.world.insert_resource(ActionState::new(map));
40}
41
42pub fn end_tick_system<A: ActionLike + std::fmt::Debug>(mut state: ResMut<ActionState<A>>) {
44 state.end_tick();
45}
46
47pub fn end_input_tick_system<A: ActionLike + std::fmt::Debug>(
50 mut state: ResMut<ActionState<A>>,
51) {
52 state.end_tick();
53}
54
55pub fn stick_pair(state_axes: &HashMap<GamepadAxis, f32>) -> (f32, f32) {
57 let x = state_axes
58 .get(&GamepadAxis::LeftStickX)
59 .copied()
60 .unwrap_or(0.0);
61 let y = state_axes
62 .get(&GamepadAxis::LeftStickY)
63 .copied()
64 .unwrap_or(0.0);
65 (x, y)
66}
67
68pub use repose_core::input::PointerButton as MouseButton;
69pub use repose_core::input::{GamepadAxis as Axis, GamepadButton as PadButton};
70pub use repose_core::shortcuts::KeyChord as Chord;