use bevy::prelude::*;
use bevy_enhanced_input::prelude::*;
#[cfg(feature = "hot_patch")]
use bevy_simple_subsecond_system::hot;
pub(super) fn plugin(app: &mut App) {
app.add_input_context::<DefaultInputContext>();
app.add_observer(default_binding);
}
#[derive(Debug, InputAction)]
#[input_action(output = Vec3)]
pub(crate) struct Move;
#[derive(Debug, InputAction)]
#[input_action(output = bool)]
pub(crate) struct Jump;
#[derive(Debug, InputAction)]
#[input_action(output = bool)]
pub(crate) struct Interact;
#[derive(Debug, InputAction)]
#[input_action(output = Vec2)]
pub(crate) struct Rotate;
#[derive(Debug, InputAction)]
#[input_action(output = bool)]
pub(crate) struct PickupProp;
#[derive(Debug, InputAction)]
#[input_action(output = bool)]
pub(crate) struct DropProp;
#[derive(Debug, InputContext, Default)]
pub(crate) struct DefaultInputContext;
#[cfg_attr(feature = "hot_patch", hot)]
fn default_binding(
trigger: Trigger<Binding<DefaultInputContext>>,
mut players: Query<&mut Actions<DefaultInputContext>>,
) {
const DEFAULT_SPEED: f32 = 8.0;
let mut actions = players.get_mut(trigger.target()).unwrap();
actions
.bind::<Move>()
.to((Cardinal::wasd_keys(), Axial::left_stick()))
.with_modifiers((
DeadZone::default(), SmoothNudge::default(), Scale::splat(DEFAULT_SPEED), Negate::y(),
SwizzleAxis::XZY,
));
actions
.bind::<Jump>()
.to((KeyCode::Space, GamepadButton::South));
actions
.bind::<Interact>()
.to((KeyCode::KeyE, GamepadButton::South));
const DEFAULT_SENSITIVITY: f32 = 0.002;
actions
.bind::<Rotate>()
.to((Input::mouse_motion(), Axial::right_stick()))
.with_modifiers((Negate::all(), Scale::splat(DEFAULT_SENSITIVITY)));
actions
.bind::<PickupProp>()
.to((MouseButton::Left, GamepadButton::East));
actions
.bind::<DropProp>()
.to((MouseButton::Right, GamepadButton::East));
}