0.1.0-0-pre.3

This commit is contained in:
2026-09-16 00:46:04 +02:00
parent 8c0252e34e
commit 2c79a05dd6
26 changed files with 589 additions and 53 deletions

View File

@@ -0,0 +1,61 @@
// file: crates/engines/engine-v1-common/src/input.rs
// version: 1
/// Platform-independent snapshot of logical input actions for one update.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct InputState {
left: bool,
right: bool,
up: bool,
down: bool,
primary: bool,
secondary: bool,
pause: bool,
}
impl InputState {
/// Creates a snapshot with no active action.
#[must_use]
pub const fn none() -> Self {
return Self { left: false, right: false, up: false, down: false, primary: false, secondary: false, pause: false };
}
/// Returns a copy with the selected logical action set to the requested state.
#[must_use]
pub const fn with_action(mut self, action: crate::GameAction, active: bool) -> Self {
match action {
crate::GameAction::Left => self.left = active,
crate::GameAction::Right => self.right = active,
crate::GameAction::Up => self.up = active,
crate::GameAction::Down => self.down = active,
crate::GameAction::Primary => self.primary = active,
crate::GameAction::Secondary => self.secondary = active,
crate::GameAction::Pause => self.pause = active,
}
return self;
}
/// Reports whether the selected logical action is active.
#[must_use]
pub const fn is_active(self, action: crate::GameAction) -> bool {
return match action {
crate::GameAction::Left => self.left,
crate::GameAction::Right => self.right,
crate::GameAction::Up => self.up,
crate::GameAction::Down => self.down,
crate::GameAction::Primary => self.primary,
crate::GameAction::Secondary => self.secondary,
crate::GameAction::Pause => self.pause,
};
}
}
#[cfg(test)]
mod unit_tests {
#[test]
fn action_state_is_independent() {
let state = crate::InputState::none().with_action(crate::GameAction::Primary, true);
assert!(state.is_active(crate::GameAction::Primary));
assert!(!state.is_active(crate::GameAction::Secondary));
}
}