generated from GarandPLG/rust-flake-template
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.
This commit is contained in:
@@ -4,8 +4,6 @@ use crate::app::states::{GameMode, PerkDecks};
|
||||
pub struct SettingsState {
|
||||
pub username: String,
|
||||
pub game_mode: GameMode,
|
||||
pub map_width: u8,
|
||||
pub map_height: u8,
|
||||
pub perk_deck: PerkDecks,
|
||||
pub starting_wood: u16,
|
||||
pub starting_iron: u16,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::app::widgets::CellWidget;
|
||||
use clap::ValueEnum;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
@@ -16,6 +17,10 @@ impl Offset {
|
||||
}
|
||||
|
||||
pub fn set_max(&mut self, max: usize) {
|
||||
if self.max != 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
self.max = max;
|
||||
}
|
||||
|
||||
@@ -28,12 +33,29 @@ impl Offset {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
#[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)]
|
||||
|
||||
Reference in New Issue
Block a user