generated from GarandPLG/rust-flake-template
Add progress tracking to tasks and turn advancement
- Extend the `Task` trait with methods for progress handling and completion. - Update `DiggingTask` to store `progress` and `tick_increase`, and implement the new trait methods. - Implement the new methods in the `Tasks` enum, adding a mutable accessor. - Introduce `BoardState::get_active_tasks` and `BoardState::advance_turn` to iterate over active tasks and update their progress each turn. - Un-comment the call to `board.advance_turn()` in `SkirmishState::tick_update`.
This commit is contained in:
1 parent
c3b76a7c2e
commit
00eeb97ed8
5 files changed
+70
-7
No files matched your search
@@ -1,15 +1,20 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use crate::app::states::skirmish_states::tasks::Task;
|
||||
use std::{collections::VecDeque, ops::Add};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DiggingTask {
|
||||
path: VecDeque<(usize, usize)>,
|
||||
progress: f32,
|
||||
tick_increase: f32,
|
||||
}
|
||||
|
||||
impl DiggingTask {
|
||||
pub fn new(path: VecDeque<(usize, usize)>) -> Self {
|
||||
Self { path }
|
||||
pub fn new(path: VecDeque<(usize, usize)>, tick_increase: f32) -> Self {
|
||||
Self {
|
||||
path,
|
||||
progress: 0.0,
|
||||
tick_increase,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,4 +34,16 @@ impl Task for DiggingTask {
|
||||
fn get_path_back_coords(&self) -> &(usize, usize) {
|
||||
self.path.back().map_or(&(0, 0), |c| c)
|
||||
}
|
||||
|
||||
fn get_progress(&self) -> f32 {
|
||||
self.progress
|
||||
}
|
||||
|
||||
fn progress(&mut self) {
|
||||
let _ = self.progress.add(self.tick_increase).max(0.0).min(100.0);
|
||||
}
|
||||
|
||||
fn is_finished(&self) -> bool {
|
||||
self.progress >= 100.0
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user