From 6c0ac7f66d6f62c3de01409297086b05b67ec875 Mon Sep 17 00:00:00 2001 From: Jim Date: Mon, 1 Sep 2025 12:08:39 -0400 Subject: [PATCH] phase -> execute loop --- Cargo.lock | 2 + assets/settings/input_map.ron | 16 +-- crates/level/Cargo.toml | 1 + crates/level/src/lib.rs | 55 +++++++++- crates/state/src/lib.rs | 43 +++++++- crates/ui_ingame/Cargo.toml | 1 + crates/ui_ingame/src/lib.rs | 190 ++++++++++++++++++++++++++++++---- 7 files changed, 273 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8843ef1..457e035 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -3195,6 +3195,7 @@ dependencies = [ "building", "camera", "combat", + "inhabitant", "inhabitant_coranth", "physics", "resource_graveyard", @@ -5298,6 +5299,7 @@ dependencies = [ "building_placement", "input", "resources", + "state", "ui_state", "upgrade", ] diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index ed21f50..b82ce27 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -3,20 +3,20 @@ MouseButton(Middle): [ CameraOrbitEnable, ], - MouseButton(Right): [ - PlaceTower, - ], - MouseButton(Left): [ - CameraPanEnable, - ], KeyCode(ShiftLeft): [ MultiPlaceTower, ], + KeyCode(F1): [ + ToggleDebugUI, + ], + MouseButton(Right): [ + PlaceTower, + ], MouseScroll: [ CameraZoom, ], - KeyCode(F1): [ - ToggleDebugUI, + MouseButton(Left): [ + CameraPanEnable, ], MouseMovementX: [ CameraYaw, diff --git a/crates/level/Cargo.toml b/crates/level/Cargo.toml index 9d7d651..9734351 100755 --- a/crates/level/Cargo.toml +++ b/crates/level/Cargo.toml @@ -13,6 +13,7 @@ camera = { path = "../camera" } combat = { path = "../combat" } physics = { path = "../physics" } building = { path = "../building" } +inhabitant = { path = "../inhabitant" } inhabitant_coranth = { path = "../inhabitant_coranth" } resource_graveyard = { path = "../resource_graveyard" } diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index 7c1b0ee..c0fa77e 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -14,20 +14,42 @@ use bevy::{ use bevy_egui::PrimaryEguiContext; use building::{BuildingTypes, PlaceBuilding}; use camera::ControlledCamera; +use inhabitant::Inhabitant; use inhabitant_coranth::SpawnCoranth; use physics::{Ground, PhysicsLayers}; use resource_graveyard::PlaceGraveyard; -use state::{AppState, GameSystemSet}; +use state::{AppState, BasePhaseState, GameSystemSet, Phase}; pub struct LevelPlugin; impl Plugin for LevelPlugin { fn build(&self, app: &mut App) { - app.add_systems(OnEnter(AppState::Game), setup) - .add_systems(FixedUpdate, spawn_enemies.in_set(GameSystemSet::Execute)); + app.init_resource::() + .add_systems(OnEnter(AppState::Game), setup) + .add_systems( + OnTransition { + exited: Phase::Execute, + entered: Phase::Plan, + }, + on_plan, + ) + .add_systems( + OnTransition { + exited: Phase::Plan, + entered: Phase::Execute, + }, + on_execute, + ) + .add_systems( + FixedUpdate, + (spawn_enemies, tick_execute_timer).in_set(GameSystemSet::Execute), + ); } } +#[derive(Resource, Default, Deref, DerefMut)] +pub struct ExecuteTimer(pub Option); + fn setup( mut commands: Commands, mut meshes: ResMut>, @@ -123,3 +145,30 @@ fn spawn_enemies( } } } + +fn on_execute(mut timer: ResMut) { + timer.0 = Some(Timer::from_seconds(5., TimerMode::Once)); +} + +fn tick_execute_timer( + mut execute_timer: ResMut, + time: Res