diff --git a/Cargo.lock b/Cargo.lock index bc931ef..da17a5a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1101,6 +1101,25 @@ dependencies = [ "winit", ] +[[package]] +name = "big-brain" +version = "0.18.0" +source = "git+https://github.com/PlagueAutomata/big-brain?rev=aed238e#aed238e65625a22816441351f9755854db661365" +dependencies = [ + "bevy", + "big-brain-derive", +] + +[[package]] +name = "big-brain-derive" +version = "0.18.0" +source = "git+https://github.com/PlagueAutomata/big-brain?rev=aed238e#aed238e65625a22816441351f9755854db661365" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.43", +] + [[package]] name = "bindgen" version = "0.69.1" @@ -2357,6 +2376,7 @@ version = "0.1.0" dependencies = [ "bevy", "bevy_egui", + "big-brain", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a9ef53b..987cb7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,4 @@ bevy = { version = "0.12.1", features = [ "wayland", ] } bevy_egui = "0.24" +big-brain = { git = "https://github.com/PlagueAutomata/big-brain", rev = "aed238e" } diff --git a/src/character.rs b/src/character.rs index 99d4291..0704aa7 100644 --- a/src/character.rs +++ b/src/character.rs @@ -1,64 +1,59 @@ +use crate::mechanics::*; use crate::{game_state::GameState, selectable::Selectable}; use bevy::prelude::*; +use big_brain::prelude::*; + +mod inventory; +mod movement; + +pub use self::{ + inventory::Inventory, + movement::{CachedFinder, FindAndMove}, +}; + +pub const DEFAULT_COLOR: Color = Color::BLACK; +pub const SLEEP_COLOR: Color = Color::BLUE; +pub const FARM_COLOR: Color = Color::YELLOW; pub struct CharacterPlugin; impl Plugin for CharacterPlugin { fn build(&self, app: &mut App) { - app.add_event::() + app.add_plugins((BigBrainPlugin::new(PreUpdate),)) + .add_event::() .add_systems(PreUpdate, spawner_system) .add_systems( Update, - (read_target_position, move_character) - .chain() - .run_if(in_state(GameState::Playing)), + sync_character_color.run_if(in_state(GameState::Playing)), ); } } #[derive(Component)] pub struct CharacterController { - pub target: Option, - pub velocity: Vec3, pub speed: f32, + pub color: Color, + pub is_sleeping: bool, } -#[derive(Component)] -pub struct MovementTarget(pub Entity); - -pub fn read_target_position( - transforms: TransformHelper, - mut query: Query<(&mut CharacterController, &MovementTarget)>, -) { - for (mut ctrl, &MovementTarget(target)) in query.iter_mut() { - ctrl.target = transforms - .compute_global_transform(target) - .map(|transform| transform.translation()) - .ok(); - } -} - -pub fn move_character( - time: Res