Add Task trait and improve miner task display

Define a full `Task` trait with icon and path accessors. Implement the
trait for
`DiggingTask` and delegate it through the `Tasks` enum. Introduce helper
functions in `MinerUnit` to convert coordinates to spreadsheet‑style
strings
and use them in a revamped `get_tasks_formatted`. Update the unit
rendering
logic to show the tasks queue only when tasks are present.
This commit is contained in:
2026-05-18 15:48:40 +02:00
parent 7c9e3d28f0
commit d2f5968861
5 changed files with 97 additions and 5 deletions
@@ -1,5 +1,7 @@
use std::collections::VecDeque;
use crate::app::states::skirmish_states::tasks::Task;
#[derive(Debug, Clone, PartialEq)]
pub struct DiggingTask {
path: VecDeque<(usize, usize)>,
@@ -10,3 +12,21 @@ impl DiggingTask {
Self { path }
}
}
impl Task for DiggingTask {
fn get_icon(&self) -> char {
'⛏'
}
fn get_path(&self) -> &VecDeque<(usize, usize)> {
&self.path
}
fn get_path_front_coords(&self) -> &(usize, usize) {
self.path.front().map_or(&(0, 0), |c| c)
}
fn get_path_back_coords(&self) -> &(usize, usize) {
self.path.back().map_or(&(0, 0), |c| c)
}
}
@@ -1 +1,11 @@
pub trait Task {}
use std::collections::VecDeque;
pub trait Task {
fn get_icon(&self) -> char;
fn get_path(&self) -> &VecDeque<(usize, usize)>;
fn get_path_front_coords(&self) -> &(usize, usize);
fn get_path_back_coords(&self) -> &(usize, usize);
}
@@ -1,6 +1,34 @@
use crate::app::states::skirmish_states::tasks::DiggingTask;
use crate::app::states::skirmish_states::tasks::{DiggingTask, Task};
use std::collections::VecDeque;
#[derive(Debug, Clone, PartialEq)]
pub enum Tasks {
Digging(DiggingTask),
}
impl Tasks {
#[inline]
fn t(&self) -> &dyn Task {
match self {
Self::Digging(d) => d,
}
}
}
impl Task for Tasks {
fn get_icon(&self) -> char {
self.t().get_icon()
}
fn get_path(&self) -> &VecDeque<(usize, usize)> {
self.t().get_path()
}
fn get_path_front_coords(&self) -> &(usize, usize) {
self.t().get_path_front_coords()
}
fn get_path_back_coords(&self) -> &(usize, usize) {
self.t().get_path_back_coords()
}
}