Commit Graph

61 Commits

Author SHA1 Message Date
GarandPLG 7ec3eec6e3 Preload audio using once_cell and correct typo
Add once_cell 1.21.4 and a Lazy‑initialized HashMap to store OGG bytes.

Replace file reads with in‑memory Cursor decoding, fix the
SoundrackParts enum typo, and derive Hash traits for it.
2026-04-09 01:37:57 +02:00
GarandPLG 3e932e5638 Add ChangePart command and buffered audio sink
Introduce a `ChangePart` variant to `AudioCmd` and a `current_part`
state in
`handle_audio`.  The audio sink is now created via
`DeviceSinkBuilder::from_default_device` with a fixed buffer size.
`load_audio`
now accepts a reference to `SoundrackParts`, and the player
automatically
queues the correct part when the queue becomes empty.
2026-04-09 01:08:50 +02:00
GarandPLG 56bef7c98e Refactor CellWidget constructor to accept selected
Update `CellWidget::new` to take a `selected` flag and remove the
chaining return values from `set_selected` and `set_zoom_level`. The
board code now passes the selection state directly during construction.
2026-04-08 23:43:16 +02:00
GarandPLG 247f5c143b Adjust board vertical offset and focus 2026-04-08 14:51:04 +02:00
GarandPLG e4682f1c52 Refactor board cells to 2D vector and auto‑scroll
Store cells as a nested vector instead of a flat list, simplifying
indexing and
rendering. Add `is_focused_cell_visible` to detect when the focused cell
is
outside the viewport and adjust vertical/horizontal offsets accordingly
in
the skirmish keybindings. Update related methods and widget rendering to
use
the new 2‑D structure.
2026-04-08 14:25:14 +02:00
GarandPLG 4917068fb1 Fix board after resize 2026-04-08 13:24:44 +02:00
GarandPLG 04db2f1daf Make BoardState fields private 2026-04-08 00:08:09 +02:00
GarandPLG 48483da1a4 Refactor skirmish focus handling and CellWidget API
Introduce a MoveFocusedCell enum and a BoardState.change_focused_cell
method to
centralize focus movement logic. Update skirmish keybindings to use this
new
method and simplify board rendering by directly using stored CellWidget
state.
Make CellWidget setters chainable and expose the new enum in the module
re‑exports. Remove duplicated max_offset logic and old move_* methods.
2026-04-07 23:20:11 +02:00
GarandPLG e3fea75983 Add zoom support and emoji keybinding icons
- CellWidget now stores a ZoomLevel, renders size‑dependent text, and
  provides
  methods to set the zoom level and build its block.
- BoardState creates cells with the current zoom level, adds a helper to
  get a
  mutable cell, and updates each cell’s zoom level in `zoom_change`.
- KeybindingsWidget constructor now takes the widget height, calculates
  vertical padding to centre groups, and adds left borders between
  groups.
- Views (default, main_menu, skirmish) pass the area height to the new
  constructor.
- Keybinding descriptions are replaced with emoji symbols (🔈, 🔊, 🔉).
- BoardWidget clones the cell template instead of dereferencing it.
2026-04-07 19:21:43 +02:00
GarandPLG 3f646de3bb Encapsulate cell selection and simplify board rendering 2026-04-07 17:48:05 +02:00
GarandPLG 2b96ec129f Encapsulate FocusedCell fields and add getters 2026-04-07 01:14:36 +02:00
GarandPLG 8e01c8c33a Add audio subsystem with mute and volume controls
Update flake.lock dependencies to latest revisions
2026-04-07 01:05:33 +02:00
GarandPLG 0f37989f55 Rename input event handler to handle_events
Rename the input event handler module and function.
Update imports, re‑exports, and main.rs to use handle_events.
Add a brief doc comment for the new function.
2026-04-06 12:20:19 +02:00
GarandPLG 30f2e17ed7 Add audio deps; extract input handling to threads
Add ALSA and Rodio crates to Cargo.toml and lockfile to enable audio
playback.
Update Nix expressions to include `alsa-lib` as a build input.
Refactor input event handling into a new `app::threads` module:
 - Define `AppEvent` enum and `handle_input_events` function there.
 - Adjust imports in `app/app.rs` and `main.rs` accordingly.
   Remove the now‑unused `handle_input_events` and `AppEvent`
   definitions from
   `app/app.rs`.
2026-04-06 11:47:46 +02:00
GarandPLG 92ace142b4 Join input thread before exiting
Store the input event thread handle and join it after the app finishes.
This
replaces the previous fire‑and‑forget spawn and ensures the thread is
cleanly
terminated before the program exits.
2026-04-06 11:10:03 +02:00
GarandPLG dd64ef78f7 Rename Event to AppEvent and update imports
Rename the generic `Event` enum to `AppEvent` and propagate the change
through `app.rs`, `mod.rs`, and `main.rs`. Adjust function signatures,
imports, and channel usage to use the new name and the `read` helper
from crossterm. Ensure all senders/receivers now work with `AppEvent`.
2026-04-06 10:34:33 +02:00
GarandPLG 921596376f Adjust map size CLI defaults and ranges 2026-04-06 10:12:43 +02:00
GarandPLG 923af91aeb 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.
2026-04-02 00:45:57 +02:00
GarandPLG c4e28255b6 Move skirmish Offset and FocusedCell to own module
Extract Offset and FocusedCell structs from skirmish.rs into a new
skirmish_states module. Re-export the structs from the top-level states
module and adjust imports in skirmish.rs.
2026-04-01 22:10:25 +02:00
GarandPLG f405c3cde1 Track window area and refactor keybinding APIs
- Track terminal size in `App::window_area` and update on resize
- Accept action slices in `count_largest_group` and
  `KeybindingsWidget::new`
- Add ACTIONS slices and layout helpers for default, main_menu, skirmish
- Add `main_menu_option_helper` for formatting menu strings and export
  it
2026-04-01 20:27:50 +02:00
GarandPLG bf8883934d Add zoom level helper and use it for cell sizing
Introduce a new `zoom_level` module containing the `CellSizes` enum and
`cell_size_helper` function to map `ZoomLevel` values to width and
height
dimensions. Export the helper from `mod.rs` and refactor `BoardWidget`
to
import and use `cell_size_helper`, eliminating duplicated match
statements.
2026-04-01 19:57:44 +02:00
GarandPLG 07e941eba1 Add bounded focus and padding to skirmish UI
- Initialize FocusedCell with map dimensions and start near the map
  centre.
- Store max rows/cols in FocusedCell and clamp moves to these bounds.
- Scroll actions now adjust the corresponding offset and also move the
  focused cell, keeping navigation consistent.
- Zoom actions modify the vertical offset to keep the view centered
  after
  changing zoom levels.
- Cell widget now uses a Padding widget with dynamic top padding based
  on
  the area height.
2026-03-30 16:32:28 +02:00
GarandPLG 363baa1c1a Add navigation and selection for skirmish cells
Reclassify Escape key as Quit and add directional actions to move the
focused cell.
2026-03-29 22:03:22 +02:00
GarandPLG d35d803a78 Show cell coordinates with column letters
Introduce `col_to_letters` to convert a zero‑based column index into
Excel‑style
letters. Add `display_coords` that returns the column letters followed
by the
row number. Update `render` to use this formatted coordinate as the
block
title instead of the previous row/col placeholder.
2026-03-29 21:07:05 +02:00
GarandPLG 6f17406d98 Add documentation
Extensive doc comments were added to keybindings, CLI options, logging,
and
widget modules. The `count_largest_group` function was introduced to
compute
the largest group size among actions. CLI validation for
`skill_points_limit`
was broadened to a 90‑690 range. Imports and signatures for `Display`
were
adjusted accordingly.
2026-03-29 15:36:11 +02:00
GarandPLG 9719e1ba6b Add block title helpers and use them in UI 2026-03-29 15:12:40 +02:00
GarandPLG 1d1dc0f2f7 Add zoom support and dynamic keybinding layout
Introduce ZoomIn/ZoomOut actions and a Zoom group with corresponding
keybindings.
Add a CLI option to set the initial zoom level and a ZoomLevel enum.
Expose a utility to compute the largest keybinding group size for layout
sizing.
Refactor board widget to adjust cell dimensions based on zoom level and
simplify offset calculations.
Update views to use the new layout sizing helper and integrate zoom
handling in skirmish logic.
2026-03-29 14:12:03 +02:00
GarandPLG edf491457e Add init flags to Offset and set vertical offset
Add `value_initiated` and `max_initiated` flags to prevent
repeated assignments. Provide `set_initial_value` for one‑time
initialisation and use it to centre the vertical offset when
creating the board widget. Remove stale comments on cell size constants.
2026-03-28 14:35:05 +01:00
GarandPLG ba0028b7a7 Refactor keybindings and add validated CLI arguments
Extracted common quit/esc handling into `common_keybindings`. Introduced
`Group::CtrlMovement` for Ctrl‑arrow keys and updated keybinding
definitions.
Removed duplicated quit logic in main_menu and skirmish modules. Bumped
clap to 4.6.0 and updated Cargo.lock. Added range‑checked parsers for
map
size, resources, supply limit, XP modifier and skill points in the CLI.
2026-03-27 20:15:15 +01:00
GarandPLG 9300eef906 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.
2026-03-27 19:25:20 +01:00
GarandPLG a0186ea0cb Add optional file logging and fix board offsets
Introduce --log CLI flag to enable logging to
war_in_tunnels.log via simplelog.
2026-03-27 18:28:16 +01:00
GarandPLG b71130d3d6 Increase board cell dimensions
Double the height from 4 to 8 and the width from 7 to 14 to improve
readability of the board display.
2026-03-27 16:58:22 +01:00
GarandPLG 5a40760151 Replace scrollbar state with simple offset struct
Introduce Offset type to track scroll positions and replace
ScrollbarState fields in SkirmishState
Update keybindings, App::draw, Widget impl, and BoardWidget::new
to use mutable references and the new Offset struct.
Adjust imports accordingly.
2026-03-26 21:50:39 +01:00
GarandPLG cc179cee03 Add scrolling actions and board widget
Introduce directional and scroll actions, update keybindings, add
scrollbar
state to SkirmishState, and render the board with a new BoardWidget.
Adjust CLI
defaults and layout heights accordingly.
2026-03-26 11:05:43 +01:00
GarandPLG 0577697059 Replace settings module with skirmish mode
Removed the settings UI and its keybinding logic, added a skirmish view
and corresponding keybindings, simplified the SettingsState to hold
skirmish configuration, updated module exports, and changed the CLI
default map height from 25 to 21. Also fixed the main menu selection
limit.
2026-03-17 14:28:46 +01:00
GarandPLG aaa2c90426 Refactor gaamestates 2026-03-16 21:58:43 +01:00
GarandPLG 53a713b5ea Refactor settings UI and add typed option handling
- Rename `GameMode::Frontlines` to `FrontLines`.
- Introduce `SettingsValue` enum and `SettingsOption` vector for
  typed settings.
- Implement `Display` for `SettingsValue`, `GameMode`, and
  `PerkDecks`.
- Enhance settings keybindings: navigation with Up/Down, value
  parsing on Enter, and error messages.
- Update settings view to render options list, selection marker,
  and popup with error feedback.
- Restyle main menu selector and keybindings widget title.
- Add required imports and minor layout adjustments.
2026-03-16 21:42:08 +01:00
GarandPLG 1d8d1eed46 Rename GameSettingsState to SettingsOptions 2026-03-16 10:45:14 +01:00
GarandPLG aacdacadd5 Extract GameSettingsState and tweak popup layout
The settings model now separates generic settings from game‑specific
fields by
introducing `GameSettingsState`. All game‑related fields are moved into
this
struct and `SettingsState` now holds a `game_settings` field.
Initialization in
`GameStates::new` is updated accordingly. The UI popup is rendered
directly
with added padding and a resized rectangle, and the unused `popup_area`
variable is removed.
2026-03-16 10:42:58 +01:00
GarandPLG fd0f6defea Rename GameStates to States and adjust keybindings
Replace the old `GameStates` struct with a new `states` module, rename
the
field in `App` to `states`, and update construction to pass CLI args.
Remove the now‑unused `game_states.rs` file and adjust imports
accordingly.
Update keybinding definitions: change the wildcard symbol to "[All]" and
simplify the wildcard detection logic by dropping the modifiers check.
2026-03-16 10:27:44 +01:00
GarandPLG 2dbe378470 Add text input handling to settings popup
Introduce a `selected_setting_new_value` field in `SettingsState` and
initialize it.
Add `Backspace` and `WildCard(char)` actions with an `Input` group, and
corresponding keybindings.
Update `event_to_action` to map wildcard characters to
`Action::WildCard`.
Handle backspace and character input in `settings_keybindings` to edit
the new field.
Display the edited value in the settings popup and include the new
actions in the UI.
2026-03-15 22:37:11 +01:00
GarandPLG 9d4ff19b6e KeybindingsWidget now accepts actions
Views now pass a list of `Action` values to `KeybindingsWidget` instead
of
pre‑resolved `KeyBinding` references. The widget resolves the bindings
internally using `binding_for`, simplifying import statements and view
logic.
2026-03-15 22:00:00 +01:00
GarandPLG acc6ba08f3 Add popup toggle to settings view
Introduce `show_popup` flag in SettingsState, toggle it with the Space
key, and
render a yellow test popup in the settings view when the flag is true.
2026-03-14 20:35:03 +01:00
GarandPLG 3d0aa42d7d Adopt clap::ValueEnum for Group and tidy menu view
- Derive `ValueEnum` for `Group` and remove its custom `iter` method.
- Update keybindings widget to use `Group::value_variants()` and adjust
  containment and filtering logic.
- Replace view option generation with a `format_view_string` helper that
  inserts a space before the second capital letter, eliminating the
  previous filter for “MAIN MENU”.
- Adjust imports to include `clap::ValueEnum` where needed.
2026-03-14 20:13:41 +01:00
GarandPLG 61e9dedfe8 Refactor view handling and keybinding API
Move the `View` enum to a dedicated module and implement `Widget` for
`&App` there.
Rename `default_view_keybindings` to `default_keybindings` and adjust
its
signature. Redesign `KeybindingsWidget` to accept an explicit list of
bindings instead of a `View`. Update imports, function signatures, and
rendering
logic across the codebase to reflect these changes.
2026-03-13 20:10:49 +01:00
GarandPLG d563bbc966 Add Settings view, widget, and keybindings
Introduce Settings view handling in key events and widgets.
Add `Enter` action with its keybinding.
Refactor keybinding lookup to use `Option<&KeyBinding>` for missing
entries.
Update view option generation to safely filter possible values.
Export `settings_keybindings` and `settings_widget` from their modules.
2026-03-13 09:31:55 +01:00
GarandPLG 7226a09bb4 Extract default view keybindings and widget
Move generic view rendering and keybinding logic into a new default
module and
replace inline implementations with calls to the new helpers.
2026-03-12 23:06:55 +01:00
GarandPLG 70a8ac348e Refactor keybindings widget and reorder Group enum
- Introduce `KeybindingsWidget::new(view)` constructor and remove the
  standalone `keybindings_widget` function.
- Update all imports and call sites to use `KeybindingsWidget` directly.
- Reorder `Group` enum to place `Quit` after `Select` and adjust its
  iterator accordingly.
2026-03-12 22:47:22 +01:00
GarandPLG 073e70441f Add group filtering and layout for keybindings UI
Return the set of used groups from `binding_for_view` and adjust
`keybindings_widget` to render only those groups. Introduce a vertical
layout in the main widget to display a placeholder paragraph above
the keybindings area, and update imports and border logic accordingly.
2026-03-12 17:31:31 +01:00
GarandPLG 8b7c2c55ce Extract keybinding handling to separate module 2026-03-12 16:37:52 +01:00