generated from GarandPLG/rust-flake-template
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:
@@ -16,6 +16,10 @@ impl BaseBuilding {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_owner(&self) -> Players {
|
||||
self.owner
|
||||
}
|
||||
|
||||
pub fn get_tag(&self) -> &'static str {
|
||||
self.tag
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
use crate::app::buildings::BaseBuilding;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Buildings {
|
||||
Base(BaseBuilding),
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
pub mod base;
|
||||
pub mod building;
|
||||
|
||||
pub use base::BaseBuilding;
|
||||
pub use building::Buildings;
|
||||
|
||||
@@ -9,5 +9,5 @@ pub use main_menu::MainMenuState;
|
||||
pub use perk_decks::{PerkDecks, PerkDecksState};
|
||||
pub use settings::SettingsState;
|
||||
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};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::skirmish_states::BoardState;
|
||||
use crate::app::{buildings::BaseBuilding, states::skirmish_states::BoardState};
|
||||
use clap::ValueEnum;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -22,8 +22,8 @@ pub enum ZoomLevel {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum CellTag {
|
||||
Base(Players),
|
||||
pub enum CellStructure {
|
||||
Base(BaseBuilding),
|
||||
Tunel,
|
||||
Stone,
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
use crate::app::{
|
||||
buildings::{BaseBuilding, Buildings},
|
||||
buildings::BaseBuilding,
|
||||
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},
|
||||
widgets::CellWidget,
|
||||
};
|
||||
@@ -62,12 +64,12 @@ impl BoardState {
|
||||
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 player_base {
|
||||
CellTag::Base(Players::Player)
|
||||
let structure: CellStructure = if player_base {
|
||||
CellStructure::Base(BaseBuilding::new(Players::Player))
|
||||
} else if enemy_base {
|
||||
CellTag::Base(Players::Enemy)
|
||||
CellStructure::Base(BaseBuilding::new(Players::Enemy))
|
||||
} else {
|
||||
CellTag::Stone
|
||||
CellStructure::Stone
|
||||
};
|
||||
|
||||
let unit: Option<Units> = if player_base {
|
||||
@@ -78,16 +80,8 @@ impl BoardState {
|
||||
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(
|
||||
row, col, zoom_level, selected, tag, unit, building,
|
||||
row, col, zoom_level, selected, structure, unit,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
+21
-31
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user