From 64f38ce8756c40b28ce73cc14613a27ec734a8e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kat=20March=C3=A1n?= <kzm@zkat.tech>
Date: Thu, 22 Apr 2021 19:41:34 -0700
Subject: [PATCH] name things and fix steps

---
 src/actions.rs | 24 ++++++++++++------------
 src/lib.rs     |  2 +-
 src/scorers.rs |  6 ++----
 src/thinker.rs |  3 +--
 4 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/src/actions.rs b/src/actions.rs
index c799eb1..2dd5f82 100644
--- a/src/actions.rs
+++ b/src/actions.rs
@@ -92,8 +92,7 @@ pub trait ActionBuilder: std::fmt::Debug + Send + Sync {
     fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity {
         let action_ent = ActionEnt(cmd.spawn().id());
         cmd.entity(action_ent.0)
-            .insert(Transform::default())
-            .insert(GlobalTransform::default())
+            .insert(Name::new("Action"))
             .insert(ActionState::new())
             .insert(Actor(actor));
         self.build(cmd, action_ent.0, actor);
@@ -121,16 +120,17 @@ impl StepsBuilder {
 
 impl ActionBuilder for StepsBuilder {
     fn build(&self, cmd: &mut Commands, action: Entity, actor: Entity) {
-        let child_action = self.steps[0].attach(cmd, actor);
-        cmd.entity(action)
-            .insert(Transform::default())
-            .insert(GlobalTransform::default())
-            .insert(Steps {
-                active_step: 0,
-                active_ent: ActionEnt(child_action),
-                steps: self.steps.clone(),
-            })
-            .push_children(&[child_action]);
+        if let Some(step) = self.steps.get(0) {
+            let child_action = step.attach(cmd, actor);
+            cmd.entity(action)
+                .insert(Name::new("Steps Action"))
+                .insert(Steps {
+                    active_step: 0,
+                    active_ent: ActionEnt(child_action),
+                    steps: self.steps.clone(),
+                })
+                .push_children(&[child_action]);
+        }
     }
 }
 
diff --git a/src/lib.rs b/src/lib.rs
index 3d64358..17e7c3f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -163,7 +163,7 @@ pub mod prelude {
     use super::*;
 
     pub use super::BigBrainPlugin;
-    pub use actions::{ActionBuilder, ActionState};
+    pub use actions::{ActionBuilder, ActionState, Steps};
     pub use pickers::{FirstToScore, Picker};
     pub use scorers::{AllOrNothing, FixedScore, Score, ScorerBuilder, SumOfScorers};
     pub use thinker::{Actor, Thinker, ThinkerBuilder};
diff --git a/src/scorers.rs b/src/scorers.rs
index 3993ec9..ba098f8 100644
--- a/src/scorers.rs
+++ b/src/scorers.rs
@@ -66,8 +66,7 @@ pub trait ScorerBuilder: std::fmt::Debug + Sync + Send {
     fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity {
         let scorer_ent = cmd.spawn().id();
         cmd.entity(scorer_ent)
-            .insert(Transform::default())
-            .insert(GlobalTransform::default())
+            .insert(Name::new("Scorer"))
             .insert(Score::default())
             .insert(Actor(actor));
         self.build(cmd, scorer_ent, actor);
@@ -178,10 +177,9 @@ impl ScorerBuilder for AllOrNothingBuilder {
             .map(|scorer| scorer.attach(cmd, actor))
             .collect();
         cmd.entity(scorer)
-            .insert(Transform::default())
-            .insert(GlobalTransform::default())
             .insert(Score::default())
             .push_children(&scorers[..])
+            .insert(Name::new("Scorer"))
             .insert(AllOrNothing {
                 threshold: self.threshold,
                 scorers: scorers.into_iter().map(ScorerEnt).collect(),
diff --git a/src/thinker.rs b/src/thinker.rs
index 68faa4b..b60286b 100644
--- a/src/thinker.rs
+++ b/src/thinker.rs
@@ -124,8 +124,6 @@ impl ActionBuilder for ThinkerBuilder {
             .map(|choice| choice.build(cmd, actor, action_ent))
             .collect();
         cmd.entity(action_ent)
-            .insert(Transform::default())
-            .insert(GlobalTransform::default())
             .insert(Thinker {
                 // TODO: reasonable default?...
                 picker: self
@@ -136,6 +134,7 @@ impl ActionBuilder for ThinkerBuilder {
                 otherwise: self.otherwise.clone(),
                 current_action: None,
             })
+            .insert(Name::new("Thinker"))
             .insert(ActiveThinker(false))
             .insert(ActionState::Requested);
     }
-- 
GitLab