diff --git a/game/src/in_game.rs b/game/src/in_game.rs index c05b81e..fbd5647 100644 --- a/game/src/in_game.rs +++ b/game/src/in_game.rs @@ -9,7 +9,10 @@ impl Plugin for InGamePlugin { fn build(&self, app: &mut App) { app.add_plugins(DefaultPickingPlugins) .add_systems(OnEnter(GameState::InGame), (setup, draw_hud)) - .add_systems(Update, (apply_seelected, click_on_ground)); + .add_systems( + Update, + (apply_seelected, click_on_ground, process_user_commands), + ); } } @@ -69,6 +72,7 @@ fn setup( max: 5.0, current: (i + 2) as f32, }, + UserCommands(Vec::new()), )); } } @@ -108,6 +112,9 @@ struct Ground; #[derive(Component)] struct HealthVis; +#[derive(Component)] +struct UserCommands(Vec); + #[derive(Component)] struct Health { max: f32, @@ -136,9 +143,39 @@ fn apply_seelected( } } -fn click_on_ground(ev: EventReader>) { - let len = ev.len(); - if len != 0 { - println!("event len: {len}",); +fn click_on_ground( + grounds: Query>, + mut ev: EventReader>, + mut selecteds: Query<(&mut UserCommands, &PickSelection)>, +) { + if !ev.is_empty() { + if let Some(ground) = grounds.iter().next() { + for e in &mut ev { + if e.target == ground { + match e.button { + PointerButton::Primary => {} + PointerButton::Secondary => { + for (mut selected, selection) in &mut selecteds { + if !selection.is_selected { + continue; + } + selected.0.push(e.hit.position.unwrap()); + } + } + PointerButton::Middle => {} + } + } + } + } + } +} + +fn process_user_commands(mut actions: Query<(&mut Transform, &mut UserCommands)>) { + for (mut trans, mut comms) in &mut actions { + if comms.0.is_empty() { + continue; + } + trans.translation = comms.0[0]; + comms.0.clear(); } } diff --git a/game/src/main.rs b/game/src/main.rs index c54133f..de21094 100644 --- a/game/src/main.rs +++ b/game/src/main.rs @@ -8,7 +8,7 @@ fn main() { App::new() .add_plugins(( DefaultPlugins, - BasePlugin::new(GameState::MainMenu), + BasePlugin::new(GameState::InGame), MainMenuPlugin, SettingsPlugin, InGamePlugin,