Files
war-in-tunnels/src/app/states/skirmish.rs
T
GarandPLG 9300eef906 Initialize skirmish board and refactor states
- Create `GameStates` from a `&Cli` and initialize the skirmish board in
  `App::new`.
- Move map dimensions to `SkirmishState` and add a `board_cells` vector
  populated by `CellWidget`s.
- Refactor `SettingsState` to store only user‑specific settings (fields
  are cloned).
- Update `BoardWidget` to hold a reference to the cell vector and use
  the new dimensions.
- Adjust CLI defaults: map width to 50 and map height to 25.
2026-03-27 19:25:20 +01:00

66 lines
1.3 KiB
Rust

use crate::app::widgets::CellWidget;
use clap::ValueEnum;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Offset {
value: usize,
max: usize,
}
impl Offset {
pub fn new() -> Self {
Self { value: 0, max: 0 }
}
pub fn get_value(&self) -> usize {
self.value
}
pub fn set_max(&mut self, max: usize) {
if self.max != 0 {
return;
}
self.max = max;
}
pub fn next(&mut self) {
self.value = self.value.saturating_add(1).min(self.max);
}
pub fn prev(&mut self) {
self.value = self.value.saturating_sub(1).max(0)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkirmishState {
pub id: usize,
pub name: &'static str,
pub map_width: usize,
pub map_height: usize,
pub vertical_offset: Offset,
pub horizontal_offset: Offset,
pub board_cells: Vec<CellWidget>,
}
impl SkirmishState {
pub fn init_board(&mut self) {
if !self.board_cells.is_empty() {
return;
}
for row in 0..self.map_height {
for col in 0..self.map_width {
self.board_cells.push(CellWidget::new(row, col));
}
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
pub enum GameMode {
LastManStanding,
FrontLines,
}