Skip to content

Commit

Permalink
feat(builders): Blanket impls for ActionBuilder and ScorerBuilder whe…
Browse files Browse the repository at this point in the history
…n Clone

This will make a lot of simpler actions and scorers much less boilerplatey
  • Loading branch information
zkat committed Jan 15, 2022
1 parent 65ca646 commit 8bed75b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ pub trait ActionBuilder: std::fmt::Debug + Send + Sync {
}
}

impl<T> ActionBuilder for T
where
T: Component + Clone + std::fmt::Debug + Send + Sync,
{
fn build(&self, cmd: &mut Commands, action: Entity, _actor: Entity) {
cmd.entity(action).insert(T::clone(self));
}
}

/**
[`ActionBuilder`] for the [`Steps`] component. Constructed through `Steps::build()`.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/scorers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ pub trait ScorerBuilder: std::fmt::Debug + Sync + Send {
}
}

impl<T> ScorerBuilder for T
where
T: Component + Clone + std::fmt::Debug + Send + Sync,
{
fn build(&self, cmd: &mut Commands, action: Entity, _actor: Entity) {
cmd.entity(action).insert(T::clone(self));
}
}

/**
Scorer that always returns the same, fixed score. Good for combining with things creatively!
*/
Expand Down

0 comments on commit 8bed75b

Please sign in to comment.