Replace CellTag with CellStructure and embed BaseBuilding

The refactor removes the `Buildings` enum and the `building` module,
replacing
`CellTag` with a new `CellStructure` enum that directly holds a
`BaseBuilding`.
A `get_owner` method is added to `BaseBuilding` to support the new
structure.
All related imports, constructors, and rendering logic are updated to
use
`CellStructure` instead of the old tag and building fields.
This commit is contained in:
2026-04-16 21:56:06 +02:00
parent 268e6d98bf
commit 6dc5f8605c
7 changed files with 38 additions and 58 deletions
+4
View File
@@ -16,6 +16,10 @@ impl BaseBuilding {
} }
} }
pub fn get_owner(&self) -> Players {
self.owner
}
pub fn get_tag(&self) -> &'static str { pub fn get_tag(&self) -> &'static str {
self.tag self.tag
} }
-6
View File
@@ -1,6 +0,0 @@
use crate::app::buildings::BaseBuilding;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Buildings {
Base(BaseBuilding),
}
-2
View File
@@ -1,5 +1,3 @@
pub mod base; pub mod base;
pub mod building;
pub use base::BaseBuilding; pub use base::BaseBuilding;
pub use building::Buildings;
+1 -1
View File
@@ -9,5 +9,5 @@ pub use main_menu::MainMenuState;
pub use perk_decks::{PerkDecks, PerkDecksState}; pub use perk_decks::{PerkDecks, PerkDecksState};
pub use settings::SettingsState; pub use settings::SettingsState;
pub use skills_config::SkillsConfigState; pub use skills_config::SkillsConfigState;
pub use skirmish::{CellTag, GameMode, Players, SkirmishState, ZoomLevel}; pub use skirmish::{CellStructure, GameMode, Players, SkirmishState, ZoomLevel};
pub use skirmish_states::{FocusedCell, Offset}; pub use skirmish_states::{FocusedCell, Offset};
+3 -3
View File
@@ -1,4 +1,4 @@
use crate::app::states::skirmish_states::BoardState; use crate::app::{buildings::BaseBuilding, states::skirmish_states::BoardState};
use clap::ValueEnum; use clap::ValueEnum;
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@@ -22,8 +22,8 @@ pub enum ZoomLevel {
} }
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CellTag { pub enum CellStructure {
Base(Players), Base(BaseBuilding),
Tunel, Tunel,
Stone, Stone,
} }
+9 -15
View File
@@ -1,7 +1,9 @@
use crate::app::{ use crate::app::{
buildings::{BaseBuilding, Buildings}, buildings::BaseBuilding,
helpers::{CellSizes, cell_size_helper, cells_area_helper}, helpers::{CellSizes, cell_size_helper, cells_area_helper},
states::{CellTag, FocusedCell, Offset, Players, ZoomLevel, skirmish_states::MoveFocusedCell}, states::{
CellStructure, FocusedCell, Offset, Players, ZoomLevel, skirmish_states::MoveFocusedCell,
},
units::{MinerUnit, Units}, units::{MinerUnit, Units},
widgets::CellWidget, widgets::CellWidget,
}; };
@@ -62,12 +64,12 @@ impl BoardState {
let player_base: bool = row == player_base_coords.0 && col == player_base_coords.1; 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 enemy_base: bool = row == enemy_base_coords.0 && col == enemy_base_coords.1;
let tag: CellTag = if player_base { let structure: CellStructure = if player_base {
CellTag::Base(Players::Player) CellStructure::Base(BaseBuilding::new(Players::Player))
} else if enemy_base { } else if enemy_base {
CellTag::Base(Players::Enemy) CellStructure::Base(BaseBuilding::new(Players::Enemy))
} else { } else {
CellTag::Stone CellStructure::Stone
}; };
let unit: Option<Units> = if player_base { let unit: Option<Units> = if player_base {
@@ -78,16 +80,8 @@ impl BoardState {
None None
}; };
let building: Option<Buildings> = if player_base {
Some(Buildings::Base(BaseBuilding::new(Players::Player)))
} else if enemy_base {
Some(Buildings::Base(BaseBuilding::new(Players::Enemy)))
} else {
None
};
rows.push(CellWidget::new( rows.push(CellWidget::new(
row, col, zoom_level, selected, tag, unit, building, row, col, zoom_level, selected, structure, unit,
)); ));
} }
+20 -30
View File
@@ -1,6 +1,5 @@
use crate::app::{ use crate::app::{
buildings::Buildings, states::{CellStructure, Players, ZoomLevel},
states::{CellTag, Players, ZoomLevel},
units::Units, units::Units,
}; };
use ratatui::{ use ratatui::{
@@ -17,10 +16,9 @@ pub struct CellWidget {
col: usize, col: usize,
selected: bool, selected: bool,
zoom_level: ZoomLevel, zoom_level: ZoomLevel,
tag: CellTag, structure: CellStructure,
marked: bool, marked: bool,
unit: Option<Units>, unit: Option<Units>,
building: Option<Buildings>,
} }
impl CellWidget { impl CellWidget {
@@ -29,19 +27,17 @@ impl CellWidget {
col: usize, col: usize,
zoom_level: ZoomLevel, zoom_level: ZoomLevel,
selected: bool, selected: bool,
tag: CellTag, structure: CellStructure,
unit: Option<Units>, unit: Option<Units>,
building: Option<Buildings>,
) -> Self { ) -> Self {
Self { Self {
row, row,
col, col,
selected, selected,
zoom_level, zoom_level,
tag,
marked: false, marked: false,
structure,
unit, unit,
building,
} }
} }
@@ -54,8 +50,8 @@ impl CellWidget {
self.zoom_level = zoom_level; self.zoom_level = zoom_level;
} }
pub fn set_tag(&mut self, tag: CellTag) { pub fn set_structure(&mut self, sctructure: CellStructure) {
self.tag = tag; self.structure = sctructure;
} }
pub fn get_marked(&self) -> bool { pub fn get_marked(&self) -> bool {
@@ -80,7 +76,7 @@ impl CellWidget {
} }
fn display_coords(&self) -> Span<'_> { fn display_coords(&self) -> Span<'_> {
if self.selected || self.tag != CellTag::Stone || self.marked { if self.selected || self.structure != CellStructure::Stone || self.marked {
format!("{}{}", self.col_to_letters(), self.row).green() format!("{}{}", self.col_to_letters(), self.row).green()
} else { } else {
"".to_span() "".to_span()
@@ -88,36 +84,30 @@ impl CellWidget {
} }
fn fg_color(&self) -> Color { fn fg_color(&self) -> Color {
match self.tag { match self.structure {
_ if self.marked && self.selected => Color::Magenta, _ if self.marked && self.selected => Color::Magenta,
_ if self.marked && !self.selected => Color::LightMagenta, _ if self.marked && !self.selected => Color::LightMagenta,
_ if self.selected && !self.marked => Color::LightYellow, _ if self.selected && !self.marked => Color::LightYellow,
CellTag::Base(Players::Player) if !self.selected => Color::LightBlue, CellStructure::Base(base) if !self.selected => match base.get_owner() {
CellTag::Base(Players::Enemy) if !self.selected => Color::LightRed, Players::Player => Color::LightBlue,
CellTag::Tunel if !self.selected => Color::Gray, Players::Enemy => Color::LightRed,
},
CellStructure::Tunel if !self.selected => Color::Gray,
_ => Color::White, _ => Color::White,
} }
} }
fn get_text_area(&self) -> Vec<Line<'_>> { fn get_text_area(&self) -> Vec<Line<'_>> {
let tag: &str = match self.building { let tag: &str = match self.structure {
Some(building) => match building { CellStructure::Base(base) => base.get_tag(),
Buildings::Base(base) => base.get_tag(), CellStructure::Tunel => "T",
CellStructure::Stone => " ",
// _ => " ", // _ => " ",
},
None => match self.tag {
CellTag::Tunel => "T",
CellTag::Stone => " ",
_ => " ",
},
}; };
let b_level: &str = match self.building { let b_level: &str = match self.structure {
Some(building) => match building { CellStructure::Base(base) => base.get_level(),
Buildings::Base(base) => base.get_level(), _ => " ",
// _ => " ",
},
None => " ",
}; };
let unit: &str = match self.unit { let unit: &str = match self.unit {