Add BaseBuilding and MinerUnit with UI rendering

This commit is contained in:
2026-04-16 10:59:02 +02:00
parent be41936f14
commit 0f60249309
8 changed files with 103 additions and 12 deletions
+25
View File
@@ -3,4 +3,29 @@ use crate::app::states::Players;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BaseBuilding {
owner: Players,
level: u8,
tag: &'static str,
}
impl BaseBuilding {
pub fn new(owner: Players) -> Self {
Self {
owner,
level: 1,
tag: "B",
}
}
pub fn get_tag(&self) -> &'static str {
self.tag
}
pub fn get_level(&self) -> &'static str {
match self.level {
1 => "1",
2 => "2",
3 => "3",
_ => " ",
}
}
}
+5 -1
View File
@@ -1,2 +1,6 @@
use crate::app::buildings::BaseBuilding;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Buildings {}
pub enum Buildings {
Base(BaseBuilding),
}
+1
View File
@@ -1,4 +1,5 @@
pub mod base;
pub mod building;
pub use base::BaseBuilding;
pub use building::Buildings;
+19 -1
View File
@@ -1,6 +1,8 @@
use crate::app::{
buildings::{BaseBuilding, Buildings},
helpers::{CellSizes, cell_size_helper, cells_area_helper},
states::{CellTag, FocusedCell, Offset, Players, ZoomLevel, skirmish_states::MoveFocusedCell},
units::{MinerUnit, Units},
widgets::CellWidget,
};
use ratatui::layout::Rect;
@@ -68,8 +70,24 @@ impl BoardState {
CellTag::Stone
};
let unit: Option<Units> = if player_base {
Some(Units::Miner(MinerUnit::new(Players::Player)))
} else if enemy_base {
Some(Units::Miner(MinerUnit::new(Players::Enemy)))
} else {
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, None, None,
row, col, zoom_level, selected, tag, unit, building,
));
}
+17
View File
@@ -0,0 +1,17 @@
use crate::app::states::Players;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MinerUnit {
owner: Players,
tag: &'static str,
}
impl MinerUnit {
pub fn new(owner: Players) -> Self {
Self { owner, tag: "M" }
}
pub fn get_tag(self) -> &'static str {
self.tag
}
}
+1
View File
@@ -1,4 +1,5 @@
pub mod miner;
pub mod unit;
pub use miner::MinerUnit;
pub use unit::Units;
+5 -1
View File
@@ -1,2 +1,6 @@
use crate::app::units::MinerUnit;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Units {}
pub enum Units {
Miner(MinerUnit),
}
+30 -9
View File
@@ -100,27 +100,48 @@ impl CellWidget {
}
fn get_text_area(&self) -> Vec<Line<'_>> {
let tag: &str = match self.tag {
CellTag::Base(_) => "B",
CellTag::Tunel => "T",
CellTag::Stone => " ",
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 b_level: &str = match self.building {
Some(building) => match building {
Buildings::Base(base) => base.get_level(),
// _ => " ",
},
None => " ",
};
let unit: &str = match self.unit {
Some(unit) => match unit {
Units::Miner(miner) => miner.get_tag(),
// _ => " ",
},
None => " ",
};
let units: &str = " "; // TODO: units count on that cell
let mut text_area: Vec<Line<'_>> = Vec::new();
match self.zoom_level {
ZoomLevel::ZoomedIn => {
text_area.push(Line::from(format!(" {}", units)));
text_area.push(Line::from(format!(" {} ", unit)));
text_area.push(Line::from(format!(" ")));
text_area.push(Line::from(format!(" {} ", tag)));
text_area.push(Line::from(format!(" ")));
text_area.push(Line::from(format!(" ")));
text_area.push(Line::from(format!(" {} ", b_level)));
}
ZoomLevel::Default => {
text_area.push(Line::from(format!(" {}", units)));
text_area.push(Line::from(format!(" {} ", unit)));
text_area.push(Line::from(format!(" {} ", tag)));
text_area.push(Line::from(format!(" ")));
text_area.push(Line::from(format!(" {} ", b_level)));
}
ZoomLevel::ZoomedOut => {
text_area.push(Line::from(format!(" {} ", tag)));