Add rustfmt configuration and reformat code

- Document new Rust formatting standards in AGENTS, CODE_MAP, and
  PROGRESS.
- Add rustfmt.toml with style 2024, 2‑space indents, 100‑char width, LF
  endings.
- Apply consistent 2‑space indentation and ordering across source files.
- Minor clean‑up of imports and whitespace to match the new style.
This commit is contained in:
GarandPLG committed 2026-10-19 12:21:20 +02:00
1 parent 9e09aaf75e
commit c4313b4117
15 files changed
+66 -44

No files matched your search

+1
View File
@@ -31,6 +31,7 @@ Audio wymaga ALSA i urządzenia odtwarzania; do pracy nad TUI używaj `--disable
## Konwencje kodu
- Formatowanie określa `rustfmt.toml`: styl Rust 2024, wcięcia po 2 spacje, szerokość docelowa 100 znaków i zakończenia LF. Stosuj `nix develop -c cargo fmt --all`; kontroluj przez `nix develop -c cargo fmt --all -- --check`.
- Jawne adnotacje typów są OBOWIĄZKOWE w nowym i zmienianym kodzie: przy zmiennych i stałych, polach struktur, parametrach funkcji i domknięć oraz typach zwracanych (także `-> ()` dla funkcji bez wyniku). Nie polegaj na inferencji typu tam, gdzie można podać typ jawnie. Dotyczy to również testów. Jest to zasada jawnego typowania; rzutowania wartości (`as`, `From`, `TryFrom`) stosuj tylko wtedy, gdy potrzebna jest rzeczywista konwersja.
- Rust 2024, jedna biblioteka i jeden binarny punkt wejścia; bez workspace.
- Wykorzystuj istniejące `App`, `GameStates`, `BoardState`, akcje i widgety.
+1
View File
@@ -21,6 +21,7 @@ Wszystkie ścieżki poniżej są względem katalogu głównego repozytorium.
| Pomocniczy layout | `src/app/helpers/` | Obszar komórek, tytuły bloków i tekst opcji menu |
| Wątki | `src/app/threads/{events,tick,audio}.rs` | Crossterm, zegar 33 ms, Rodio i komendy audio |
| Środowisko | `Cargo.toml`, `flake.nix`, `default.nix`, `flake.lock` | Zależności, toolchain Fenix, ALSA, pakowanie przez Naersk lub buildRustPackage |
| Formatowanie | `rustfmt.toml` | Rustfmt, styl 2024, wcięcia po 2 spacje, docelowo 100 znaków i zakończenia LF |
| Zasoby | `soundtracks/default/`, `ui_draft/` | Dwa pliki OGG i tekstowe szkice ekranów |
Ścieżki skrócone `skirmish_states/` oznaczają `src/app/states/skirmish_states/`. Nie ma osobnego silnika gry, bazy danych ani warstwy sieciowej. Zależności Cargo: Ratatui/Crossterm, Clap, Rodio, log/simplelog i once_cell.
+6
View File
@@ -1,5 +1,11 @@
# Dziennik prac
## 2026-10-19 — formatowanie Rust z wcięciami po 2 spacje
Dodano `rustfmt.toml` z uzgodnionymi opcjami: edycja i styl 2024, `max_width = 100`, `hard_tabs = false`, `tab_spaces = 2`, zakończenia Unix, sortowanie importów i modułów oraz domyślne heurystyki krótkich konstrukcji. Zastosowano `nix develop -c cargo fmt --all` do źródeł i testów (56 zmienionych plików Rust). Zaktualizowano instrukcje agentów i mapę konfiguracji projektu.
Weryfikacja przez `nix develop -c`: `cargo fmt --all -- --check`, `cargo check --all-targets` i `cargo test --all-targets` zakończone sukcesem; 45 testów zaliczonych. Nie wprowadzano zmian mechanik ani zależności. Nie powtarzano Clippy ani ręcznej sesji TUI przy zmianie formatowania.
## 2026-10-18 — przekazanie kontekstu na kolejną sesję
Użytkownik zaakceptował aktualny stan. Nie ma ustalonego kolejnego zadania. Na start kolejnej sesji przeczytaj `docs/AGENTS.md`, `docs/CODE_MAP.md` i `docs/TESTING.md`; instrukcje w `docs/` mogą wymagać jawnego wskazania agentowi.
+11
View File
@@ -0,0 +1,11 @@
edition = "2024"
style_edition = "2024"
max_width = 100
hard_tabs = false
tab_spaces = 2
newline_style = "Unix"
reorder_imports = true
reorder_modules = true
use_small_heuristics = "Default"
+1 -2
View File
@@ -76,8 +76,7 @@ impl App {
fn draw(&mut self, frame: &mut Frame<'_>) {
let window_area: Rect = frame.area();
if window_area.width != self.window_area.width
|| window_area.height != self.window_area.height
if window_area.width != self.window_area.width || window_area.height != self.window_area.height
{
self.window_area = window_area;
if self.states.is_none() {
+1 -1
View File
@@ -17,7 +17,7 @@ pub fn block_title_helper(
line.spans.push(Span::from("[ ").gray());
for (i, (text, color)) in texts.iter().enumerate() {
let span = Span::styled(text.clone(), Style::new().fg(*color));
let span: Span<'_> = Span::styled(text.clone(), Style::new().fg(*color));
line.spans.push(span);
if let Some(sep) = separator {
+2 -4
View File
@@ -14,12 +14,10 @@ pub fn main_menu_keybindings(app: &mut App, event: &KeyEvent) {
match action {
Action::Up => {
states.main_menu.selected_view =
states.main_menu.selected_view.saturating_sub(1).max(1);
states.main_menu.selected_view = states.main_menu.selected_view.saturating_sub(1).max(1);
}
Action::Down => {
states.main_menu.selected_view =
states.main_menu.selected_view.saturating_add(1).min(3);
states.main_menu.selected_view = states.main_menu.selected_view.saturating_add(1).min(3);
}
Action::Space => {
let selected_view: usize = states.main_menu.selected_view;
+23 -19
View File
@@ -56,8 +56,7 @@ impl BoardState {
);
let horizontal_offset: Offset = Offset::new(None, Some(h_max_offset));
let focused_cell: FocusedCell =
FocusedCell::new((map_height) / 2, 3, map_height, map_width);
let focused_cell: FocusedCell = FocusedCell::new((map_height) / 2, 3, map_height, map_width);
let mut cells: Vec<Vec<CellWidget>> = Vec::new();
@@ -71,8 +70,7 @@ impl BoardState {
let (focused_row, focused_col) = focused_cell.get_coords();
let selected: bool = row == focused_row && col == focused_col;
let player_base: bool = row == player_base_coords.0 && col == player_base_coords.1;
let player_ore: bool =
row == player_base_coords.0 && col == player_base_coords.1 - 1;
let player_ore: bool = row == player_base_coords.0 && col == player_base_coords.1 - 1;
let enemy_base: bool = row == enemy_base_coords.0 && col == enemy_base_coords.1;
let enemy_ore: bool = row == enemy_base_coords.0 && col == enemy_base_coords.1 + 1;
@@ -138,7 +136,8 @@ impl BoardState {
}
pub fn get_marked_cells_widgets(&self) -> VecDeque<&CellWidget> {
self.marked_cells
self
.marked_cells
.marked_cells
.iter()
.map(|&(row, col)| &self.cells[row][col])
@@ -169,7 +168,8 @@ impl BoardState {
cell.set_marked(true);
}
self.marked_cells
self
.marked_cells
.marked_cells
.push_back((new_cell.0, new_cell.1));
}
@@ -221,13 +221,16 @@ impl BoardState {
self.focused_cell.set_focused_cell(start);
let start: (usize, usize) = self.focused_cell.get_coords();
self.get_mut_cell(row, col).set_selected(false);
self.get_mut_cell(start.0, start.1)
self
.get_mut_cell(start.0, start.1)
.set_selected(true)
.set_marked(true);
if !self.is_focused_cell_visible() {
self.vertical_offset
self
.vertical_offset
.set_value(start.0.saturating_sub(self.rows / 2));
self.horizontal_offset
self
.horizontal_offset
.set_value(start.1.saturating_sub(self.cols / 2));
}
self.marked_cells.selected_unit = selected_unit;
@@ -278,7 +281,8 @@ impl BoardState {
}
fn is_walkable(&self, (row, col): (usize, usize)) -> bool {
self.cells
self
.cells
.get(row)
.and_then(|cells| cells.get(col))
.is_some_and(|cell| {
@@ -324,8 +328,7 @@ impl BoardState {
self.horizontal_offset =
Offset::new(Some(self.horizontal_offset.get_value()), Some(h_max_offset));
self.vertical_offset =
Offset::new(Some(self.vertical_offset.get_value()), Some(v_max_offset));
self.vertical_offset = Offset::new(Some(self.vertical_offset.get_value()), Some(v_max_offset));
}
pub fn change_zoom(&mut self, new_zoom_level: ZoomLevel) {
@@ -340,8 +343,7 @@ impl BoardState {
let v_max_offset: usize = Self::max_offset(self.map_height, self.rows);
let h_max_offset: usize = Self::max_offset(self.map_width, self.cols);
self.vertical_offset =
Offset::new(Some(self.vertical_offset.get_value()), Some(v_max_offset));
self.vertical_offset = Offset::new(Some(self.vertical_offset.get_value()), Some(v_max_offset));
self.horizontal_offset =
Offset::new(Some(self.horizontal_offset.get_value()), Some(h_max_offset));
@@ -361,7 +363,8 @@ impl BoardState {
let old_cell: (usize, usize) = self.focused_cell.get_coords();
let new_cell: (usize, usize) = self.focused_cell.move_focused_cell(direction);
self.get_mut_cell(old_cell.0, old_cell.1)
self
.get_mut_cell(old_cell.0, old_cell.1)
.set_selected(false);
self.get_mut_cell(new_cell.0, new_cell.1).set_selected(true);
@@ -378,7 +381,8 @@ impl BoardState {
.enumerate()
.flat_map(|(row, cells)| {
cells.iter().enumerate().filter_map(move |(col, cell)| {
cell.get_ref_option_unit()
cell
.get_ref_option_unit()
.as_ref()
.filter(|unit| !unit.get_ref_tasks().is_empty())
.map(|_| (row, col))
@@ -420,9 +424,9 @@ impl BoardState {
(Tasks::Digging(dig), Structures::Tunnel(_) | Structures::Base(_)) => {
Tasks::Moving(MovingTask::from_digging(dig))
}
(Tasks::Moving(moving), Structures::Stone(_)) => Tasks::Digging(
DiggingTask::from_moving(moving, unit.get_digging_power()),
),
(Tasks::Moving(moving), Structures::Stone(_)) => {
Tasks::Digging(DiggingTask::from_moving(moving, unit.get_digging_power()))
}
(task, _) => task,
};
match (&mut task, structure) {
@@ -93,7 +93,8 @@ impl Unit for MinerUnit {
fn get_tasks_formatted(&self) -> Vec<Line<'_>> {
Vec::from(
self.tasks
self
.tasks
.iter()
.enumerate()
.flat_map(|(i, task): (usize, &Tasks)| -> [Line<'_>; 2] {
@@ -125,19 +125,22 @@ impl Unit for Option<Units> {
}
fn get_ref_tasks(&self) -> &VecDeque<Tasks> {
self.as_ref()
self
.as_ref()
.expect("attempted to get referenced tasks from `None`")
.get_ref_tasks()
}
fn get_mut_tasks(&mut self) -> &mut VecDeque<Tasks> {
self.as_mut()
self
.as_mut()
.expect("attempted to get mutable tasks from `None`")
.get_mut_tasks()
}
fn get_tasks_formatted(&self) -> Vec<Line<'_>> {
self.as_ref()
self
.as_ref()
.map_or(Vec::new(), |u| u.get_tasks_formatted())
}
+2 -1
View File
@@ -34,7 +34,8 @@ impl Widget for BoardWidget<'_> {
.split(*col_area);
for (row_idx, cell_area) in vertical.iter().enumerate() {
self.state
self
.state
.cells
.get(row_idx + self.state.vertical_offset.get_value())
.and_then(|rows| rows.get(col_idx + self.state.horizontal_offset.get_value()))
+2 -1
View File
@@ -119,7 +119,8 @@ impl CellWidget {
let mut lines: Vec<Line<'_>> = self.zoom_level.get_cell_text_area(
self.structure.get_tag(),
self.structure.get_level(),
self.unit
self
.unit
.get_tag()
.to_string()
.fg(self.unit.get_owner().get_color()),
+2 -7
View File
@@ -62,11 +62,7 @@ impl KeybindingsWidget {
.filter(|b| b.as_ref().map_or(false, |kb| kb.group == *group))
.filter_map(|b| {
b.as_ref().map(|kb| {
Line::from_iter([
kb.symbol.red().bold(),
" - ".into(),
kb.description.into(),
])
Line::from_iter([kb.symbol.red().bold(), " - ".into(), kb.description.into()])
})
})
.collect();
@@ -115,8 +111,7 @@ impl Widget for KeybindingsWidget {
return;
}
let block: Block<'_> =
Block::default()
let block: Block<'_> = Block::default()
.borders(Borders::ALL)
.title(block_single_title_helper(
"Keybindings".to_string(),
+2 -1
View File
@@ -98,7 +98,8 @@ fn skirmish_keys_move_focus_toggle_panel_and_limit_zoom() {
app.view = View::Skirmish;
press(&mut app, KeyCode::Right);
assert_eq!(
app.states_ref()
app
.states_ref()
.unwrap()
.skirmish
.board
+4 -4
View File
@@ -281,7 +281,8 @@ fn miner_symbol_in_tunnel_uses_owner_color_even_when_selected_or_marked() {
let mut game = game();
let cell = &mut game.board.cells[5][3];
cell.set_structure(Structures::Tunnel(Tunnel::new()));
cell.set_selected(selected)
cell
.set_selected(selected)
.set_marked(marked)
.set_zoom_level(zoom);
*cell.get_mut_option_unit() = Some(Units::Miner(MinerUnit::new(owner, (5, 3))));
@@ -330,9 +331,8 @@ fn tui_shows_movement_percentage_and_clears_it_after_each_step() {
cell.render(area, &mut buffer);
buffer
};
let text = |buffer: &Buffer| -> String {
buffer.content.iter().map(|cell| cell.symbol()).collect()
};
let text =
|buffer: &Buffer| -> String { buffer.content.iter().map(|cell| cell.symbol()).collect() };
assert!(!text(&render(&game.board, 2)).contains('%'));
advance(&mut game, 46);
let buffer = render(&game.board, 2);