Add max durability and enhance side panel UI

- Introduce `max_durability` fields to BaseBuilding, Stone, and Tunnel
  structures.
- Extend `Structure` trait with `get_max_durability` and implement it in
  all structures.
- Update `Structures` enum to forward `get_max_durability`.
- Add color utilities and `get_span` method to `Players` enum for styled
  text.
- Refactor `CellWidget` method names (`get_option_unit`,
  `set_structure`).
- Revise side panel widget to accept references to `Structures` and
  `Option<Units>`, render colored blocks and detailed stats.
- Simplify skirmish view to use `BoardState` directly and adapt side
  panel rendering.
This commit is contained in:
2026-04-26 21:04:19 +02:00
parent c24862dd48
commit f7c1795f29
9 changed files with 165 additions and 62 deletions
@@ -4,6 +4,7 @@ use ratatui::style::Color;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct BaseBuilding {
durability: u16,
max_durability: u16,
stress: u8,
owner: Players,
level: u8,
@@ -13,6 +14,7 @@ impl BaseBuilding {
pub fn new(owner: Players) -> Self {
Self {
durability: 1500,
max_durability: 1500,
stress: 0,
owner,
level: b'1',
@@ -44,6 +46,10 @@ impl Structure for BaseBuilding {
self.durability
}
fn get_max_durability(&self) -> u16 {
self.max_durability
}
fn get_stress(&self) -> u8 {
self.stress
}
@@ -4,6 +4,7 @@ use ratatui::style::Color;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Stone {
durability: u16,
max_durability: u16,
stress: u8,
}
@@ -11,6 +12,7 @@ impl Stone {
pub fn new() -> Self {
Self {
durability: 1000,
max_durability: 1000,
stress: 0,
}
}
@@ -33,6 +35,10 @@ impl Structure for Stone {
self.durability
}
fn get_max_durability(&self) -> u16 {
self.max_durability
}
fn get_stress(&self) -> u8 {
self.stress
}
@@ -40,6 +40,10 @@ impl Structure for Structures {
self.structure().get_durability()
}
fn get_max_durability(&self) -> u16 {
self.structure().get_max_durability()
}
fn get_stress(&self) -> u8 {
self.structure().get_stress()
}
@@ -6,5 +6,6 @@ pub trait Structure {
fn get_level(&self) -> char;
fn get_stress(&self) -> u8;
fn get_durability(&self) -> u16;
fn get_max_durability(&self) -> u16;
fn get_name(&self) -> &'static str;
}
@@ -4,6 +4,7 @@ use ratatui::style::Color;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Tunnel {
durability: u16,
max_durability: u16,
stress: u8,
roof_support: bool,
rail: bool,
@@ -14,6 +15,7 @@ impl Tunnel {
pub fn new() -> Self {
Self {
durability: 500,
max_durability: 500,
stress: 25,
roof_support: false,
rail: false,
@@ -39,6 +41,10 @@ impl Structure for Tunnel {
self.durability
}
fn get_max_durability(&self) -> u16 {
self.max_durability
}
fn get_stress(&self) -> u8 {
self.stress
}