Skip to content
Snippets Groups Projects
choices.rs 872 B
Newer Older
use bevy::prelude::*;
Kat Marchán's avatar
Kat Marchán committed
use serde::Deserialize;

use crate::{
    actions::{Action, ActionState},
    scorers::{Scorer, Score},
    thinker::{ActionEnt, ScorerEnt},
Kat Marchán's avatar
Kat Marchán committed
};

// Contains different types of Considerations and Actions
#[derive(Debug)]
pub struct Choice {
    pub scorer: ScorerEnt,
Kat Marchán's avatar
Kat Marchán committed
    pub action_state: ActionEnt,
}
impl Choice {
    pub fn calculate(&self, scores: &Query<&Score>) -> f32 {
        scores.get(self.scorer.0).expect("Where did the score go?").0
Kat Marchán's avatar
Kat Marchán committed
    }
}

#[derive(Debug, Deserialize)]
pub struct ChoiceBuilder {
    pub when: Box<dyn Scorer>,
Kat Marchán's avatar
Kat Marchán committed
    pub then: Box<dyn Action>,
}
impl ChoiceBuilder {
    pub fn build(self, actor: Entity, cmd: &mut Commands) -> Choice {
Kat Marchán's avatar
Kat Marchán committed
        let action = self.then;
        Choice {
            scorer: self.when.build(actor, cmd),
            action_state: ActionState::build(action, actor, cmd),