generated from GarandPLG/rust-flake-template
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:
@@ -1,4 +1,8 @@
|
||||
use crate::app::states::skirmish_states::{Players, tasks::Tasks, units::Unit};
|
||||
use crate::app::states::skirmish_states::{
|
||||
Players,
|
||||
tasks::{Task, Tasks},
|
||||
units::Unit,
|
||||
};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
@@ -22,6 +26,22 @@ impl MinerUnit {
|
||||
tasks: VecDeque::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn col_to_letters(&self, col: usize) -> String {
|
||||
let mut col: usize = col + 1;
|
||||
let mut letters: Vec<char> = Vec::new();
|
||||
|
||||
while col > 0 {
|
||||
letters.push((b'A' + ((col - 1) % 26) as u8) as char);
|
||||
col = (col - 1) / 26;
|
||||
}
|
||||
|
||||
letters.iter().rev().collect()
|
||||
}
|
||||
|
||||
fn display_coords(&self, coords: &(usize, usize)) -> String {
|
||||
format!("{}{}", self.col_to_letters(coords.0), coords.1)
|
||||
}
|
||||
}
|
||||
|
||||
impl Unit for MinerUnit {
|
||||
@@ -62,7 +82,17 @@ impl Unit for MinerUnit {
|
||||
}
|
||||
|
||||
fn get_tasks_formatted(&self) -> String {
|
||||
format!("{:?}", self.tasks)
|
||||
// format!("{:?}", self.tasks)
|
||||
let mut output: String = String::new();
|
||||
for task in &self.tasks {
|
||||
output.push(task.get_icon());
|
||||
output.push(' ');
|
||||
output += &self.display_coords(task.get_path_front_coords());
|
||||
output += " -> ";
|
||||
output += &self.display_coords(task.get_path_back_coords());
|
||||
}
|
||||
|
||||
output
|
||||
}
|
||||
|
||||
fn set_task(&mut self, task: Tasks) {
|
||||
|
||||
Reference in New Issue
Block a user