pub struct Interaction { /* private fields */ }Implementations§
Source§impl Interaction
impl Interaction
pub fn new(duration: f32) -> Result<Interaction, LoopError>
pub fn progress(&self) -> f32
pub fn cancel(&mut self)
Sourcepub fn eligibility(
&self,
input: InteractionInput,
) -> Result<(), InteractionRejection>
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);Sourcepub fn step_checked(
&mut self,
dt: f32,
input: InteractionInput,
) -> Result<InteractionOutcome, LoopError>
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));Sourcepub fn step(
&mut self,
dt: f32,
pair: Option<(u64, u64)>,
) -> Result<bool, LoopError>
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
impl Clone for Interaction
Source§fn clone(&self) -> Interaction
fn clone(&self) -> Interaction
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more