Skip to main content

Behavior

Trait Behavior 

Source
pub trait Behavior {
    // Required method
    fn on_interact(&mut self, event: &InteractEvent) -> Vec<Action>;

    // Provided methods
    fn on_load(&mut self) { ... }
    fn on_tick(&mut self, _dt_ms: i32) { ... }
    fn on_event(&mut self, _event: &Value) -> Vec<Action> { ... }
}
Expand description

One instantiated behavior module (a WASM instance, or a plain-Rust one in tests). The browser owns a Behavior per manifest behavior id and dispatches events to it, then performs the Actions it returns.

Required Methods§

Source

fn on_interact(&mut self, event: &InteractEvent) -> Vec<Action>

A player interacted with a bound placement → the effects to perform.

Provided Methods§

Source

fn on_load(&mut self)

Called once after instantiation.

Source

fn on_tick(&mut self, _dt_ms: i32)

A per-frame tick, if the behavior declared "tick" in its on[].

Source

fn on_event(&mut self, _event: &Value) -> Vec<Action>

An asynchronous reply (purchase_result, codex_ready, presence, …).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§