Add base tags, adjust margins, update CLI defaults

Introduce `CellTag` and `Players` enums and extend `CellWidget` to carry
a tag.
Store player and enemy base coordinates in `BoardState` and tag those
cells.
Reduce horizontal margin from 3 to 1 in board layout helpers.
Change CLI defaults: map width default 42, map height min 11 and default
11.
Adjust offset calculation and render constraints to match the new
layout.
This commit is contained in:
2026-04-09 18:16:26 +02:00
parent 6e6181887c
commit b45c300bc3
6 changed files with 97 additions and 44 deletions
+22 -9
View File
@@ -1,7 +1,7 @@
use crate::app::{
helpers::{CellSizes, cell_size_helper, cells_area_helper},
states::{FocusedCell, Offset, ZoomLevel, skirmish_states::MoveFocusedCell},
widgets::CellWidget,
widgets::{CellTag, CellWidget, Players},
};
use ratatui::layout::Rect;
@@ -19,6 +19,8 @@ pub struct BoardState {
pub cells: Vec<Vec<CellWidget>>,
pub zoom_level: ZoomLevel,
focused_cell: FocusedCell,
player_base_coords: (usize, usize),
enemy_base_coords: (usize, usize),
}
impl BoardState {
@@ -35,25 +37,34 @@ 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) / 2 + 1),
Some((map_height - rows as usize + 1) / 2),
Some(v_max_offset),
);
let horizontal_offset: Offset = Offset::new(None, Some(h_max_offset));
let focused_cell: FocusedCell = FocusedCell::new(map_height / 2, 2, map_height, map_width);
let focused_cell: FocusedCell =
FocusedCell::new((map_height) / 2, 2, map_height, map_width);
let mut cells: Vec<Vec<CellWidget>> = Vec::new();
let player_base_coords: (usize, usize) = ((map_height) / 2, 1);
let enemy_base_coords: (usize, usize) = ((map_height) / 2, map_width - 2);
for row in 0..map_height {
let mut rows: Vec<CellWidget> = Vec::new();
for col in 0..map_width {
rows.push(CellWidget::new(
row,
col,
row == focused_cell.get_row() && col == focused_cell.get_col(),
zoom_level,
));
let selected: bool = row == focused_cell.get_row() && col == focused_cell.get_col();
let tag: CellTag = if row == player_base_coords.0 && col == player_base_coords.1 {
CellTag::Base(Players::Player)
} else if row == enemy_base_coords.0 && col == enemy_base_coords.1 {
CellTag::Base(Players::Enemy)
} else {
CellTag::Stone
};
rows.push(CellWidget::new(row, col, zoom_level, selected, tag));
}
cells.push(rows);
@@ -72,6 +83,8 @@ impl BoardState {
cells,
zoom_level,
focused_cell,
player_base_coords,
enemy_base_coords,
}
}