generated from GarandPLG/rust-flake-template
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:
@@ -1,5 +1,9 @@
|
||||
use crate::app::states::skirmish_states::BoardState;
|
||||
use clap::ValueEnum;
|
||||
use ratatui::{
|
||||
style::{Color, Stylize},
|
||||
text::Span,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct SkirmishState {
|
||||
@@ -20,3 +24,26 @@ pub enum Players {
|
||||
Player,
|
||||
Enemy,
|
||||
}
|
||||
|
||||
impl Players {
|
||||
pub fn get_text(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Player => "Player",
|
||||
Self::Enemy => "Enemy",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> Color {
|
||||
match self {
|
||||
Self::Player => Color::LightBlue,
|
||||
Self::Enemy => Color::LightRed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_span(&self) -> Span<'static> {
|
||||
match self {
|
||||
Self::Player => self.get_text().fg(self.get_color()),
|
||||
Self::Enemy => self.get_text().fg(self.get_color()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user