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,4 +1,4 @@
|
||||
use crate::app::states::Players;
|
||||
use crate::app::states::{Players, skirmish_states::units::Unit};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct MinerUnit {
|
||||
@@ -9,8 +9,14 @@ impl MinerUnit {
|
||||
pub fn new(owner: Players) -> Self {
|
||||
Self { owner }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_tag(self) -> char {
|
||||
impl Unit for MinerUnit {
|
||||
fn get_owner(&self) -> Players {
|
||||
self.owner
|
||||
}
|
||||
|
||||
fn get_tag(&self) -> char {
|
||||
'M'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
mod miner;
|
||||
mod units_enum;
|
||||
mod units_trait;
|
||||
|
||||
pub use miner::MinerUnit;
|
||||
pub use units_enum::Units;
|
||||
pub use units_trait::{OptionalUnit, Unit};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
use crate::app::states::skirmish_states::units::{MinerUnit, OptionalUnit, Unit};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Units {
|
||||
Miner(MinerUnit),
|
||||
}
|
||||
|
||||
impl Units {
|
||||
pub fn get_tag(&self) -> char {
|
||||
match self {
|
||||
Units::Miner(m) => m.get_tag(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl OptionalUnit for Option<Units> {
|
||||
fn try_get_tag(&self) -> char {
|
||||
self.map_or(' ', |u| u.get_tag())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
use crate::app::states::Players;
|
||||
|
||||
pub trait Unit {
|
||||
fn get_owner(&self) -> Players;
|
||||
fn get_tag(&self) -> char;
|
||||
}
|
||||
|
||||
pub trait OptionalUnit {
|
||||
fn try_get_tag(&self) -> char;
|
||||
}
|
||||
Reference in New Issue
Block a user