pub struct Input {
pub mouse_delta: Vec2,
pub scroll: f32,
pub canvas: Canvas,
/* private fields */
}Expand description
Input snapshot, editable action bindings and shell requests.
Interior mutability permits shared script access to bindings and the HUD.
Do not hold a Self::hud borrow while calling another HUD operation.
Fields§
§mouse_delta: Vec2Pointer movement accumulated by the shell for this frame, in shell units.
scroll: f32Vertical wheel movement for this frame, in shell units.
canvas: CanvasScreen interface drawn by scripts this frame.
Implementations§
Source§impl Input
impl Input
Sourcepub fn key_pressed(&self, k: Key) -> bool
pub fn key_pressed(&self, k: Key) -> bool
True only on the frame the key went down.
Sourcepub fn key_released(&self, k: Key) -> bool
pub fn key_released(&self, k: Key) -> bool
True only in the snapshot where a previously held key was released.
Sourcepub fn mouse_down(&self, b: MouseButton) -> bool
pub fn mouse_down(&self, b: MouseButton) -> bool
Whether a pointer button is currently held.
Sourcepub fn mouse_pressed(&self, b: MouseButton) -> bool
pub fn mouse_pressed(&self, b: MouseButton) -> bool
True only in the snapshot where a pointer button went down.
Sourcepub fn mouse_released(&self, b: MouseButton) -> bool
pub fn mouse_released(&self, b: MouseButton) -> bool
True only in the snapshot where a pointer button was released.
Sourcepub fn lock_cursor(&self, lock: bool)
pub fn lock_cursor(&self, lock: bool)
Scripts ask the shell to hide the cursor and keep it centred (mouse look).
Sourcepub fn cursor_locked(&self) -> bool
pub fn cursor_locked(&self) -> bool
Current cursor-lock request; the hosting shell is responsible for applying it.
Sourcepub fn request_scene(&self, request: SceneRequest)
pub fn request_scene(&self, request: SceneRequest)
Asks the host to change scenes after this frame. A later request in the same frame wins.
Sourcepub fn take_scene_request(&self) -> Option<SceneRequest>
pub fn take_scene_request(&self) -> Option<SceneRequest>
Takes the pending scene change, if any (hosts call this after each tick).
Sourcepub fn scene_path(&self) -> String
pub fn scene_path(&self) -> String
Asset path of the running scene (empty when the host did not say).
Sourcepub fn set_scene_path(&self, path: &str)
pub fn set_scene_path(&self, path: &str)
Records the asset path of the running scene (hosts call this).
Sourcepub fn set_storage(&self, storage: Storage)
pub fn set_storage(&self, storage: Storage)
Sets the game’s data folder (hosts call this once).
Sourcepub fn request_quit(&self)
pub fn request_quit(&self)
Asks the host to close the game.
Sourcepub fn quit_requested(&self) -> bool
pub fn quit_requested(&self) -> bool
Whether a script asked to quit (hosts poll this).
Sourcepub fn request_fullscreen(&self, on: bool)
pub fn request_fullscreen(&self, on: bool)
Asks the host to switch fullscreen on or off.
Sourcepub fn take_fullscreen_request(&self) -> Option<bool>
pub fn take_fullscreen_request(&self) -> Option<bool>
Takes a pending fullscreen request (hosts poll this).
Sourcepub fn begin_frame(&self, dt: f32)
pub fn begin_frame(&self, dt: f32)
Called by the game loop every frame before scripts run.
Sourcepub fn axis(&self, minus: Key, plus: Key) -> f32
pub fn axis(&self, minus: Key, plus: Key) -> f32
Axis from two keys: +1 when plus is held, -1 when minus is held.
Sourcepub fn action_down(&self, name: &str) -> bool
pub fn action_down(&self, name: &str) -> bool
True while any input bound to the action is held.
Sourcepub fn action_pressed(&self, name: &str) -> bool
pub fn action_pressed(&self, name: &str) -> bool
True on the frame an input bound to the action went down.
Sourcepub fn action_released(&self, name: &str) -> bool
pub fn action_released(&self, name: &str) -> bool
True when the last held source of an action is released. Releasing one alternative while another is held does not release the action. A press and release of different sources in the same snapshot keeps it active.
Sourcepub fn action_vector(
&self,
left: &str,
right: &str,
down: &str,
up: &str,
) -> Vec2
pub fn action_vector( &self, left: &str, right: &str, down: &str, up: &str, ) -> Vec2
Two-dimensional action vector, clamped to unit length to avoid faster diagonals.
Positive X is right, positive Y is up; absent actions contribute zero.
Sourcepub fn has_action(&self, name: &str) -> bool
pub fn has_action(&self, name: &str) -> bool
Whether an action exists, including actions with no sources.
Sourcepub fn remove_action(&self, name: &str) -> bool
pub fn remove_action(&self, name: &str) -> bool
Removes an action, returning whether it existed.
Sourcepub fn try_rebind(&self, name: &str, sources: &[&str]) -> Result<(), String>
pub fn try_rebind(&self, name: &str, sources: &[&str]) -> Result<(), String>
Validates all input names before replacing a binding.
Returns the first invalid name without changing existing bindings.
Unlike Self::rebind, this catches configuration typos.
Sourcepub fn action_axis(&self, negative: &str, positive: &str) -> f32
pub fn action_axis(&self, negative: &str, positive: &str) -> f32
-1..1 from two actions, e.g. action_axis("MoveLeft", "MoveRight").
Sourcepub fn rebind(&self, name: &str, sources: &[&str])
pub fn rebind(&self, name: &str, sources: &[&str])
Replaces (or creates) an action’s bindings. Unknown names are ignored.
Sourcepub fn bindings(&self) -> Vec<(String, Vec<&'static str>)>
pub fn bindings(&self) -> Vec<(String, Vec<&'static str>)>
Current bindings as (action, input names).
Sourcepub fn set_bindings<S: AsRef<str>>(&self, defs: &[(String, Vec<S>)])
pub fn set_bindings<S: AsRef<str>>(&self, defs: &[(String, Vec<S>)])
Replaces all actions. Duplicate action names use the last definition;
unknown physical input names are ignored as in Self::rebind.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Input
impl !RefUnwindSafe for Input
impl !Sync for Input
impl Send for Input
impl Unpin for Input
impl UnsafeUnpin for Input
impl UnwindSafe for Input
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.