From fd2a5f093688b09a5567b97631aa7d4d2cd502e6 Mon Sep 17 00:00:00 2001 From: Hennadii Chernyshchyk Date: Thu, 12 Dec 2024 20:37:42 +0200 Subject: [PATCH] Remove lots They don't affect gameplay right now and need to be remade into new undo system. Will bring it back to life later. --- base/src/game_world/actor/task.rs | 47 ++--- base/src/game_world/actor/task/buy_lot.rs | 90 --------- base/src/game_world/city.rs | 6 +- base/src/game_world/city/lot.rs | 196 ------------------- base/src/game_world/city/lot/creating_lot.rs | 141 ------------- base/src/game_world/city/lot/moving_lot.rs | 169 ---------------- base/src/math.rs | 4 +- base/src/math/polygon.rs | 56 ------ ui/src/hud/city_hud.rs | 5 +- ui/src/hud/city_hud/lots_node.rs | 54 ----- 10 files changed, 23 insertions(+), 745 deletions(-) delete mode 100644 base/src/game_world/actor/task/buy_lot.rs delete mode 100644 base/src/game_world/city/lot.rs delete mode 100644 base/src/game_world/city/lot/creating_lot.rs delete mode 100644 base/src/game_world/city/lot/moving_lot.rs delete mode 100644 base/src/math/polygon.rs delete mode 100644 ui/src/hud/city_hud/lots_node.rs diff --git a/base/src/game_world/actor/task.rs b/base/src/game_world/actor/task.rs index c432e726..553ac4ea 100644 --- a/base/src/game_world/actor/task.rs +++ b/base/src/game_world/actor/task.rs @@ -1,4 +1,3 @@ -mod buy_lot; mod friendly; mod linked_task; mod move_here; @@ -27,7 +26,6 @@ use crate::{ picking::Clicked, }, }; -use buy_lot::BuyLotPlugin; use friendly::FriendlyPlugins; use linked_task::LinkedTaskPlugin; use move_here::MoveHerePlugin; @@ -36,31 +34,26 @@ pub(super) struct TaskPlugin; impl Plugin for TaskPlugin { fn build(&self, app: &mut App) { - app.add_plugins(( - BuyLotPlugin, - FriendlyPlugins, - LinkedTaskPlugin, - MoveHerePlugin, - )) - .register_type::() - .replicate::() - .observe(Self::list) - .add_client_event::(ChannelKind::Unordered) - .add_client_event_with( - ChannelKind::Unordered, - serialize_task_request, - deserialize_task_request, - ) - .add_systems( - PreUpdate, - (Self::request, Self::cancel) - .after(ClientSet::Receive) - .run_if(server_or_singleplayer), - ) - .add_systems( - PostUpdate, - (Self::despawn_cancelled, Self::activate_queued).run_if(server_or_singleplayer), - ); + app.add_plugins((FriendlyPlugins, LinkedTaskPlugin, MoveHerePlugin)) + .register_type::() + .replicate::() + .observe(Self::list) + .add_client_event::(ChannelKind::Unordered) + .add_client_event_with( + ChannelKind::Unordered, + serialize_task_request, + deserialize_task_request, + ) + .add_systems( + PreUpdate, + (Self::request, Self::cancel) + .after(ClientSet::Receive) + .run_if(server_or_singleplayer), + ) + .add_systems( + PostUpdate, + (Self::despawn_cancelled, Self::activate_queued).run_if(server_or_singleplayer), + ); } } diff --git a/base/src/game_world/actor/task/buy_lot.rs b/base/src/game_world/actor/task/buy_lot.rs deleted file mode 100644 index ac85ae14..00000000 --- a/base/src/game_world/actor/task/buy_lot.rs +++ /dev/null @@ -1,90 +0,0 @@ -use bevy::{ - ecs::entity::{EntityMapper, MapEntities}, - math::Vec3Swizzles, - prelude::*, -}; -use bevy_replicon::prelude::*; -use serde::{Deserialize, Serialize}; - -use super::{AvailableTasks, ListTasks, Task, TaskState}; -use crate::game_world::{ - actor::Actor, - city::{ - lot::{LotFamily, LotVertices}, - Ground, - }, -}; - -pub(super) struct BuyLotPlugin; - -impl Plugin for BuyLotPlugin { - fn build(&self, app: &mut App) { - app.register_type::() - .replicate::() - .observe(Self::add_to_list) - .add_systems(Update, Self::buy.run_if(server_or_singleplayer)); - } -} - -impl BuyLotPlugin { - fn add_to_list( - trigger: Trigger, - mut available_tasks: ResMut, - grounds: Query<(), With>, - lots: Query<(Entity, &LotVertices), Without>, - ) { - if grounds.get(trigger.entity()).is_ok() { - if let Some((lot_entity, _)) = lots - .iter() - .find(|(_, vertices)| vertices.contains_point(trigger.event().xz())) - { - available_tasks.add(BuyLot(lot_entity)); - } - } - } - - fn buy( - mut commands: Commands, - lots: Query<(), Without>, - actors: Query<&Actor>, - tasks: Query<(Entity, &Parent, &BuyLot, &TaskState), Changed>, - ) { - for (entity, parent, buy, &task_state) in &tasks { - if task_state == TaskState::Active { - let actor = actors - .get(**parent) - .expect("task should have assigned actors"); - if lots.get(buy.0).is_ok() { - commands - .entity(buy.0) - .insert(LotFamily(actor.family_entity)); - } else { - error!("`{buy:?}` from actor `{entity}` points to not a lot"); - } - commands.entity(entity).despawn(); - } - } - } -} - -#[derive(Clone, Component, Copy, Debug, Deserialize, Reflect, Serialize)] -#[reflect(Component)] -pub(crate) struct BuyLot(Entity); - -impl Task for BuyLot { - fn name(&self) -> &str { - "Buy lot" - } -} - -impl FromWorld for BuyLot { - fn from_world(_world: &mut World) -> Self { - Self(Entity::PLACEHOLDER) - } -} - -impl MapEntities for BuyLot { - fn map_entities(&mut self, entity_mapper: &mut T) { - self.0 = entity_mapper.map_entity(self.0); - } -} diff --git a/base/src/game_world/city.rs b/base/src/game_world/city.rs index ac90a98c..9836f1b2 100644 --- a/base/src/game_world/city.rs +++ b/base/src/game_world/city.rs @@ -1,4 +1,3 @@ -pub mod lot; pub mod road; use std::f32::consts::FRAC_PI_2; @@ -21,14 +20,13 @@ use crate::{ core::GameState, game_world::{actor::ACTOR_RADIUS, Layer}, }; -use lot::LotPlugin; use road::RoadPlugin; pub(super) struct CityPlugin; impl Plugin for CityPlugin { fn build(&self, app: &mut App) { - app.add_plugins((LotPlugin, RoadPlugin)) + app.add_plugins(RoadPlugin) .add_sub_state::() .enable_state_scoped_entities::() .register_type::() @@ -202,7 +200,6 @@ impl FromWorld for GroundMesh { pub enum CityMode { #[default] Objects, - Lots, Roads, } @@ -210,7 +207,6 @@ impl CityMode { pub fn glyph(self) -> &'static str { match self { Self::Objects => "🌳", - Self::Lots => "⬛", Self::Roads => "🚧", } } diff --git a/base/src/game_world/city/lot.rs b/base/src/game_world/city/lot.rs deleted file mode 100644 index 352dfde1..00000000 --- a/base/src/game_world/city/lot.rs +++ /dev/null @@ -1,196 +0,0 @@ -pub mod creating_lot; -pub mod moving_lot; - -use bevy::{ecs::entity::MapEntities, prelude::*}; -use bevy_replicon::prelude::*; -use serde::{Deserialize, Serialize}; -use strum::{Display, EnumIter}; - -use crate::{ - common_conditions::in_any_state, - game_world::{city::CityMode, WorldState}, - math::polygon::Polygon, -}; -use creating_lot::CreatingLotPlugin; -use moving_lot::MovingLotPlugin; - -pub(super) struct LotPlugin; - -impl Plugin for LotPlugin { - fn build(&self, app: &mut App) { - app.add_sub_state::() - .enable_state_scoped_entities::() - .add_plugins((CreatingLotPlugin, MovingLotPlugin)) - .register_type::() - .replicate::() - .add_mapped_client_event::(ChannelKind::Unordered) - .add_mapped_client_event::(ChannelKind::Ordered) - .add_mapped_client_event::(ChannelKind::Unordered) - .add_server_event::(ChannelKind::Unordered) - .add_systems( - PreUpdate, - (Self::create, Self::apply_movement, Self::delete) - .after(ServerSet::Receive) - .run_if(server_or_singleplayer), - ) - .add_systems( - PostUpdate, - Self::draw_lines.run_if(in_any_state([WorldState::City, WorldState::Family])), - ); - } -} - -impl LotPlugin { - fn draw_lines( - mut gizmos: Gizmos, - lots: Query<(&Parent, &LotVertices)>, - cities: Query<&GlobalTransform>, - ) { - for (parent, vertices) in &lots { - let transform = cities.get(**parent).unwrap(); - let points_iter = vertices - .iter() - .map(|vertex| Vec3::new(vertex.x, 0.0, vertex.y)) - .map(|point| transform.transform_point(point)); - gizmos.linestrip(points_iter, Color::WHITE); - } - } - - fn create( - mut commands: Commands, - mut create_events: EventReader>, - mut confirm_events: EventWriter>, - ) { - for FromClient { client_id, event } in create_events.read().cloned() { - info!("`{client_id:?}` creates lot"); - commands.entity(event.city_entity).with_children(|parent| { - parent.spawn(LotBundle::new(event.polygon)); - }); - confirm_events.send(ToClients { - mode: SendMode::Direct(client_id), - event: LotEventConfirmed, - }); - } - } - - fn apply_movement( - mut move_events: EventReader>, - mut confirm_events: EventWriter>, - mut lots: Query<&mut LotVertices>, - ) { - for FromClient { client_id, event } in move_events.read().copied() { - match lots.get_mut(event.entity) { - Ok(mut vertices) => { - info!("`{client_id:?}` moves lot `{:?}`", event.entity); - for vertex in vertices.iter_mut() { - *vertex += event.offset; - } - confirm_events.send(ToClients { - mode: SendMode::Direct(client_id), - event: LotEventConfirmed, - }); - } - Err(e) => error!("unable to apply lot movement: {e}"), - } - } - } - - fn delete( - mut commands: Commands, - mut delete_events: EventReader>, - mut confirm_events: EventWriter>, - ) { - for FromClient { client_id, event } in delete_events.read().copied() { - info!("`{client_id:?}` deletes lot `{:?}`", event.0); - commands.entity(event.0).despawn_recursive(); - confirm_events.send(ToClients { - mode: SendMode::Direct(client_id), - event: LotEventConfirmed, - }); - } - } -} - -#[derive( - Clone, Component, Copy, Debug, Default, Display, EnumIter, Eq, Hash, PartialEq, SubStates, -)] -#[source(CityMode = CityMode::Lots)] -pub enum LotTool { - #[default] - Create, - Move, -} - -impl LotTool { - pub fn glyph(self) -> &'static str { - match self { - Self::Create => "✏", - Self::Move => "↔", - } - } -} - -#[derive(Bundle)] -struct LotBundle { - vertices: LotVertices, - parent_sync: ParentSync, - replication: Replicated, -} - -impl LotBundle { - fn new(polygon: Polygon) -> Self { - Self { - vertices: LotVertices(polygon), - parent_sync: Default::default(), - replication: Replicated, - } - } -} - -#[derive(Clone, Component, Default, Deref, DerefMut, Deserialize, Reflect, Serialize)] -#[reflect(Component)] -pub(crate) struct LotVertices(Polygon); - -/// Contains a family entity that owns the lot. -#[derive(Component)] -#[allow(dead_code)] -pub(crate) struct LotFamily(pub(crate) Entity); - -#[derive(Clone, Deserialize, Event, Serialize)] -struct LotCreate { - polygon: Polygon, - city_entity: Entity, -} - -impl MapEntities for LotCreate { - fn map_entities(&mut self, entity_mapper: &mut T) { - self.city_entity = entity_mapper.map_entity(self.city_entity); - } -} - -#[derive(Clone, Copy, Deserialize, Event, Serialize)] -struct LotMove { - entity: Entity, - offset: Vec2, -} - -impl MapEntities for LotMove { - fn map_entities(&mut self, entity_mapper: &mut T) { - self.entity = entity_mapper.map_entity(self.entity); - } -} - -#[derive(Clone, Copy, Event, Deserialize, Serialize)] -struct LotDelete(Entity); - -impl MapEntities for LotDelete { - fn map_entities(&mut self, entity_mapper: &mut T) { - self.0 = entity_mapper.map_entity(self.0); - } -} - -#[derive(Deserialize, Event, Serialize)] -struct LotEventConfirmed; - -#[derive(Component)] -struct UnconfirmedLot; diff --git a/base/src/game_world/city/lot/creating_lot.rs b/base/src/game_world/city/lot/creating_lot.rs deleted file mode 100644 index e84489ec..00000000 --- a/base/src/game_world/city/lot/creating_lot.rs +++ /dev/null @@ -1,141 +0,0 @@ -use bevy::{math::Vec3Swizzles, prelude::*}; -use bevy_enhanced_input::prelude::*; - -use super::{LotCreate, LotTool, LotVertices, UnconfirmedLot}; -use crate::{ - common_conditions::observer_in_state, - game_world::{city::ActiveCity, picking::Clicked, player_camera::CameraCaster}, -}; - -pub(super) struct CreatingLotPlugin; - -impl Plugin for CreatingLotPlugin { - fn build(&self, app: &mut App) { - app.add_input_context::() - .observe(Self::start) - .observe(Self::cancel) - .observe(Self::confirm) - .add_systems( - Update, - Self::set_vertex_position.run_if(in_state(LotTool::Create)), - ); - } -} - -impl CreatingLotPlugin { - fn start( - trigger: Trigger, - lot_tool: Option>>, - mut commands: Commands, - cities: Query>, - ) { - if !observer_in_state(lot_tool, LotTool::Create) { - return; - } - - info!("starting placing lot"); - // Spawn with two the same vertices because we edit the last one on cursor movement. - commands.entity(cities.single()).with_children(|parent| { - parent.spawn(( - StateScoped(LotTool::Create), - LotVertices(vec![trigger.event().xz(); 2].into()), - CreatingLot, - )); - }); - } - - fn set_vertex_position( - camera_caster: CameraCaster, - mut creating_lots: Query<&mut LotVertices, (With, Without)>, - ) { - if let Ok(mut lot_vertices) = creating_lots.get_single_mut() { - if let Some(point) = camera_caster.intersect_ground().map(|hover| hover.xz()) { - let first_vertex = *lot_vertices - .first() - .expect("vertices should have at least 2 vertices"); - let last_vertex = lot_vertices.last_mut().unwrap(); - - const SNAP_DELTA: f32 = 0.1; - let delta = first_vertex - point; - if delta.x.abs() <= SNAP_DELTA && delta.y.abs() <= SNAP_DELTA { - trace!("snapping vertex position to last vertex `{last_vertex:?}`"); - *last_vertex = first_vertex; - } else { - trace!("updating vertex position to `{point:?}`"); - *last_vertex = point; - } - } - } - } - - fn cancel( - _trigger: Trigger>, - lot_tool: Option>>, - mut commands: Commands, - creating_lots: Query>, - ) { - if !observer_in_state(lot_tool, LotTool::Create) { - return; - } - - if let Ok(entity) = creating_lots.get_single() { - info!("ending lot creation"); - commands.entity(entity).despawn(); - } - } - - fn confirm( - _trigger: Trigger>, - lot_tool: Option>>, - mut create_events: EventWriter, - mut creating_lots: Query<&mut LotVertices, (With, Without)>, - cities: Query>, - ) { - if !observer_in_state(lot_tool, LotTool::Create) { - return; - } - - if let Ok(mut lot_vertices) = creating_lots.get_single_mut() { - let first_vertex = *lot_vertices - .first() - .expect("vertices should have at least 2 vertices"); - let last_vertex = *lot_vertices.last().unwrap(); - if first_vertex == last_vertex { - info!("confirming lot creation"); - create_events.send(LotCreate { - polygon: lot_vertices.0.clone(), - city_entity: cities.single(), - }); - } else { - info!("confirming lot point"); - lot_vertices.push(last_vertex); - } - } - } -} - -#[derive(Component)] -struct CreatingLot; - -impl InputContext for CreatingLot { - const PRIORITY: isize = 1; - - fn context_instance(_world: &World, _entity: Entity) -> ContextInstance { - let mut ctx = ContextInstance::default(); - - ctx.bind::() - .to((KeyCode::Escape, GamepadButtonType::East)); - ctx.bind::() - .to((MouseButton::Left, GamepadButtonType::South)); - - ctx - } -} - -#[derive(Debug, InputAction)] -#[input_action(output = bool)] -struct CancelLot; - -#[derive(Debug, InputAction)] -#[input_action(output = bool)] -struct ConfirmLot; diff --git a/base/src/game_world/city/lot/moving_lot.rs b/base/src/game_world/city/lot/moving_lot.rs deleted file mode 100644 index 8e50e4c8..00000000 --- a/base/src/game_world/city/lot/moving_lot.rs +++ /dev/null @@ -1,169 +0,0 @@ -use bevy::{math::Vec3Swizzles, prelude::*}; -use bevy_enhanced_input::prelude::*; - -use super::{LotDelete, LotMove, LotTool, LotVertices, UnconfirmedLot}; -use crate::{ - common_conditions::observer_in_state, - game_world::{picking::Clicked, player_camera::CameraCaster}, - settings::Settings, -}; - -pub(super) struct MovingLotPlugin; - -impl Plugin for MovingLotPlugin { - fn build(&self, app: &mut App) { - app.add_input_context::() - .observe(Self::pick) - .observe(Self::delete) - .observe(Self::cancel) - .observe(Self::confirm) - .add_systems(Update, Self::apply_movement.run_if(in_state(LotTool::Move))) - .add_systems( - PostUpdate, - Self::cleanup_despawned.run_if(in_state(LotTool::Move)), - ); - } -} - -impl MovingLotPlugin { - fn pick( - trigger: Trigger, - lot_tool: Option>>, - mut commands: Commands, - lots: Query<(Entity, &Parent, &LotVertices)>, - ) { - if !observer_in_state(lot_tool, LotTool::Move) { - return; - } - - let point = trigger.event().xz(); - if let Some((entity, parent, vertices)) = lots - .iter() - .find(|(.., vertices)| vertices.contains_point(point)) - { - info!("picking lot `{entity}`"); - commands.entity(**parent).with_children(|parent| { - parent.spawn(( - StateScoped(LotTool::Move), - vertices.clone(), - MovingLot { - entity, - offset: **trigger.event(), - }, - )); - }); - } - } - - fn apply_movement( - camera_caster: CameraCaster, - mut moving_lots: Query<(&mut Transform, &MovingLot), Without>, - ) { - if let Ok((mut transform, moving_lot)) = moving_lots.get_single_mut() { - if let Some(point) = camera_caster.intersect_ground() { - transform.translation = point - moving_lot.offset; - } - } - } - - fn delete( - _trigger: Trigger>, - lot_tool: Option>>, - mut delete: EventWriter, - moving_lots: Query<&MovingLot, Without>, - ) { - if !observer_in_state(lot_tool, LotTool::Move) { - return; - } - - if let Ok(moving_lot) = moving_lots.get_single() { - info!("deleting picked lot"); - delete.send(LotDelete(moving_lot.entity)); - } - } - - fn cancel( - _trigger: Trigger>, - lot_tool: Option>>, - mut commands: Commands, - mut moving_lots: Query>, - ) { - if !observer_in_state(lot_tool, LotTool::Move) { - return; - } - - if let Ok(entity) = moving_lots.get_single_mut() { - info!("ending lot movement"); - commands.entity(entity).despawn(); - } - } - - fn confirm( - _trigger: Trigger>, - lot_tool: Option>>, - mut move_events: EventWriter, - mut moving_lots: Query<(&mut Transform, &MovingLot), Without>, - ) { - if !observer_in_state(lot_tool, LotTool::Move) { - return; - } - - if let Ok((transform, moving_lot)) = moving_lots.get_single_mut() { - info!("confirming lot movement"); - move_events.send(LotMove { - entity: moving_lot.entity, - offset: transform.translation.xz(), - }); - } - } - - fn cleanup_despawned(mut commands: Commands, mut moving_lots: Query<(Entity, &MovingLot)>) { - if let Ok((entity, moving_lot)) = moving_lots.get_single_mut() { - if commands.get_entity(moving_lot.entity).is_none() { - info!( - "cancelling movement for despawned lot `{:?}`", - moving_lot.entity - ); - commands.entity(entity).despawn(); - } - } - } -} - -#[derive(Component)] -struct MovingLot { - /// The entity of the lot for which the movement is performed. - entity: Entity, - /// Contains the offset of the cursor position to the position of the object when it was picked. - offset: Vec3, -} - -impl InputContext for MovingLot { - const PRIORITY: isize = 1; - - fn context_instance(world: &World, _entity: Entity) -> ContextInstance { - let mut ctx = ContextInstance::default(); - let settings = world.resource::(); - - ctx.bind::() - .to((&settings.keyboard.delete, GamepadButtonType::North)); - ctx.bind::() - .to((KeyCode::Escape, GamepadButtonType::East)); - ctx.bind::() - .to((MouseButton::Left, GamepadButtonType::South)); - - ctx - } -} - -#[derive(Debug, InputAction)] -#[input_action(output = bool)] -struct DeleteLot; - -#[derive(Debug, InputAction)] -#[input_action(output = bool)] -struct CancelLot; - -#[derive(Debug, InputAction)] -#[input_action(output = bool)] -struct ConfirmLot; diff --git a/base/src/math.rs b/base/src/math.rs index 267b4678..c8e1800b 100644 --- a/base/src/math.rs +++ b/base/src/math.rs @@ -1,16 +1,14 @@ -pub(super) mod polygon; pub(super) mod segment; pub(super) mod triangulator; use bevy::prelude::*; -use polygon::Polygon; use segment::Segment; pub(super) struct MathPlugin; impl Plugin for MathPlugin { fn build(&self, app: &mut App) { - app.register_type::().register_type::(); + app.register_type::(); } } diff --git a/base/src/math/polygon.rs b/base/src/math/polygon.rs deleted file mode 100644 index 11fb1da5..00000000 --- a/base/src/math/polygon.rs +++ /dev/null @@ -1,56 +0,0 @@ -use bevy::prelude::*; -use itertools::Itertools; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Default, Deref, DerefMut, Deserialize, Reflect, Serialize)] -pub(crate) struct Polygon(pub(crate) Vec); - -impl Polygon { - /// A port of W. Randolph Franklin's [PNPOLY](https://wrf.ecse.rpi.edu//Research/Short_Notes/pnpoly.html) algorithm. - #[must_use] - pub(crate) fn contains_point(&self, point: Vec2) -> bool { - let mut inside = false; - for (a, b) in self.iter().tuple_windows() { - if ((a.y > point.y) != (b.y > point.y)) - && (point.x < (b.x - a.x) * (point.y - a.y) / (b.y - a.y) + a.x) - { - inside = !inside; - } - } - - inside - } -} - -impl From> for Polygon { - fn from(value: Vec) -> Self { - Self(value) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn contains_point() { - let polygon = Polygon(vec![ - Vec2::new(1.0, 1.0), - Vec2::new(1.0, 2.0), - Vec2::new(2.0, 2.0), - Vec2::new(2.0, 1.0), - ]); - assert!(polygon.contains_point(Vec2::new(1.2, 1.9))); - } - - #[test] - fn not_contains_point() { - let polygon = Polygon(vec![ - Vec2::new(1.0, 1.0), - Vec2::new(1.0, 2.0), - Vec2::new(2.0, 2.0), - Vec2::new(2.0, 1.0), - ]); - assert!(!polygon.contains_point(Vec2::new(3.2, 4.9))); - } -} diff --git a/ui/src/hud/city_hud.rs b/ui/src/hud/city_hud.rs index b3aa9ae1..7eb2c121 100644 --- a/ui/src/hud/city_hud.rs +++ b/ui/src/hud/city_hud.rs @@ -1,4 +1,3 @@ -mod lots_node; mod roads_node; use bevy::prelude::*; @@ -16,14 +15,13 @@ use project_harmonia_widgets::{ use strum::IntoEnumIterator; use crate::hud::{objects_node, tools_node}; -use lots_node::LotsNodePlugin; use roads_node::RoadsNodePlugin; pub(super) struct CityHudPlugin; impl Plugin for CityHudPlugin { fn build(&self, app: &mut App) { - app.add_plugins((LotsNodePlugin, RoadsNodePlugin)) + app.add_plugins(RoadsNodePlugin) .add_systems(OnEnter(WorldState::City), Self::setup) .add_systems( Update, @@ -94,7 +92,6 @@ impl CityHudPlugin { ObjectCategory::CITY_CATEGORIES, ); } - CityMode::Lots => lots_node::setup(parent, &theme), CityMode::Roads => roads_node::setup( parent, &mut tab_commands, diff --git a/ui/src/hud/city_hud/lots_node.rs b/ui/src/hud/city_hud/lots_node.rs deleted file mode 100644 index 44394c99..00000000 --- a/ui/src/hud/city_hud/lots_node.rs +++ /dev/null @@ -1,54 +0,0 @@ -use bevy::prelude::*; -use strum::IntoEnumIterator; - -use project_harmonia_base::game_world::{city::lot::LotTool, WorldState}; -use project_harmonia_widgets::{ - button::{ExclusiveButton, TextButtonBundle, Toggled}, - theme::Theme, -}; - -pub(super) struct LotsNodePlugin; - -impl Plugin for LotsNodePlugin { - fn build(&self, app: &mut App) { - app.add_systems( - Update, - Self::set_lot_tool.run_if(in_state(WorldState::City)), - ); - } -} - -impl LotsNodePlugin { - fn set_lot_tool( - mut lot_tool: ResMut>, - buttons: Query<(Ref, &LotTool), Changed>, - ) { - for (toggled, &mode) in &buttons { - if toggled.0 && !toggled.is_added() { - info!("changing lot tool to `{mode:?}`"); - lot_tool.set(mode); - } - } - } -} - -pub(super) fn setup(parent: &mut ChildBuilder, theme: &Theme) { - parent - .spawn(NodeBundle { - style: Style { - flex_direction: FlexDirection::Column, - ..Default::default() - }, - ..Default::default() - }) - .with_children(|parent| { - for tool in LotTool::iter() { - parent.spawn(( - tool, - ExclusiveButton, - Toggled(tool == Default::default()), - TextButtonBundle::symbol(theme, tool.glyph()), - )); - } - }); -}