Trait big_brain::actions::ActionBuilder
source · pub trait ActionBuilder: Debug + Send + Sync {
fn build(&self, cmd: &mut Commands<'_, '_>, action: Entity, actor: Entity);
fn label(&self) -> Option<&str> { ... }
}
Expand description
Trait that must be defined by types in order to be ActionBuilder
s.
ActionBuilder
s’ job is to spawn new Action
entities on demand. In
general, most of this is already done for you, and the only method you
really have to implement is .build()
.
The build()
method MUST be implemented for any ActionBuilder
s you want
to define.
Required Methods§
sourcefn build(&self, cmd: &mut Commands<'_, '_>, action: Entity, actor: Entity)
fn build(&self, cmd: &mut Commands<'_, '_>, action: Entity, actor: Entity)
MUST insert your concrete Action component into the Scorer [Entity
],
using cmd
. You may use actor
, but it’s perfectly normal to just
ignore it.
In most cases, your ActionBuilder
and Action
can be the same type.
The only requirement is that your struct implements Debug
,
Component,
Clone. You can then use the derive macro
ActionBuilderto turn your struct into a
ActionBuilder`
Example
Using the derive macro (the easy way):
#[derive(Debug, Clone, Component, ActionBuilder)]
#[action_label = "MyActionLabel"] // Optional. Defaults to type name.
struct MyAction;
Implementing it manually:
#[derive(Debug)]
struct MyBuilder;
#[derive(Debug, Component)]
struct MyAction;
impl ActionBuilder for MyBuilder {
fn build(&self, cmd: &mut Commands, action: Entity, actor: Entity) {
cmd.entity(action).insert(MyAction);
}
}