0.1.0-0-pre.8
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
// file: crates/engines/engine-v1-common/src/input.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
/// Platform-independent snapshot of logical input actions for one update.
|
||||
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq)]
|
||||
pub struct InputState {
|
||||
left: bool,
|
||||
right: bool,
|
||||
@@ -11,13 +11,23 @@ pub struct InputState {
|
||||
primary: bool,
|
||||
secondary: bool,
|
||||
pause: bool,
|
||||
pointer: crate::PointerState,
|
||||
}
|
||||
|
||||
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 };
|
||||
return Self {
|
||||
left: false,
|
||||
right: false,
|
||||
up: false,
|
||||
down: false,
|
||||
primary: false,
|
||||
secondary: false,
|
||||
pause: false,
|
||||
pointer: crate::PointerState::inactive(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns a copy with the selected logical action set to the requested state.
|
||||
@@ -35,6 +45,13 @@ impl InputState {
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Returns a copy carrying the selected normalized primary pointer state.
|
||||
#[must_use]
|
||||
pub const fn with_pointer(mut self, pointer: crate::PointerState) -> Self {
|
||||
self.pointer = pointer;
|
||||
return self;
|
||||
}
|
||||
|
||||
/// Reports whether the selected logical action is active.
|
||||
#[must_use]
|
||||
pub const fn is_active(self, action: crate::GameAction) -> bool {
|
||||
@@ -48,6 +65,12 @@ impl InputState {
|
||||
crate::GameAction::Pause => self.pause,
|
||||
};
|
||||
}
|
||||
|
||||
/// Returns the primary pointer snapshot.
|
||||
#[must_use]
|
||||
pub const fn pointer(self) -> crate::PointerState {
|
||||
return self.pointer;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user