Files
war-in-tunnels/src/app/states/skirmish_states/units/units_enum.rs
T
GarandPLG 41020708e4 Rename internal helpers and adjust related calls
Rename `structure` to `s` in Structures and `unit` to `u` in Units,
updating all
call sites. Refactor `Structures::text` to match on the owner directly
and
push the owner line only for claimed owners. Change the “% )” token
color
in unit display from green to gray.
2026-05-06 18:51:45 +02:00

82 lines
1.5 KiB
Rust

use crate::app::states::skirmish_states::{
Players,
units::{MinerUnit, Unit},
};
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Units {
Miner(MinerUnit),
}
impl Units {
fn u(&self) -> &dyn Unit {
match self {
Self::Miner(m) => m,
}
}
}
impl Unit for Units {
fn get_tag(&self) -> char {
self.u().get_tag()
}
fn get_name(&self) -> &'static str {
self.u().get_name()
}
fn get_owner(&self) -> Players {
self.u().get_owner()
}
fn get_hp(&self) -> u16 {
self.u().get_hp()
}
fn get_max_hp(&self) -> u16 {
self.u().get_max_hp()
}
fn get_can_dig(&self) -> bool {
self.u().get_can_dig()
}
fn get_digging_power(&self) -> f32 {
self.u().get_digging_power()
}
}
impl Unit for Option<Units> {
fn is_unit(&self) -> bool {
self.map_or(false, |u| u.is_unit())
}
fn get_tag(&self) -> char {
self.map_or(' ', |u| u.get_tag())
}
fn get_name(&self) -> &'static str {
self.map_or("", |u| u.get_name())
}
fn get_owner(&self) -> Players {
self.map_or(Players::Unclaimed, |u| u.get_owner())
}
fn get_hp(&self) -> u16 {
self.map_or(0, |u| u.get_hp())
}
fn get_max_hp(&self) -> u16 {
self.map_or(0, |u| u.get_max_hp())
}
fn get_can_dig(&self) -> bool {
self.map_or(false, |u| u.get_can_dig())
}
fn get_digging_power(&self) -> f32 {
self.map_or(0.0, |u| u.get_digging_power())
}
}