generated from GarandPLG/rust-flake-template
Move ZoomLevel into skirmish_states
Introduce Structure and Unit traits with enum wrappers. Replace old zoom helper with ZoomLevel methods. Update imports, BoardState, CellWidget, and CLI to use new locations.
This commit is contained in:
@@ -1,34 +1,50 @@
|
||||
use crate::app::states::{Players, skirmish_states::structures::Structure};
|
||||
use ratatui::style::Color;
|
||||
|
||||
use crate::app::states::Players;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct BaseBuilding {
|
||||
durability: u16,
|
||||
stress: u8,
|
||||
owner: Players,
|
||||
level: u8,
|
||||
}
|
||||
|
||||
impl BaseBuilding {
|
||||
pub fn new(owner: Players) -> Self {
|
||||
Self { owner, level: b'1' }
|
||||
}
|
||||
|
||||
pub fn get_tag(&self) -> char {
|
||||
'B'
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> Color {
|
||||
match self.owner {
|
||||
Players::Player => Color::LightBlue,
|
||||
Players::Enemy => Color::LightRed,
|
||||
Self {
|
||||
durability: 1500,
|
||||
stress: 0,
|
||||
owner,
|
||||
level: b'1',
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_owner(&self) -> Players {
|
||||
self.owner
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_level(&self) -> char {
|
||||
impl Structure for BaseBuilding {
|
||||
fn get_tag(&self) -> char {
|
||||
'B'
|
||||
}
|
||||
|
||||
fn get_color(&self) -> Color {
|
||||
match self.owner {
|
||||
Players::Player => Color::LightBlue,
|
||||
Players::Enemy => Color::LightRed,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_level(&self) -> char {
|
||||
self.level as char
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
self.durability
|
||||
}
|
||||
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.stress
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
mod base;
|
||||
mod stone;
|
||||
mod structures_enum;
|
||||
mod structures_trait;
|
||||
mod tunnel;
|
||||
|
||||
pub use base::BaseBuilding;
|
||||
pub use stone::Stone;
|
||||
pub use structures_enum::Structures;
|
||||
pub use structures_trait::Structure;
|
||||
pub use tunnel::Tunnel;
|
||||
|
||||
@@ -1,20 +1,39 @@
|
||||
use crate::app::states::skirmish_states::structures::Structure;
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Stone {
|
||||
durability: u16,
|
||||
stress: u8,
|
||||
}
|
||||
|
||||
impl Stone {
|
||||
pub fn new() -> Self {
|
||||
Self { durability: 1000 }
|
||||
Self {
|
||||
durability: 1000,
|
||||
stress: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tag(&self) -> char {
|
||||
impl Structure for Stone {
|
||||
fn get_tag(&self) -> char {
|
||||
' '
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> Color {
|
||||
fn get_color(&self) -> Color {
|
||||
Color::White
|
||||
}
|
||||
|
||||
fn get_level(&self) -> char {
|
||||
' '
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
self.durability
|
||||
}
|
||||
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.stress
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
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 {
|
||||
pub fn get_color(&self) -> Color {
|
||||
match self {
|
||||
Structures::Base(b) => b.get_color(),
|
||||
Structures::Tunnel(t) => t.get_color(),
|
||||
Structures::Stone(s) => s.get_color(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tag(&self) -> char {
|
||||
match self {
|
||||
Structures::Base(b) => b.get_tag(),
|
||||
Structures::Tunnel(t) => t.get_tag(),
|
||||
Structures::Stone(s) => s.get_tag(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_level(&self) -> char {
|
||||
match self {
|
||||
Structures::Base(b) => b.get_level(),
|
||||
Structures::Tunnel(t) => t.get_level(),
|
||||
Structures::Stone(s) => s.get_level(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
use ratatui::style::Color;
|
||||
|
||||
pub trait Structure {
|
||||
fn get_tag(&self) -> char;
|
||||
fn get_color(&self) -> Color;
|
||||
fn get_level(&self) -> char;
|
||||
fn get_stress(&self) -> u8;
|
||||
fn get_durability(&self) -> u16;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::app::states::skirmish_states::structures::Structure;
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -19,20 +20,26 @@ impl Tunnel {
|
||||
lamp: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tag(&self) -> char {
|
||||
impl Structure for Tunnel {
|
||||
fn get_tag(&self) -> char {
|
||||
'T'
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> Color {
|
||||
fn get_color(&self) -> Color {
|
||||
Color::Gray
|
||||
}
|
||||
|
||||
pub fn get_durability(&self) -> u16 {
|
||||
fn get_level(&self) -> char {
|
||||
' '
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
self.durability
|
||||
}
|
||||
|
||||
pub fn get_stress(&self) -> u8 {
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.stress
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user