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
+21 -31
View File
@@ -1,6 +1,5 @@
use crate::app::{
buildings::Buildings,
states::{CellTag, Players, ZoomLevel},
states::{CellStructure, Players, ZoomLevel},
units::Units,
};
use ratatui::{
@@ -17,10 +16,9 @@ pub struct CellWidget {
col: usize,
selected: bool,
zoom_level: ZoomLevel,
tag: CellTag,
structure: CellStructure,
marked: bool,
unit: Option<Units>,
building: Option<Buildings>,
}
impl CellWidget {
@@ -29,19 +27,17 @@ impl CellWidget {
col: usize,
zoom_level: ZoomLevel,
selected: bool,
tag: CellTag,
structure: CellStructure,
unit: Option<Units>,
building: Option<Buildings>,
) -> Self {
Self {
row,
col,
selected,
zoom_level,
tag,
marked: false,
structure,
unit,
building,
}
}
@@ -54,8 +50,8 @@ impl CellWidget {
self.zoom_level = zoom_level;
}
pub fn set_tag(&mut self, tag: CellTag) {
self.tag = tag;
pub fn set_structure(&mut self, sctructure: CellStructure) {
self.structure = sctructure;
}
pub fn get_marked(&self) -> bool {
@@ -80,7 +76,7 @@ impl CellWidget {
}
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()
} else {
"".to_span()
@@ -88,36 +84,30 @@ impl CellWidget {
}
fn fg_color(&self) -> Color {
match self.tag {
match self.structure {
_ if self.marked && self.selected => Color::Magenta,
_ if self.marked && !self.selected => Color::LightMagenta,
_ if self.selected && !self.marked => Color::LightYellow,
CellTag::Base(Players::Player) if !self.selected => Color::LightBlue,
CellTag::Base(Players::Enemy) if !self.selected => Color::LightRed,
CellTag::Tunel if !self.selected => Color::Gray,
CellStructure::Base(base) if !self.selected => match base.get_owner() {
Players::Player => Color::LightBlue,
Players::Enemy => Color::LightRed,
},
CellStructure::Tunel if !self.selected => Color::Gray,
_ => Color::White,
}
}
fn get_text_area(&self) -> Vec<Line<'_>> {
let tag: &str = match self.building {
Some(building) => match building {
Buildings::Base(base) => base.get_tag(),
// _ => " ",
},
None => match self.tag {
CellTag::Tunel => "T",
CellTag::Stone => " ",
_ => " ",
},
let tag: &str = match self.structure {
CellStructure::Base(base) => base.get_tag(),
CellStructure::Tunel => "T",
CellStructure::Stone => " ",
// _ => " ",
};
let b_level: &str = match self.building {
Some(building) => match building {
Buildings::Base(base) => base.get_level(),
// _ => " ",
},
None => " ",
let b_level: &str = match self.structure {
CellStructure::Base(base) => base.get_level(),
_ => " ",
};
let unit: &str = match self.unit {