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:
GarandPLG committed 2026-04-02 00:45:57 +02:00
1 parent c4e28255b6
commit 923af91aeb
15 files changed
+228 -178

No files matched your search

+9 -10
View File
@@ -28,7 +28,7 @@ const ACTIONS: &[Action] = &[
Action::Esc,
];
fn skirmish_layout(area: Rect) -> [Rect; 3] {
pub fn skirmish_layout(area: Rect) -> [Rect; 3] {
Layout::vertical([
Constraint::Length(4),
Constraint::Fill(1),
@@ -37,22 +37,21 @@ fn skirmish_layout(area: Rect) -> [Rect; 3] {
.areas(area)
}
pub fn skirmish_view(app: &mut App, area: Rect, buf: &mut Buffer) {
pub fn skirmish_view(app: &App, area: Rect, buf: &mut Buffer) {
let Some(states) = app.states() else { return };
let [title_area, main_area, keybindings_area] = skirmish_layout(area);
{
let lines: Vec<Line<'_>> = Vec::from_iter([
Line::raw("War in Tunnels").yellow(),
Line::from_iter([
format!("Wood: {} (+{}) | ", app.states.settings.starting_wood, 5),
format!("Iron: {} (+{}) | ", app.states.settings.starting_iron, 1),
format!(
"Supply Limit: {}/{} | ",
10, app.states.settings.supply_limit
),
format!("Wood: {} (+{}) | ", states.settings.starting_wood, 5),
format!("Iron: {} (+{}) | ", states.settings.starting_iron, 1),
format!("Supply Limit: {}/{} | ", 10, states.settings.supply_limit),
format!(
"Skills points: {} ({}/{}) | ",
1, 20, app.states.settings.skill_points_limit
1, 20, states.settings.skill_points_limit
),
format!("Perk Deck: {}/9", 5),
]),
@@ -91,7 +90,7 @@ pub fn skirmish_view(app: &mut App, area: Rect, buf: &mut Buffer) {
vertical: 1,
});
BoardWidget::new(app, cells_area.width, cells_area.height).render(cells_area, buf);
BoardWidget::new(&states.skirmish.board).render(cells_area, buf);
}
{