generated from GarandPLG/rust-flake-template
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.
This commit is contained in:
@@ -17,7 +17,7 @@ pub enum Structures {
|
||||
|
||||
impl Structures {
|
||||
#[inline]
|
||||
fn structure(&self) -> &dyn Structure {
|
||||
fn s(&self) -> &dyn Structure {
|
||||
match self {
|
||||
Self::Base(b) => b,
|
||||
Self::Tunnel(t) => t,
|
||||
@@ -29,46 +29,50 @@ impl Structures {
|
||||
|
||||
impl Structure for Structures {
|
||||
fn get_color(&self) -> Color {
|
||||
self.structure().get_color()
|
||||
self.s().get_color()
|
||||
}
|
||||
|
||||
fn get_tag(&self) -> char {
|
||||
self.structure().get_tag()
|
||||
self.s().get_tag()
|
||||
}
|
||||
|
||||
fn get_level(&self) -> char {
|
||||
self.structure().get_level()
|
||||
self.s().get_level()
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
self.structure().get_name()
|
||||
self.s().get_name()
|
||||
}
|
||||
|
||||
fn get_durability(&self) -> u16 {
|
||||
self.structure().get_durability()
|
||||
self.s().get_durability()
|
||||
}
|
||||
|
||||
fn get_max_durability(&self) -> u16 {
|
||||
self.structure().get_max_durability()
|
||||
self.s().get_max_durability()
|
||||
}
|
||||
|
||||
fn get_stress(&self) -> u8 {
|
||||
self.structure().get_stress()
|
||||
self.s().get_stress()
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.structure().get_owner()
|
||||
self.s().get_owner()
|
||||
}
|
||||
|
||||
fn text(&self) -> Vec<Line<'_>> {
|
||||
let owner: Players = self.structure().get_owner();
|
||||
let mut lines: Vec<Line<'_>> = self.structure().text();
|
||||
match self.s().get_owner() {
|
||||
Players::Unclaimed => self.s().text(),
|
||||
Players::Player | Players::Enemy => {
|
||||
let mut lines: Vec<Line<'_>> = self.s().text();
|
||||
|
||||
match owner {
|
||||
Players::Unclaimed => {}
|
||||
_ => lines.push(Line::from_iter(["Owner: ".gray(), owner.get_span()])),
|
||||
lines.push(Line::from_iter([
|
||||
"Owner: ".gray(),
|
||||
self.s().get_owner().get_span(),
|
||||
]));
|
||||
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
||||
lines
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ pub trait Unit {
|
||||
max_hp.green(),
|
||||
" ( ".gray(),
|
||||
hp_percent.green(),
|
||||
"% )".green(),
|
||||
"% )".gray(),
|
||||
]),
|
||||
]);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ pub enum Units {
|
||||
}
|
||||
|
||||
impl Units {
|
||||
fn unit(&self) -> &dyn Unit {
|
||||
fn u(&self) -> &dyn Unit {
|
||||
match self {
|
||||
Self::Miner(m) => m,
|
||||
}
|
||||
@@ -18,31 +18,31 @@ impl Units {
|
||||
|
||||
impl Unit for Units {
|
||||
fn get_tag(&self) -> char {
|
||||
self.unit().get_tag()
|
||||
self.u().get_tag()
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
self.unit().get_name()
|
||||
self.u().get_name()
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.unit().get_owner()
|
||||
self.u().get_owner()
|
||||
}
|
||||
|
||||
fn get_hp(&self) -> u16 {
|
||||
self.unit().get_hp()
|
||||
self.u().get_hp()
|
||||
}
|
||||
|
||||
fn get_max_hp(&self) -> u16 {
|
||||
self.unit().get_max_hp()
|
||||
self.u().get_max_hp()
|
||||
}
|
||||
|
||||
fn get_can_dig(&self) -> bool {
|
||||
self.unit().get_can_dig()
|
||||
self.u().get_can_dig()
|
||||
}
|
||||
|
||||
fn get_digging_power(&self) -> f32 {
|
||||
self.unit().get_digging_power()
|
||||
self.u().get_digging_power()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user