diff --git a/src/control/mod.rs b/src/control/mod.rs index b5f87c3..052427f 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -1,6 +1,10 @@ use bevy::prelude::*; -use crate::GameState; +use crate::{ + GameState, + head::ActiveHead, + heads_database::{HeadControls, HeadsDatabase}, +}; mod collisions; pub mod controller_common; @@ -48,10 +52,6 @@ pub fn plugin(app: &mut App) { app.add_event::(); - app.add_systems( - Update, - switch_controller.before(ControllerSet::CollectInputs), - ); app.configure_sets( Update, ( @@ -66,20 +66,24 @@ pub fn plugin(app: &mut App) { .chain() .run_if(in_state(GameState::Playing)), ); + + app.add_systems(Update, head_change.run_if(in_state(GameState::Playing))); } -fn switch_controller( +fn head_change( + query: Query<&ActiveHead, Changed>, + heads_db: Res, mut selected_controller: ResMut, - keyboard: Res>, - mut event_controller_switch: EventWriter, ) { - if keyboard.just_pressed(KeyCode::KeyF) { - event_controller_switch.send(ControllerSwitchEvent); + for head in query.iter() { + let stats = heads_db.head_stats(head.0); + let controller = match stats.controls { + HeadControls::Plane => ControllerSet::ApplyControlsFly, + HeadControls::Walk => ControllerSet::ApplyControlsRun, + }; - if selected_controller.0 == ControllerSet::ApplyControlsFly { - selected_controller.0 = ControllerSet::ApplyControlsRun; - } else { - selected_controller.0 = ControllerSet::ApplyControlsFly; + if selected_controller.0 != controller { + selected_controller.0 = controller; } } }