use bevy::prelude::*;
use leafwing_input_manager::clashing_inputs::ClashStrategy;
use leafwing_input_manager::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(InputManagerPlugin::<TestAction>::default())
.add_systems(Startup, spawn_input_map)
.add_systems(Update, report_pressed_actions)
.insert_resource(ClashStrategy::PrioritizeLongest)
.run()
}
#[derive(Actionlike, Debug, Clone, Copy, PartialEq, Eq, Hash, Reflect)]
enum TestAction {
One,
Two,
Three,
OneAndTwo,
OneAndThree,
TwoAndThree,
OneAndTwoAndThree,
}
fn spawn_input_map(mut commands: Commands) {
use KeyCode::*;
use TestAction::*;
let mut input_map = InputMap::default();
input_map.insert_multiple([(One, Digit1), (Two, Digit2), (Three, Digit3)]);
input_map.insert_chord(OneAndTwo, [Digit1, Digit2]);
input_map.insert_chord(OneAndThree, [Digit1, Digit3]);
input_map.insert_chord(TwoAndThree, [Digit2, Digit3]);
input_map.insert_chord(OneAndTwoAndThree, [Digit1, Digit2, Digit3]);
commands.spawn(InputManagerBundle {
input_map,
..Default::default()
});
}
fn report_pressed_actions(
query: Query<&ActionState<TestAction>, Changed<ActionState<TestAction>>>,
) {
let action_state = query.single();
dbg!(action_state.get_just_pressed());
}