generated from GarandPLG/rust-flake-template
Add tests, fix offset logic, and bump dependencies
- Introduce a comprehensive test suite (cli, app, board, tasks, audio) and a new TESTING.md document describing test execution. - Correct vertical offset calculation in `BoardState` to use saturating subtraction and ceiling division. - Clamp initial `Offset` values to the provided maximum in `Offset::new`. - Export `load_audio` from the audio thread module and switch to `LoopedDecoder` for proper OGG looping. - Update several crate versions: clap, ratatui, log, rodio, and bitflags.
This commit is contained in:
1 parent
9bc42dc898
commit
fcdbbaf74c
16 files changed
+817
-246
No files matched your search
@@ -51,7 +51,7 @@ impl BoardState {
|
||||
let h_max_offset: usize = Self::max_offset(map_width, cols);
|
||||
|
||||
let vertical_offset: Offset = Offset::new(
|
||||
Some((map_height - rows as usize + 1) / 2),
|
||||
Some(map_height.saturating_sub(rows).div_ceil(2)),
|
||||
Some(v_max_offset),
|
||||
);
|
||||
let horizontal_offset: Offset = Offset::new(None, Some(h_max_offset));
|
||||
|
||||
@@ -7,7 +7,7 @@ pub struct Offset {
|
||||
impl Offset {
|
||||
pub fn new(initial_value: Option<usize>, initial_max: Option<usize>) -> Self {
|
||||
Self {
|
||||
value: initial_value.unwrap_or(0),
|
||||
value: initial_value.unwrap_or(0).min(initial_max.unwrap_or(0)),
|
||||
max: initial_max.unwrap_or(0),
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,12 @@ impl Offset {
|
||||
}
|
||||
|
||||
pub fn set_value(&mut self, value: usize) {
|
||||
self.value = value;
|
||||
self.value = value.min(self.max);
|
||||
}
|
||||
|
||||
pub fn set_max(&mut self, max: usize) {
|
||||
self.max = max;
|
||||
self.value = self.value.min(max);
|
||||
}
|
||||
|
||||
pub fn next(&mut self) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::app::states::skirmish_states::tasks::Task;
|
||||
use std::{collections::VecDeque, ops::Add};
|
||||
use std::collections::VecDeque;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DiggingTask {
|
||||
@@ -49,7 +49,7 @@ impl Task for DiggingTask {
|
||||
}
|
||||
|
||||
fn progress(&mut self) {
|
||||
let _ = self.progress.add(self.tick_increase).max(0.0).min(100.0);
|
||||
self.progress = (self.progress + self.tick_increase).clamp(0.0, 100.0);
|
||||
}
|
||||
|
||||
fn is_finished(&self) -> bool {
|
||||
|
||||
Reference in new issue
Block a user