feat: Player is now using leafwing-input-manager

This commit is contained in:
Alexey 2026-03-03 16:49:28 +03:00
commit 957717671a
4 changed files with 68 additions and 24 deletions

View file

@ -5,16 +5,32 @@ pub mod input;
mod tests;
use bevy::prelude::*;
use leafwing_input_manager::prelude::*;
use serde::{Deserialize, Serialize};
pub struct ExpeditionPlugin;
pub enum InputActions {
MoveLeft,
MoveRight,
#[derive(Actionlike, PartialEq, Eq, Hash, Debug, Clone, Reflect, Serialize, Deserialize)]
pub enum InputAction {
#[actionlike(Axis)]
Move,
ToggleInventory,
Interact,
}
impl InputAction {
pub fn default_input_map() -> InputMap<Self> {
let input_map = InputMap::default()
.with_axis(Self::Move, VirtualAxis::ad())
.with_axis(Self::Move, GamepadAxis::LeftStickX)
.with(Self::ToggleInventory, KeyCode::KeyI)
.with(Self::ToggleInventory, GamepadButton::Select)
.with(Self::Interact, KeyCode::KeyE)
.with(Self::Interact, GamepadButton::East);
input_map
}
}
fn camera_bundle() -> impl Bundle {
(
Camera2d,
@ -38,7 +54,8 @@ fn setup_global(mut commands: Commands) {
impl Plugin for ExpeditionPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Startup, (player::setup_player, setup_global))
app.add_plugins(input::InputAssetPlugin::<InputAction>::default())
.add_systems(Startup, (player::setup_player, setup_global))
.add_systems(Update, player::handle_input);
}
}