use heads db to choose movement controls
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::GameState;
|
use crate::{
|
||||||
|
GameState,
|
||||||
|
head::ActiveHead,
|
||||||
|
heads_database::{HeadControls, HeadsDatabase},
|
||||||
|
};
|
||||||
|
|
||||||
mod collisions;
|
mod collisions;
|
||||||
pub mod controller_common;
|
pub mod controller_common;
|
||||||
@@ -48,10 +52,6 @@ pub fn plugin(app: &mut App) {
|
|||||||
|
|
||||||
app.add_event::<ControllerSwitchEvent>();
|
app.add_event::<ControllerSwitchEvent>();
|
||||||
|
|
||||||
app.add_systems(
|
|
||||||
Update,
|
|
||||||
switch_controller.before(ControllerSet::CollectInputs),
|
|
||||||
);
|
|
||||||
app.configure_sets(
|
app.configure_sets(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
@@ -66,20 +66,24 @@ pub fn plugin(app: &mut App) {
|
|||||||
.chain()
|
.chain()
|
||||||
.run_if(in_state(GameState::Playing)),
|
.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<ActiveHead>>,
|
||||||
|
heads_db: Res<HeadsDatabase>,
|
||||||
mut selected_controller: ResMut<SelectedController>,
|
mut selected_controller: ResMut<SelectedController>,
|
||||||
keyboard: Res<ButtonInput<KeyCode>>,
|
|
||||||
mut event_controller_switch: EventWriter<ControllerSwitchEvent>,
|
|
||||||
) {
|
) {
|
||||||
if keyboard.just_pressed(KeyCode::KeyF) {
|
for head in query.iter() {
|
||||||
event_controller_switch.send(ControllerSwitchEvent);
|
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 {
|
if selected_controller.0 != controller {
|
||||||
selected_controller.0 = ControllerSet::ApplyControlsRun;
|
selected_controller.0 = controller;
|
||||||
} else {
|
|
||||||
selected_controller.0 = ControllerSet::ApplyControlsFly;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user