Trait big_brain::scorers::ScorerBuilder
source · 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 ScorerBuilder
s.
ScorerBuilder
s’ 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 ScorerBuilder
s you want
to define.
Required Methods§
sourcefn build(&self, cmd: &mut Commands<'_, '_>, scorer: Entity, actor: Entity)
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 a
ScorerBuilder`
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);
}
}