generated from GarandPLG/rust-flake-template
Refactor GameMode and Players into skirmish_states
Move the GameMode and Players enums from the top‑level states module into the skirmish_states submodule, add an Unclaimed variant to Players, and update all imports, trait implementations, and related logic accordingly. Adjust the durability percentage calculation to use u32 for safety.
This commit is contained in:
@@ -9,5 +9,5 @@ pub use main_menu::MainMenuState;
|
||||
pub use perk_decks::{PerkDecks, PerkDecksState};
|
||||
pub use settings::SettingsState;
|
||||
pub use skills_config::SkillsConfigState;
|
||||
pub use skirmish::{GameMode, Players, SkirmishState};
|
||||
pub use skirmish::SkirmishState;
|
||||
pub use skirmish_states::{FocusedCell, Offset};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::{GameMode, PerkDecks};
|
||||
use crate::app::states::{PerkDecks, skirmish_states::GameMode};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct SettingsState {
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
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 {
|
||||
@@ -12,38 +7,3 @@ pub struct SkirmishState {
|
||||
pub board: BoardState,
|
||||
pub side_panel: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
|
||||
pub enum GameMode {
|
||||
LastManStanding,
|
||||
FrontLines,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
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()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::app::{
|
||||
helpers::cells_area_helper,
|
||||
states::{
|
||||
FocusedCell, Offset, Players,
|
||||
FocusedCell, Offset,
|
||||
skirmish_states::{
|
||||
CellSizes, MoveFocusedCell, ZoomLevel,
|
||||
CellSizes, MoveFocusedCell, Players, ZoomLevel,
|
||||
structures::{BaseBuilding, Stone, Structures},
|
||||
units::{MinerUnit, Units},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
use clap::ValueEnum;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
|
||||
pub enum GameMode {
|
||||
LastManStanding,
|
||||
FrontLines,
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
mod board;
|
||||
mod focused_cell;
|
||||
mod game_mode;
|
||||
mod offset;
|
||||
mod players;
|
||||
pub mod structures;
|
||||
pub mod units;
|
||||
pub mod zoom_level;
|
||||
|
||||
pub use board::BoardState;
|
||||
pub use focused_cell::{FocusedCell, MoveFocusedCell};
|
||||
pub use game_mode::GameMode;
|
||||
pub use offset::Offset;
|
||||
pub use players::Players;
|
||||
pub use zoom_level::{CellSizes, ZoomLevel};
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
use ratatui::{
|
||||
style::{Color, Stylize},
|
||||
text::Span,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Players {
|
||||
Player,
|
||||
Enemy,
|
||||
Unclaimed,
|
||||
}
|
||||
|
||||
impl Players {
|
||||
pub fn get_text(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Player => "Player",
|
||||
Self::Enemy => "Enemy",
|
||||
Self::Unclaimed => "Unclaimed",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> Color {
|
||||
match self {
|
||||
Self::Player => Color::LightBlue,
|
||||
Self::Enemy => Color::LightRed,
|
||||
Self::Unclaimed => Color::White,
|
||||
}
|
||||
}
|
||||
|
||||
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()),
|
||||
Self::Unclaimed => self.get_text().fg(self.get_color()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::{Players, skirmish_states::structures::Structure};
|
||||
use crate::app::states::skirmish_states::{Players, structures::Structure};
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -20,10 +20,6 @@ impl BaseBuilding {
|
||||
level: b'1',
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_owner(&self) -> Players {
|
||||
self.owner
|
||||
}
|
||||
}
|
||||
|
||||
impl Structure for BaseBuilding {
|
||||
@@ -35,6 +31,7 @@ impl Structure for BaseBuilding {
|
||||
match self.owner {
|
||||
Players::Player => Color::LightBlue,
|
||||
Players::Enemy => Color::LightRed,
|
||||
Players::Unclaimed => Color::LightGreen,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,4 +54,8 @@ impl Structure for BaseBuilding {
|
||||
fn get_name(&self) -> &'static str {
|
||||
"Base"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.owner
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::skirmish_states::structures::Structure;
|
||||
use crate::app::states::skirmish_states::{Players, structures::Structure};
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -46,4 +46,8 @@ impl Structure for Stone {
|
||||
fn get_name(&self) -> &'static str {
|
||||
"Stone"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
Players::Unclaimed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::app::states::skirmish_states::structures::{BaseBuilding, Stone, Structure, Tunnel};
|
||||
use crate::app::states::skirmish_states::{
|
||||
Players,
|
||||
structures::{BaseBuilding, Stone, Structure, Tunnel},
|
||||
};
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -47,4 +50,8 @@ impl Structure for Structures {
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.structure().get_stress()
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.structure().get_owner()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::app::states::skirmish_states::Players;
|
||||
use ratatui::style::Color;
|
||||
|
||||
pub trait Structure {
|
||||
@@ -8,4 +9,5 @@ pub trait Structure {
|
||||
fn get_durability(&self) -> u16;
|
||||
fn get_max_durability(&self) -> u16;
|
||||
fn get_name(&self) -> &'static str;
|
||||
fn get_owner(&self) -> Players;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::skirmish_states::structures::Structure;
|
||||
use crate::app::states::skirmish_states::{Players, structures::Structure};
|
||||
use ratatui::style::Color;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -52,4 +52,8 @@ impl Structure for Tunnel {
|
||||
fn get_name(&self) -> &'static str {
|
||||
"Tunnel"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
Players::Unclaimed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::{Players, skirmish_states::units::Unit};
|
||||
use crate::app::states::skirmish_states::{Players, units::Unit};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MinerUnit {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::app::states::{
|
||||
use crate::app::states::skirmish_states::{
|
||||
Players,
|
||||
skirmish_states::units::{MinerUnit, Unit},
|
||||
units::{MinerUnit, Unit},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -40,6 +40,6 @@ impl Unit for Option<Units> {
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.map_or(Players::Enemy, |u| u.get_owner())
|
||||
self.map_or(Players::Unclaimed, |u| u.get_owner())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::app::states::Players;
|
||||
use crate::app::states::skirmish_states::Players;
|
||||
|
||||
pub trait Unit {
|
||||
fn get_owner(&self) -> Players;
|
||||
|
||||
@@ -72,7 +72,7 @@ impl<'a> SidePanelWidget<'a> {
|
||||
let s: &Structures = self.structure;
|
||||
let durability: u16 = s.get_durability();
|
||||
let max_durability: u16 = s.get_max_durability();
|
||||
let durability_percent: u16 = durability * 100 / max_durability;
|
||||
let durability_percent: u32 = durability as u32 * 100u32 / max_durability as u32;
|
||||
let stress: u8 = s.get_stress();
|
||||
let level: char = s.get_level();
|
||||
|
||||
|
||||
+4
-1
@@ -1,5 +1,8 @@
|
||||
use crate::app::{
|
||||
states::{GameMode, PerkDecks, skirmish_states::ZoomLevel},
|
||||
states::{
|
||||
PerkDecks,
|
||||
skirmish_states::{GameMode, ZoomLevel},
|
||||
},
|
||||
threads::Soundtrack,
|
||||
view::View,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user