Skip to content

Commit

Permalink
feat(api): rename attach and hide it from docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Jan 15, 2022
1 parent 8bed75b commit 6c64df4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
13 changes: 6 additions & 7 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ pub trait ActionBuilder: std::fmt::Debug + Send + Sync {
*/
fn build(&self, cmd: &mut Commands, action: Entity, actor: Entity);

/**
Don't implement this yourself unless you know what you're doing.
*/
fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity {
#[doc(hidden)]
// Don't implement this yourself unless you know what you're doing.
fn spawn_action(&self, cmd: &mut Commands, actor: Entity) -> Entity {
let action_ent = ActionEnt(cmd.spawn().id());
cmd.entity(action_ent.0)
.insert(Name::new("Action"))
Expand Down Expand Up @@ -131,7 +130,7 @@ impl StepsBuilder {
impl ActionBuilder for StepsBuilder {
fn build(&self, cmd: &mut Commands, action: Entity, actor: Entity) {
if let Some(step) = self.steps.get(0) {
let child_action = step.attach(cmd, actor);
let child_action = step.spawn_action(cmd, actor);
cmd.entity(action)
.insert(Name::new("Steps Action"))
.insert(Steps {
Expand Down Expand Up @@ -223,7 +222,7 @@ pub fn steps_system(

steps_action.active_step += 1;
let step_builder = steps_action.steps[steps_action.active_step].clone();
let step_ent = step_builder.attach(&mut cmd, *actor);
let step_ent = step_builder.spawn_action(&mut cmd, *actor);
cmd.entity(seq_ent).push_children(&[step_ent]);
steps_action.active_ent.0 = step_ent;
}
Expand Down Expand Up @@ -268,7 +267,7 @@ impl ActionBuilder for ConcurrentlyBuilder {
let children: Vec<Entity> = self
.actions
.iter()
.map(|action| action.attach(cmd, actor))
.map(|action| action.spawn_action(cmd, actor))
.collect();
cmd.entity(action)
.insert(Name::new("Concurrent Action"))
Expand Down
2 changes: 1 addition & 1 deletion src/choices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl ChoiceBuilder {
}

pub fn build(&self, cmd: &mut Commands, actor: Entity, parent: Entity) -> Choice {
let scorer_ent = self.when.attach(cmd, actor);
let scorer_ent = self.when.spawn_scorer(cmd, actor);
cmd.entity(parent).push_children(&[scorer_ent]);
Choice {
scorer: ScorerEnt(scorer_ent),
Expand Down
15 changes: 7 additions & 8 deletions src/scorers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ pub trait ScorerBuilder: std::fmt::Debug + Sync + Send {
*/
fn build(&self, cmd: &mut Commands, scorer: Entity, actor: Entity);

/**
Don't implement this yourself unless you know what you're doing.
*/
fn attach(&self, cmd: &mut Commands, actor: Entity) -> Entity {
// Don't implement this yourself unless you know what you're doing.
#[doc(hidden)]
fn spawn_scorer(&self, cmd: &mut Commands, actor: Entity) -> Entity {
let scorer_ent = cmd.spawn().id();
cmd.entity(scorer_ent)
.insert(Name::new("Scorer"))
Expand Down Expand Up @@ -186,7 +185,7 @@ impl ScorerBuilder for AllOrNothingBuilder {
let scorers: Vec<_> = self
.scorers
.iter()
.map(|scorer| scorer.attach(cmd, actor))
.map(|scorer| scorer.spawn_scorer(cmd, actor))
.collect();
cmd.entity(scorer)
.insert(Score::default())
Expand Down Expand Up @@ -269,7 +268,7 @@ impl ScorerBuilder for SumOfScorersBuilder {
let scorers: Vec<_> = self
.scorers
.iter()
.map(|scorer| scorer.attach(cmd, actor))
.map(|scorer| scorer.spawn_scorer(cmd, actor))
.collect();
cmd.entity(scorer)
.insert(Transform::default())
Expand Down Expand Up @@ -360,7 +359,7 @@ impl ScorerBuilder for WinningScorerBuilder {
let scorers: Vec<_> = self
.scorers
.iter()
.map(|scorer| scorer.attach(cmd, actor))
.map(|scorer| scorer.spawn_scorer(cmd, actor))
.collect();
cmd.entity(scorer)
.insert(Transform::default())
Expand Down Expand Up @@ -431,7 +430,7 @@ pub struct EvaluatingScorerBuilder {

impl ScorerBuilder for EvaluatingScorerBuilder {
fn build(&self, cmd: &mut Commands, scorer: Entity, actor: Entity) {
let inner_scorer = self.scorer.attach(cmd, actor);
let inner_scorer = self.scorer.spawn_scorer(cmd, actor);
cmd.entity(scorer)
.insert(Transform::default())
.insert(GlobalTransform::default())
Expand Down
6 changes: 3 additions & 3 deletions src/thinker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn thinker_component_attach_system(
q: Query<(Entity, &ThinkerBuilder), Without<HasThinker>>,
) {
for (entity, thinker_builder) in q.iter() {
let thinker = thinker_builder.attach(&mut cmd, entity);
let thinker = thinker_builder.spawn_action(&mut cmd, entity);
cmd.entity(entity).insert(HasThinker(thinker));
}
}
Expand Down Expand Up @@ -305,7 +305,7 @@ fn exec_picked_action(
// Despawn the action itself.
cmd.entity(action_ent.0).despawn_recursive();
thinker.current_action = Some((
ActionEnt(picked_action.1.attach(cmd, actor)),
ActionEnt(picked_action.1.spawn_action(cmd, actor)),
picked_action.clone(),
));
}
Expand All @@ -326,7 +326,7 @@ fn exec_picked_action(
// current_action in the thinker. The logic here is pretty
// straightforward -- we set the action, Request it, and
// that's it.
let new_action = picked_action.1.attach(cmd, actor);
let new_action = picked_action.1.spawn_action(cmd, actor);
thinker.current_action = Some((ActionEnt(new_action), picked_action.clone()));
}
}

0 comments on commit 6c64df4

Please sign in to comment.