#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum InputAction {
MoveForward,
MoveBackward,
MoveLeft,
MoveRight,
MoveUp,
MoveDown,
Sprint,
Crouch,
Jump,
CameraRotate,
CameraPan,
CameraZoomIn,
CameraZoomOut,
CameraReset,
PrimaryAction,
SecondaryAction,
Interact,
Cancel,
Confirm,
OpenInventory,
OpenMap,
OpenChat,
OpenMenu,
ToggleFullscreen,
QuickSlot(u8),
Attack,
Block,
Dodge,
UseAbility(u8),
Pause,
Screenshot,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub enum InputMode {
#[default]
TileMap,
FreeCamera,
UiFocus,
Cinematic,
}
impl InputMode {
pub fn movement_enabled(&self) -> bool {
matches!(self, Self::TileMap | Self::FreeCamera)
}
pub fn camera_rotation_enabled(&self) -> bool {
matches!(self, Self::FreeCamera)
}
pub fn ui_capture(&self) -> bool {
matches!(self, Self::UiFocus)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn input_mode_defaults_to_tilemap() {
assert_eq!(InputMode::default(), InputMode::TileMap);
}
#[test]
fn movement_enabled_modes() {
assert!(InputMode::TileMap.movement_enabled());
assert!(InputMode::FreeCamera.movement_enabled());
assert!(!InputMode::UiFocus.movement_enabled());
assert!(!InputMode::Cinematic.movement_enabled());
}
#[test]
fn camera_rotation_only_free_camera() {
assert!(!InputMode::TileMap.camera_rotation_enabled());
assert!(InputMode::FreeCamera.camera_rotation_enabled());
assert!(!InputMode::UiFocus.camera_rotation_enabled());
}
#[test]
fn ui_capture_only_ui_focus() {
assert!(!InputMode::TileMap.ui_capture());
assert!(!InputMode::FreeCamera.ui_capture());
assert!(InputMode::UiFocus.ui_capture());
assert!(!InputMode::Cinematic.ui_capture());
}
#[test]
fn input_action_quick_slot() {
let a = InputAction::QuickSlot(0);
let b = InputAction::QuickSlot(1);
assert_ne!(a, b);
}
#[test]
fn input_action_use_ability() {
let a = InputAction::UseAbility(0);
let b = InputAction::UseAbility(3);
assert_ne!(a, b);
}
}