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 ActionBuilders. ActionBuilders’ 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 ActionBuilders you want to define.

Required Methods§

source

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 aActionBuilder`

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);
  }
}

Provided Methods§

source

fn label(&self) -> Option<&str>

  • A label to display when logging using the Action’s tracing span.

Implementors§