generated from GarandPLG/rust-flake-template
Use VecDeque for tasks and marked cells
Replace `Vec` with `VecDeque` in `BoardState` marked cells, `DiggingTask` path, and `MinerUnit` tasks to enable efficient push/pop operations. Remove the `Copy` trait from several structs and enums, adjust derives accordingly, and use `as_ref` in `Option<Units>` implementations to avoid consuming the option. Update cell rendering to clone widgets and adjust `CellWidget::get_option_unit` to return a cloned `Option<Units>`. Add necessary `VecDeque` imports.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
use crate::app::states::skirmish_states::{Players, tasks::Tasks, units::Unit};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct MinerUnit {
|
||||
owner: Players,
|
||||
hp: u16,
|
||||
can_dig: bool,
|
||||
digging_power: f32,
|
||||
// tasks: Vec<Tasks>,
|
||||
pub tasks: VecDeque<Tasks>,
|
||||
}
|
||||
|
||||
impl MinerUnit {
|
||||
@@ -16,7 +17,7 @@ impl MinerUnit {
|
||||
hp: 100,
|
||||
can_dig: true,
|
||||
digging_power: 0.55,
|
||||
// tasks: Vec::new(),
|
||||
tasks: VecDeque::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,13 @@ use crate::app::states::skirmish_states::{
|
||||
units::{MinerUnit, Unit},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum Units {
|
||||
Miner(MinerUnit),
|
||||
}
|
||||
|
||||
impl Units {
|
||||
#[inline]
|
||||
fn u(&self) -> &dyn Unit {
|
||||
match self {
|
||||
Self::Miner(m) => m,
|
||||
@@ -48,34 +49,34 @@ impl Unit for Units {
|
||||
|
||||
impl Unit for Option<Units> {
|
||||
fn is_unit(&self) -> bool {
|
||||
self.map_or(false, |u| u.is_unit())
|
||||
self.as_ref().map_or(false, |u| u.is_unit())
|
||||
}
|
||||
|
||||
fn get_tag(&self) -> char {
|
||||
self.map_or(' ', |u| u.get_tag())
|
||||
self.as_ref().map_or(' ', |u| u.get_tag())
|
||||
}
|
||||
|
||||
fn get_name(&self) -> &'static str {
|
||||
self.map_or("", |u| u.get_name())
|
||||
self.as_ref().map_or("", |u| u.get_name())
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Players {
|
||||
self.map_or(Players::Unclaimed, |u| u.get_owner())
|
||||
self.as_ref().map_or(Players::Unclaimed, |u| u.get_owner())
|
||||
}
|
||||
|
||||
fn get_hp(&self) -> u16 {
|
||||
self.map_or(0, |u| u.get_hp())
|
||||
self.as_ref().map_or(0, |u| u.get_hp())
|
||||
}
|
||||
|
||||
fn get_max_hp(&self) -> u16 {
|
||||
self.map_or(0, |u| u.get_max_hp())
|
||||
self.as_ref().map_or(0, |u| u.get_max_hp())
|
||||
}
|
||||
|
||||
fn get_can_dig(&self) -> bool {
|
||||
self.map_or(false, |u| u.get_can_dig())
|
||||
self.as_ref().map_or(false, |u| u.get_can_dig())
|
||||
}
|
||||
|
||||
fn get_digging_power(&self) -> f32 {
|
||||
self.map_or(0.0, |u| u.get_digging_power())
|
||||
self.as_ref().map_or(0.0, |u| u.get_digging_power())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user