Struct Interaction

Source
pub struct Interaction { /* private fields */ }

Implementations§

Source§

impl Interaction

Source

pub fn new(duration: f32) -> Result<Interaction, LoopError>

Source

pub fn progress(&self) -> f32

Source

pub fn cancel(&mut self)

Source

pub fn eligibility( &self, input: InteractionInput, ) -> Result<(), InteractionRejection>

Checks current conditions without consuming time, changing the pair, clearing progress or rearming the completion latch.

Ok(()) means the hold may advance, not that it is complete. A different eligible pair may start a new hold; the query does not perform that switch. If several gates fail, precedence follows InteractionRejection. Always supply current conditions again when stepping; a query is not authorization to use a stale snapshot later.

use ferravex_play::gameplay::interaction::{
    Interaction, InteractionInput, InteractionRejection,
};
let mut hold = Interaction::new(1.0).unwrap();
hold.step(0.5, Some((1, 2))).unwrap();
let blocked = InteractionInput {
    pair: Some((1, 2)), held: true, in_range: false, focused: true,
    permitted: true, visible: true,
};
assert_eq!(hold.eligibility(blocked), Err(InteractionRejection::OutOfRange));
assert_eq!(hold.progress(), 0.5);
Source

pub fn step_checked( &mut self, dt: f32, input: InteractionInput, ) -> Result<InteractionOutcome, LoopError>

Advances an eligible hold and reports rejection/interruption reasons.

A failed condition discards the unfinished hold (continuous holding is required), but spends none of dt and cannot emit a completion. Repeating a rejected input reports the same rejection without another interruption. AlreadyCompleted preserves the completion latch and full progress. Pair switches restart exactly as in Self::step.

Call only for actual simulation ticks, using simulation seconds in 0..=3600. Invalid time returns LoopError::Invalid before checking gates or changing any state, including when input would interrupt.

use ferravex_play::gameplay::interaction::{
    Interaction, InteractionInput, InteractionInterruption, InteractionRejection,
};
let input = InteractionInput {
    pair: Some((1, 2)), held: true, in_range: true, focused: true,
    permitted: true, visible: true,
};
let mut hold = Interaction::new(1.0).unwrap();
assert!(!hold.step_checked(0.5, input).unwrap().completed);
let lost_focus = InteractionInput { focused: false, ..input };
let stopped = hold.step_checked(1.0, lost_focus).unwrap();
assert!(!stopped.completed);
assert_eq!(stopped.interruption, Some(InteractionInterruption::Rejected(
    InteractionRejection::FocusLost,
)));
assert_eq!(hold.progress(), 0.0);
assert!(hold.step_checked(1.0, input).unwrap().completed);
assert_eq!(hold.step_checked(1.0, input).unwrap().rejection,
    Some(InteractionRejection::AlreadyCompleted));
Source

pub fn step( &mut self, dt: f32, pair: Option<(u64, u64)>, ) -> Result<bool, LoopError>

None interrupts. Supply Some only while the button, range, permissions and line of sight are valid. Target switches restart; completion latches until interruption/switch, so holding cannot repeatedly grant a reward. Use Self::step_checked to retain typed reasons for failed conditions.

Trait Implementations§

Source§

impl Clone for Interaction

Source§

fn clone(&self) -> Interaction

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Interaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Copy for Interaction

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.