From 8bed75b54a43c72b53fbf9e2605b942cb2c53214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= <kzm@zkat.tech> Date: Fri, 14 Jan 2022 22:12:02 -0800 Subject: [PATCH] feat(builders): Blanket impls for ActionBuilder and ScorerBuilder when Clone This will make a lot of simpler actions and scorers much less boilerplatey --- src/actions.rs | 9 +++++++++ src/scorers.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/actions.rs b/src/actions.rs index 4a5dcb8..2f95cc4 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -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()`. */ diff --git a/src/scorers.rs b/src/scorers.rs index 8f2e682..0e58f14 100644 --- a/src/scorers.rs +++ b/src/scorers.rs @@ -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! */ -- GitLab