From 44d29bd3ad4561ff7ba6c1e0e7fd951afb386dbe Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Mon, 13 Apr 2026 21:27:44 +0200 Subject: [PATCH] Add Building and Unit structs, extend CellWidget Introduce empty Building and Unit types and expose them through new modules. Extend CellWidget to store optional Unit and Building, update its constructor, and adjust board rendering to create cells with these new fields (currently always None). --- src/app/buildings/building.rs | 2 ++ src/app/buildings/mod.rs | 3 +++ src/app/mod.rs | 2 ++ src/app/states/skirmish_states/board.rs | 10 +++++++--- src/app/units/mod.rs | 3 +++ src/app/units/unit.rs | 2 ++ src/app/widgets/cell.rs | 8 +++++++- 7 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/app/buildings/building.rs create mode 100644 src/app/buildings/mod.rs create mode 100644 src/app/units/mod.rs create mode 100644 src/app/units/unit.rs diff --git a/src/app/buildings/building.rs b/src/app/buildings/building.rs new file mode 100644 index 0000000..bba5c6f --- /dev/null +++ b/src/app/buildings/building.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Building {} diff --git a/src/app/buildings/mod.rs b/src/app/buildings/mod.rs new file mode 100644 index 0000000..6802d55 --- /dev/null +++ b/src/app/buildings/mod.rs @@ -0,0 +1,3 @@ +pub mod building; + +pub use building::Building; diff --git a/src/app/mod.rs b/src/app/mod.rs index ba41332..b9e0203 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -1,10 +1,12 @@ pub mod app; +pub mod buildings; pub mod helpers; pub mod keybind; pub mod keybindings; pub mod state; pub mod states; pub mod threads; +pub mod units; pub mod view; pub mod views; pub mod widgets; diff --git a/src/app/states/skirmish_states/board.rs b/src/app/states/skirmish_states/board.rs index 3377544..cc08ee9 100644 --- a/src/app/states/skirmish_states/board.rs +++ b/src/app/states/skirmish_states/board.rs @@ -57,16 +57,20 @@ impl BoardState { for col in 0..map_width { let selected: bool = row == focused_cell.get_row() && col == focused_cell.get_col(); + let player_base: bool = row == player_base_coords.0 && col == player_base_coords.1; + let enemy_base: bool = row == enemy_base_coords.0 && col == enemy_base_coords.1; - let tag: CellTag = if row == player_base_coords.0 && col == player_base_coords.1 { + let tag: CellTag = if player_base { CellTag::Base(Players::Player) - } else if row == enemy_base_coords.0 && col == enemy_base_coords.1 { + } else if enemy_base { CellTag::Base(Players::Enemy) } else { CellTag::Stone }; - rows.push(CellWidget::new(row, col, zoom_level, selected, tag)); + rows.push(CellWidget::new( + row, col, zoom_level, selected, tag, None, None, + )); } cells.push(rows); diff --git a/src/app/units/mod.rs b/src/app/units/mod.rs new file mode 100644 index 0000000..dde757e --- /dev/null +++ b/src/app/units/mod.rs @@ -0,0 +1,3 @@ +pub mod unit; + +pub use unit::Unit; diff --git a/src/app/units/unit.rs b/src/app/units/unit.rs new file mode 100644 index 0000000..d824ba6 --- /dev/null +++ b/src/app/units/unit.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Unit {} diff --git a/src/app/widgets/cell.rs b/src/app/widgets/cell.rs index 5e719b3..3260287 100644 --- a/src/app/widgets/cell.rs +++ b/src/app/widgets/cell.rs @@ -1,4 +1,4 @@ -use crate::app::states::ZoomLevel; +use crate::app::{buildings::Building, states::ZoomLevel, units::Unit}; use ratatui::{ buffer::Buffer, layout::{Alignment, Rect}, @@ -28,6 +28,8 @@ pub struct CellWidget { zoom_level: ZoomLevel, tag: CellTag, marked: bool, + unit: Option, + building: Option, } impl CellWidget { @@ -37,6 +39,8 @@ impl CellWidget { zoom_level: ZoomLevel, selected: bool, tag: CellTag, + unit: Option, + building: Option, ) -> Self { Self { row, @@ -45,6 +49,8 @@ impl CellWidget { zoom_level, tag, marked: false, + unit, + building, } }