Lazy init game states and extract board module

App now stores CLI arguments and an optional GameStates, initializing
the
states lazily on the first window resize. Skirmish board logic is moved
to
a new BoardState module with dedicated helpers (cells_area_helper and
updated cell size handling). Views and keybindings are updated to use
the
optional state accessors.
This commit is contained in:
2026-04-02 00:45:57 +02:00
parent c4e28255b6
commit 923af91aeb
15 changed files with 228 additions and 178 deletions
+2 -25
View File
@@ -1,34 +1,11 @@
use crate::app::{
states::{FocusedCell, Offset},
widgets::CellWidget,
};
use crate::app::states::skirmish_states::BoardState;
use clap::ValueEnum;
#[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>,
pub zoom_level: ZoomLevel,
pub focused_cell: FocusedCell,
}
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, false));
}
}
}
pub board: BoardState,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]