From 0f602493094ff7abd62dd8c95ff4c11857ee5b2d Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Thu, 16 Apr 2026 10:59:02 +0200 Subject: [PATCH] Add BaseBuilding and MinerUnit with UI rendering --- src/app/buildings/base.rs | 25 ++++++++++++++++ src/app/buildings/building.rs | 6 +++- src/app/buildings/mod.rs | 1 + src/app/states/skirmish_states/board.rs | 20 ++++++++++++- src/app/units/miner.rs | 17 +++++++++++ src/app/units/mod.rs | 1 + src/app/units/unit.rs | 6 +++- src/app/widgets/cell.rs | 39 +++++++++++++++++++------ 8 files changed, 103 insertions(+), 12 deletions(-) diff --git a/src/app/buildings/base.rs b/src/app/buildings/base.rs index a6df8a8..689e3c3 100644 --- a/src/app/buildings/base.rs +++ b/src/app/buildings/base.rs @@ -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", + _ => " ", + } + } } diff --git a/src/app/buildings/building.rs b/src/app/buildings/building.rs index fd32577..7519f77 100644 --- a/src/app/buildings/building.rs +++ b/src/app/buildings/building.rs @@ -1,2 +1,6 @@ +use crate::app::buildings::BaseBuilding; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Buildings {} +pub enum Buildings { + Base(BaseBuilding), +} diff --git a/src/app/buildings/mod.rs b/src/app/buildings/mod.rs index 9bb19f8..d27af94 100644 --- a/src/app/buildings/mod.rs +++ b/src/app/buildings/mod.rs @@ -1,4 +1,5 @@ pub mod base; pub mod building; +pub use base::BaseBuilding; pub use building::Buildings; diff --git a/src/app/states/skirmish_states/board.rs b/src/app/states/skirmish_states/board.rs index 39ff056..8b812c6 100644 --- a/src/app/states/skirmish_states/board.rs +++ b/src/app/states/skirmish_states/board.rs @@ -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 = 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 = 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, )); } diff --git a/src/app/units/miner.rs b/src/app/units/miner.rs index e69de29..e6bf4d7 100644 --- a/src/app/units/miner.rs +++ b/src/app/units/miner.rs @@ -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 + } +} diff --git a/src/app/units/mod.rs b/src/app/units/mod.rs index 8ee07f9..179756b 100644 --- a/src/app/units/mod.rs +++ b/src/app/units/mod.rs @@ -1,4 +1,5 @@ pub mod miner; pub mod unit; +pub use miner::MinerUnit; pub use unit::Units; diff --git a/src/app/units/unit.rs b/src/app/units/unit.rs index 2688d48..e12c8dc 100644 --- a/src/app/units/unit.rs +++ b/src/app/units/unit.rs @@ -1,2 +1,6 @@ +use crate::app::units::MinerUnit; + #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum Units {} +pub enum Units { + Miner(MinerUnit), +} diff --git a/src/app/widgets/cell.rs b/src/app/widgets/cell.rs index a04549c..461e88d 100644 --- a/src/app/widgets/cell.rs +++ b/src/app/widgets/cell.rs @@ -100,27 +100,48 @@ impl CellWidget { } fn get_text_area(&self) -> Vec> { - 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> = 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)));