85 lines
1.8 KiB
Rust
85 lines
1.8 KiB
Rust
use bevy::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq, Default)]
|
|
pub enum InputActionState {
|
|
JustPressed,
|
|
Pressed,
|
|
JustReleased,
|
|
#[default]
|
|
Released,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum InputMapAction {
|
|
MovementXDir(i32),
|
|
MovementYDir(i32),
|
|
Jump,
|
|
Shield,
|
|
Attack,
|
|
}
|
|
|
|
impl InputMapAction {
|
|
pub const fn digital_action(&self) -> Option<crate::input::DigitalAction> {
|
|
match self {
|
|
Self::Jump => Some(crate::input::DigitalAction::Jump),
|
|
Self::Shield => Some(crate::input::DigitalAction::Shield),
|
|
Self::Attack => Some(crate::input::DigitalAction::Attack),
|
|
Self::MovementXDir(_) | Self::MovementYDir(_) => None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum MenuInputMapAction {
|
|
MovementXDir(i32),
|
|
MovementYDir(i32),
|
|
Accept,
|
|
Back,
|
|
Start,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct KeyboardInputMapElement {
|
|
pub key: KeyCode,
|
|
pub action: InputMapAction,
|
|
pub binding_slot: u8,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum GamepadBinding {
|
|
Button(GamepadButton),
|
|
Axis(GamepadAxis, i32),
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct GamepadInputMapElement {
|
|
pub binding: GamepadBinding,
|
|
pub action: InputMapAction,
|
|
pub binding_slot: u8,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct MenuKeyboardInputMapElement {
|
|
pub key: KeyCode,
|
|
pub action: MenuInputMapAction,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct MenuGamepadInputMapElement {
|
|
pub binding: GamepadBinding,
|
|
pub action: MenuInputMapAction,
|
|
}
|
|
|
|
#[derive(Resource)]
|
|
pub struct BaseInputMap {
|
|
pub keyboard: Vec<KeyboardInputMapElement>,
|
|
pub gamepad: Vec<GamepadInputMapElement>,
|
|
}
|
|
|
|
#[derive(Resource)]
|
|
pub struct MenuInputMap {
|
|
pub keyboard: Vec<MenuKeyboardInputMapElement>,
|
|
pub gamepad: Vec<MenuGamepadInputMapElement>,
|
|
}
|