Refactor task handling to use VecDeque references

- Change `get_tasks` to return `&VecDeque<Tasks>` instead of a formatted
  `String`.
- Introduce `get_tasks_formatted` for display purposes.
- Update `MinerUnit`, `Unit` trait, `Units` enum, and its `Option`
  implementation accordingly.
- Add `EMPTY_TASKS` lazy static for handling empty task lists.
- Adjust `BoardState` to use the new task API (commented out
  conditional).
This commit is contained in:
GarandPLG committed 2026-05-18 14:48:07 +02:00
1 parent e4728aab5d
commit 7c9e3d28f0
4 files changed
+30 -6

No files matched your search

@@ -1,8 +1,13 @@
use once_cell::sync::Lazy;
use crate::app::states::skirmish_states::{
Players,
tasks::Tasks,
units::{MinerUnit, Unit},
};
use std::collections::VecDeque;
static EMPTY_TASKS: Lazy<VecDeque<Tasks>> = Lazy::new(|| VecDeque::new());
#[derive(Debug, Clone, PartialEq)]
pub enum Units {
@@ -58,10 +63,14 @@ impl Unit for Units {
self.u().get_coords()
}
fn get_tasks(&self) -> String {
fn get_tasks(&self) -> &VecDeque<Tasks> {
self.u().get_tasks()
}
fn get_tasks_formatted(&self) -> String {
self.u().get_tasks_formatted()
}
fn set_task(&mut self, task: Tasks) {
self.u_mut().set_task(task);
}
@@ -104,8 +113,13 @@ impl Unit for Option<Units> {
self.as_ref().map_or((0, 0), |u| u.get_coords())
}
fn get_tasks(&self) -> String {
self.as_ref().map_or("".to_string(), |u| u.get_tasks())
fn get_tasks(&self) -> &VecDeque<Tasks> {
self.as_ref().map_or(&EMPTY_TASKS, |u| u.get_tasks())
}
fn get_tasks_formatted(&self) -> String {
self.as_ref()
.map_or("".to_string(), |u| u.get_tasks_formatted())
}
fn set_task(&mut self, task: Tasks) {