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

fix(thinker): add Transform and GlobalTransform

This is... ridiculous, but it happend to be required by the
Bevy Parenting system. Without this, the Thinker will be randomly
removed from the hierarchy :(
parent 10a6d022
No related branches found
No related tags found
No related merge requests found
......@@ -92,6 +92,8 @@ 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(ActionState::new())
.insert(Actor(actor));
self.build(cmd, action_ent.0, actor);
......@@ -121,6 +123,8 @@ 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),
......
......@@ -38,9 +38,9 @@ impl FirstToScore {
}
impl Picker for FirstToScore {
fn pick(&self, choices: &[Choice], utilities: &Query<&Score>) -> Option<Choice> {
fn pick(&self, choices: &[Choice], scores: &Query<&Score>) -> Option<Choice> {
for choice in choices {
let value = choice.calculate(utilities);
let value = choice.calculate(scores);
if value >= self.threshold {
return Some(choice.clone());
}
......
......@@ -66,6 +66,8 @@ 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(Score::default())
.insert(Actor(actor));
self.build(cmd, scorer_ent, actor);
......@@ -176,6 +178,8 @@ 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(AllOrNothing {
......@@ -256,7 +260,10 @@ impl ScorerBuilder for SumOfScorersBuilder {
.iter()
.map(|scorer| scorer.attach(cmd, actor))
.collect();
cmd.entity(scorer).insert(AllOrNothing {
cmd.entity(scorer)
.insert(Transform::default())
.insert(GlobalTransform::default())
.insert(AllOrNothing {
threshold: self.threshold,
scorers: scorers.into_iter().map(ScorerEnt).collect(),
});
......
......@@ -118,13 +118,14 @@ impl ThinkerBuilder {
impl ActionBuilder for ThinkerBuilder {
fn build(&self, cmd: &mut Commands, action_ent: Entity, actor: Entity) {
println!("building thinker");
let choices = self
.choices
.iter()
.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
......@@ -190,7 +191,7 @@ pub fn thinker_system(
mut cmd: Commands,
mut iterations: Local<ThinkerIterations>,
mut thinker_q: Query<(Entity, &Actor, &mut Thinker, &ActiveThinker)>,
utilities: Query<&Score>,
scores: Query<&Score>,
mut action_states: Query<&mut actions::ActionState>,
) {
let start = Instant::now();
......@@ -229,7 +230,7 @@ pub fn thinker_system(
}
}
ActionState::Requested | ActionState::Executing => {
if let Some(choice) = thinker.picker.pick(&thinker.choices, &utilities) {
if let Some(choice) = thinker.picker.pick(&thinker.choices, &scores) {
// Think about what action we're supposed to be taking. We do this
// every tick, because we might change our mind.
// ...and then execute it (details below).
......
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