Skip to content
Snippets Groups Projects
Unverified Commit db16e2f6 authored by Kat Marchán's avatar Kat Marchán
Browse files

fix(thinker): stop using the child/parent system for toplevel thinkers

parent 440aff7d
No related branches found
No related tags found
No related merge requests found
...@@ -194,6 +194,7 @@ impl Plugin for BigBrainPlugin { ...@@ -194,6 +194,7 @@ impl Plugin for BigBrainPlugin {
app.add_system(thinker::thinker_system.system()); app.add_system(thinker::thinker_system.system());
app.add_system(thinker::thinker_component_attach_system.system()); app.add_system(thinker::thinker_component_attach_system.system());
app.add_system(thinker::thinker_component_detach_system.system()); app.add_system(thinker::thinker_component_detach_system.system());
app.add_system(thinker::actor_gone_cleanup.system());
app.add_system(actions::steps_system.system()); app.add_system(actions::steps_system.system());
app.add_system(scorers::fixed_score_system.system()); app.add_system(scorers::fixed_score_system.system());
app.add_system(scorers::all_or_nothing_system.system()); app.add_system(scorers::all_or_nothing_system.system());
......
...@@ -147,9 +147,7 @@ pub fn thinker_component_attach_system( ...@@ -147,9 +147,7 @@ pub fn thinker_component_attach_system(
) { ) {
for (entity, thinker_builder) in q.iter() { for (entity, thinker_builder) in q.iter() {
let thinker = thinker_builder.attach(&mut cmd, entity); let thinker = thinker_builder.attach(&mut cmd, entity);
cmd.entity(entity) cmd.entity(entity).insert(HasThinker(thinker));
.insert(HasThinker(thinker))
.push_children(&[thinker]);
} }
} }
...@@ -163,6 +161,19 @@ pub fn thinker_component_detach_system( ...@@ -163,6 +161,19 @@ pub fn thinker_component_detach_system(
} }
} }
pub fn actor_gone_cleanup(
mut cmd: Commands,
actors: Query<&ThinkerBuilder>,
q: Query<(Entity, &Actor)>,
) {
for (child, Actor(actor)) in q.iter() {
if actors.get(*actor).is_err() {
// Actor is gone. Let's clean up.
cmd.entity(child).despawn_recursive();
}
}
}
#[derive(Debug)] #[derive(Debug)]
pub struct HasThinker(Entity); pub struct HasThinker(Entity);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment