generated from GarandPLG/rust-flake-template
f7c1795f29
- 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.
51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use crate::app::states::skirmish_states::structures::{BaseBuilding, Stone, Structure, Tunnel};
|
|
use ratatui::style::Color;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum Structures {
|
|
Base(BaseBuilding),
|
|
Tunnel(Tunnel),
|
|
Stone(Stone),
|
|
}
|
|
|
|
impl Structures {
|
|
#[inline]
|
|
fn structure(&self) -> &dyn Structure {
|
|
match self {
|
|
Self::Base(b) => b,
|
|
Self::Tunnel(t) => t,
|
|
Self::Stone(s) => s,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Structure for Structures {
|
|
fn get_color(&self) -> Color {
|
|
self.structure().get_color()
|
|
}
|
|
|
|
fn get_tag(&self) -> char {
|
|
self.structure().get_tag()
|
|
}
|
|
|
|
fn get_level(&self) -> char {
|
|
self.structure().get_level()
|
|
}
|
|
|
|
fn get_name(&self) -> &'static str {
|
|
self.structure().get_name()
|
|
}
|
|
|
|
fn get_durability(&self) -> u16 {
|
|
self.structure().get_durability()
|
|
}
|
|
|
|
fn get_max_durability(&self) -> u16 {
|
|
self.structure().get_max_durability()
|
|
}
|
|
|
|
fn get_stress(&self) -> u8 {
|
|
self.structure().get_stress()
|
|
}
|
|
}
|