pub struct TriggerManager { /* private fields */ }Expand description
Manages a collection of Triggers and determines which ones should fire
given the player’s current (and previous) position.
§Usage
let mut mgr = TriggerManager::new();
mgr.add_trigger(Trigger::single_tile(
"heal_npc", "StartTown", TriggerType::OnStep,
3, 5, "healParty", true,
));
// Every frame
let triggered: Vec<String> = mgr.check_triggers("StartTown", 3, 5);
for name in &triggered {
script_engine.call_function(name);
}
// On A button press
if let Some(name) = mgr.check_interact_mut("StartTown", facing_x, facing_y) {
script_engine.call_function(&name);
}Implementations§
Source§impl TriggerManager
impl TriggerManager
Sourcepub fn add_trigger(&mut self, trigger: Trigger)
pub fn add_trigger(&mut self, trigger: Trigger)
Registers a single trigger.
Sourcepub fn add_triggers(&mut self, triggers: impl IntoIterator<Item = Trigger>)
pub fn add_triggers(&mut self, triggers: impl IntoIterator<Item = Trigger>)
Registers multiple triggers in bulk.
Sourcepub fn remove_triggers_for_map(&mut self, map_id: &str)
pub fn remove_triggers_for_map(&mut self, map_id: &str)
Removes all triggers associated with map_id.
Sourcepub fn reset_fired_for_map(&mut self, map_id: &str)
pub fn reset_fired_for_map(&mut self, map_id: &str)
Resets the fired flag for every trigger on the
given map, allowing one-shot triggers to fire again (e.g. after the
player re-enters the map).
Sourcepub fn all_triggers(&self) -> impl Iterator<Item = &Trigger>
pub fn all_triggers(&self) -> impl Iterator<Item = &Trigger>
Returns an iterator over all registered triggers (regardless of map).
Sourcepub fn check_triggers(
&mut self,
map_id: &str,
player_x: u32,
player_y: u32,
) -> Vec<String>
pub fn check_triggers( &mut self, map_id: &str, player_x: u32, player_y: u32, ) -> Vec<String>
Checks all triggers for the given map against the player’s current
position. Handles OnStep and
OnEnter triggers.
Returns the script_name of every trigger
that should fire this frame. Callers should iterate the returned
list and invoke each function on the script engine.
One-shot triggers are automatically marked as fired so they won’t
activate again until reset_fired_for_map
is called.
§OnEnter vs OnStep
- OnEnter — fires when the player was not in the area last frame but is this frame (entry detection).
- OnStep — fires every frame the player stands inside the area.
Sourcepub fn check_interact(
&self,
map_id: &str,
facing_x: u32,
facing_y: u32,
) -> Option<&str>
pub fn check_interact( &self, map_id: &str, facing_x: u32, facing_y: u32, ) -> Option<&str>
Checks for OnInteract triggers at the tile
the player is facing. Returns the script name if one is found.
This is a read-only query — it does not mark one-shot triggers
as fired. Use check_interact_mut when
you also want to disable the trigger after activation.
Sourcepub fn check_interact_mut(
&mut self,
map_id: &str,
facing_x: u32,
facing_y: u32,
) -> Option<String>
pub fn check_interact_mut( &mut self, map_id: &str, facing_x: u32, facing_y: u32, ) -> Option<String>
Checks for OnInteract triggers at the tile
the player is facing. Returns the script name and marks the trigger as
fired (so one-shot triggers won’t activate again).
Trait Implementations§
Source§impl Clone for TriggerManager
impl Clone for TriggerManager
Source§fn clone(&self) -> TriggerManager
fn clone(&self) -> TriggerManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more