pub trait ScorerBuilder: Debug + Sync + Send {
    fn build(&self, cmd: &mut Commands<'_, '_>, scorer: Entity, actor: Entity);

    fn label(&self) -> Option<&str> { ... }
}
Expand description

Trait that must be defined by types in order to be ScorerBuilders. ScorerBuilders’ job is to spawn new Scorer entities. 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 ScorerBuilders you want to define.

Required Methods§

source

fn build(&self, cmd: &mut Commands<'_, '_>, scorer: Entity, actor: Entity)

MUST insert your concrete Scorer component into the Scorer [Entity], using cmd. You may use actor, but it’s perfectly normal to just ignore it.

In most cases, your ScorerBuilder and Scorer can be the same type. The only requirement is that your struct implements Debug, Component, Clone. You can then use the derive macro ScorerBuilderto turn your struct into aScorerBuilder`

Example

Using the derive macro (the easy way):

#[derive(Debug, Clone, Component, ScorerBuilder)]
#[scorer_label = "MyScorerLabel"] // Optional. Defaults to type name.
struct MyScorer;

Implementing it manually:

#[derive(Debug)]
struct MyBuilder;
#[derive(Debug, Component)]
struct MyScorer;

impl ScorerBuilder for MyBuilder {
  fn build(&self, cmd: &mut Commands, scorer: Entity, _actor: Entity) {
    cmd.entity(scorer).insert(MyScorer);
  }
}

Provided Methods§

source

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

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

Implementors§