generated from GarandPLG/rust-flake-template
Add digging tasks and unit coordinate support
Introduce Tasks handling for units, store coordinates in MinerUnit, expose getters/setters for unit tasks, add logging of marked cells, and provide cell accessors for mutable unit options.
This commit is contained in:
1 parent
a3bb9dc6f1
commit
f554fa2efc
5 files changed
+70
-7
No files matched your search
@@ -1,5 +1,6 @@
|
||||
use crate::app::states::skirmish_states::{
|
||||
Players,
|
||||
tasks::Tasks,
|
||||
units::{MinerUnit, Unit},
|
||||
};
|
||||
|
||||
@@ -15,6 +16,13 @@ impl Units {
|
||||
Self::Miner(m) => m,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn u_mut(&mut self) -> &mut dyn Unit {
|
||||
match self {
|
||||
Self::Miner(m) => m,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Unit for Units {
|
||||
@@ -45,6 +53,14 @@ impl Unit for Units {
|
||||
fn get_digging_power(&self) -> f32 {
|
||||
self.u().get_digging_power()
|
||||
}
|
||||
|
||||
fn get_coords(&self) -> (usize, usize) {
|
||||
self.u().get_coords()
|
||||
}
|
||||
|
||||
fn set_task(&mut self, task: Tasks) {
|
||||
self.u_mut().set_task(task);
|
||||
}
|
||||
}
|
||||
|
||||
impl Unit for Option<Units> {
|
||||
@@ -79,4 +95,12 @@ impl Unit for Option<Units> {
|
||||
fn get_digging_power(&self) -> f32 {
|
||||
self.as_ref().map_or(0.0, |u| u.get_digging_power())
|
||||
}
|
||||
|
||||
fn get_coords(&self) -> (usize, usize) {
|
||||
self.as_ref().map_or((0, 0), |u| u.get_coords())
|
||||
}
|
||||
|
||||
fn set_task(&mut self, task: Tasks) {
|
||||
self.as_mut().map_or((), |u| u.set_task(task))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user