Milestone 21: Centralize UI SFX configuration and add audio integrity tests, Part #10
PR #827 Summary: UI Navigation Focus SFX & Global UI Audio Integration
Author: @ikostan
Repository: ikostan/SkyLockAssault
Milestone: Milestone 21 – Implement Global UI SFX Layer & Decouple Settings
Labels: enhancement, good first issue, testing, menu, audio, refactoring, EPIC
What This PR Does
This PR centralizes sound effect (SFX) asset path configuration and strengthens testing for global UI audio features in the Godot-based SkyLockAssault project. It lays groundwork for consistent UI navigation sounds (focus, accept, cancel, etc.) by reducing duplication and improving maintainability.
Key Changes by File
-
scripts/resources/audio_constants.gd:- Added
SFX_DIR_PATHas the single source of truth for all SFX assets. - Replaced legacy
UI_NAV_SOUND_PATH. - Enhanced constants for audio buses and mappings.
- Added
-
scripts/managers/audio_manager.gd:- Updated
play_sfx()to use the centralizedAudioConstants.SFX_DIR_PATH. - Removed duplicated local path constants.
- Updated
-
test/gut/test_audio_constants_discoverability.gd(new):- Comprehensive GUT tests verifying:
- Directory existence and format.
- Bus name constants and
BUS_CONFIGstructure. SFX_ASSET_MAPandUI_SFXreferential integrity.
- Includes associated
.uidfile.
- Comprehensive GUT tests verifying:
AI & Bot Support
- @sourcery-ai: Provided PR summary, Reviewer's Guide, and actionable review comments.
- @coderabbitai: Assisted with review tips and unit test ideas.
- @deepsource-io: Ran automated code review with a detailed Report Card.
Relation to Broader Work
- Advances EPIC #490 and related issues (#801, #802) around global UI audio handling, decoupling from
globals.gd, and legacy cleanup. - Note: Some full UI input routing and callback migration items are noted as still pending in the PR assessment.
Testing & Status
- Changes tested in Godot editor.
- New unit tests added for long-term reliability.
- Multiple iterative commits by @ikostan incorporating bot feedback.
This is a solid refactoring step toward a cleaner, more maintainable audio system for UI interactions across the game.
Developer Changelog
- Centralized UI SFX path configuration so audio asset locations have one authoritative source, preventing path drift between playback code and configuration/tests.
- Hardened pooled SFX playback against Godot lifecycle timing by safely handling calls before pool initialization and ignoring freed
AudioStreamPlayerinstances during playback and diagnostics. - Improved audio routing resilience by validating requested buses and safely falling back to the dedicated menu-SFX bus when a caller supplies an invalid bus.
- Expanded audio integrity coverage from static checks to runtime validation: mapped assets must load as valid
AudioStreams, fallback routing is exercised, and freed-player scenarios are tested end-to-end. - Preserved session-level caching of missing assets intentionally to avoid repeated resource lookups and input-time micro-stutter when an asset is unavailable.
- Strengthened type clarity in UI traversal code to improve editor assistance and maintainability without adding runtime overhead.
Player-Facing Impact
- UI navigation, confirmation, and cancellation sounds should be more consistent and reliable across menus.
- The game is more resilient during scene changes, startup timing, and audio-system edge cases—reducing the chance of missing UI sounds or runtime errors.
- Invalid or unavailable audio configuration now degrades more gracefully, favoring fallback behavior over broken or silent interactions.
- No intended gameplay changes; this is a stability, consistency, and maintainability improvement to the UI audio experience.
Reviewer's Guide
Centralizes UI SFX configuration and input handling into shared managers/constants, hardens pooled audio playback, and adds regression/integrity tests to validate menu navigation and device-toggle audio behavior end-to-end.
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Decouple global UI input/audio routing from Globals into a dedicated UiManager that owns menu-context detection and navigation/cancel SFX playback. |
|
scripts/core/globals.gdscripts/managers/ui_manager.gdtest/gut/test_globals_input_guards.gdtest/gut/test_nav_escape_sfx.gdtest/gut/test_audio_integration.gdtest/gut/test_audio_sfx_centralization.gd |
| Centralize SFX directory and UI/action-related audio constants and reuse them across managers and menus. |
|
scripts/resources/audio_constants.gdscripts/managers/audio_manager.gdscripts/ui/menus/key_mapping.gd |
| Harden AudioManager’s pooled SFX handling against uninitialized pools and freed AudioStreamPlayer instances while improving diagnostics. |
|
scripts/managers/audio_manager.gd |
| Add audio constants discoverability and integrity tests to enforce configuration correctness, asset existence, bus routing fallbacks, and resilience to freed pool players. |
|
test/gut/test_audio_constants_discoverability.gdtest/gut/test_audio_constants_discoverability.gd.uid |
| Extend regression coverage for UI navigation SFX across all menus and for device-toggle/key-mapping behaviors, including paused trees and silent initialization requirements. |
|
test/gut/test_all_menus_navigation_regression.gdtest/gut/test_device_toggle_audio_regression.gdtest/gut/test_key_mapping_load_regression.gdtest/gut/test_all_menus_navigation_regression.gd.uidtest/gut/test_device_toggle_audio_regression.gd.uidtest/gut/test_key_mapping_load_regression.gd.uid |
| Refine key_mapping menu initialization and device-toggle audio behavior to avoid spurious sounds while providing explicit confirmation feedback. |
|
scripts/ui/menus/key_mapping.gdtest/gut/test_device_toggle_audio_regression.gdtest/gut/test_key_mapping_load_regression.gd |
| Document the centralized UI SFX configuration and new audio integrity/regression test suites as part of Milestone 21. |
|
files/docs/milestones/21/Part_10_Centralize_UI_SFX_configuration_&_add_audio_integrity_tests.md |
Assessment against linked issues
| Issue | Objective | Addressed | Explanation |
|---|---|---|---|
| #490 | Decouple global UI input handling from Globals by introducing a UiManager singleton that intercepts input, tracks the active device, evaluates menu context, and triggers navigation/cancel SFX, while removing the input/SFX logic from Globals.gd. | ✅ | |
| #490 | Centralize UI SFX configuration and routing by using AudioConstants for SFX paths and navigation action lists, and ensure global UI navigation/cancel and device-toggle sounds are played via AudioManager using the appropriate SFX buses. | ✅ | |
| #490 | Update and expand test coverage to validate the decoupled UiManager input pipeline, audio constants integrity, menu navigation SFX across all menus (including paused states), device toggle audio behavior, and silent initialization of the key mapping menu. | ✅ | |
| #801 | Port global button pressed audio callback logic from globals.gd to audio_manager.gd and adapt it to use AudioManager's pooled playback (_sfx_pool) with centralized SFX configuration (AudioConstants.SFX_DIR_PATH, UI_SFX, BUS_SFX_MENU). | ✅ | |
| #801 | Migrate the global UI input listener loop and input-device tracking out of globals.gd into a dedicated UiManager singleton, routing UI navigation/accept/cancel SFX via AudioManager and AudioConstants, and keeping it active even when the SceneTree is paused. | ✅ | |
| #801 | Update legacy references across the codebase (including tests) that called Globals._on_node_added, Globals._on_global_button_pressed, or Globals._input so they now target AudioManager and UiManager equivalents instead. | ✅ | |
| #802 | Purge legacy UI audio/input handling and deprecated hooks/constants from globals.gd (including removal of UI_NAV_SOUND_PATH usage and moving global input/SFX logic out of the globals singleton so no dead UI audio code remains there). | ✅ | |
| #802 | Centralize SFX asset path configuration and UI navigation SFX handling into dedicated resources/managers (e.g., AudioConstants, AudioManager, UiManager), with code using the centralized constants rather than legacy globals. | ✅ | |
| #802 | Strengthen and document automated test coverage for global UI audio behavior and configuration (GUT tests for audio constants, navigation/cancel SFX, menu/device toggle regression, and milestone documentation reflecting this verification). | ✅ | |
| #828 | Ensure that toggling the Keyboard device CheckButton in the Key Mapping / Controls menu plays the check.wav confirmation sound via the audio system. | ✅ | |
| #828 | Ensure that toggling the Gamepad device CheckButton in the Key Mapping / Controls menu plays the check.wav confirmation sound via the audio system. | ✅ |
Possibly linked issues
- #490: PR delivers EPIC #490: adds UiManager, centralized AudioConstants-based UI SFX, reroutes input, and comprehensive audio tests.
Bots/AI Contributions Summary for PR #827
This PR received significant support from AI-powered code review and automation bots that provided summaries, feedback, reviews, and testing prompts.
AI / Bot Contributors
- @sourcery-ai — Generated the main PR summary, Reviewer's Guide, and left detailed code review comments (e.g., suggestions around
UI_NAV_SOUND_PATHreplacement and discoverability). Offered commands for further interactions like@sourcery-ai reviewor@sourcery-ai summary. - @coderabbitai — Contributed finishing touches, unit test generation suggestions, and overall code review assistance (highlighted in the PR conversation with thanks for OSS support).
- @deepsource-io (DeepSource Code Review / DeepsourceReview) — Performed automated static analysis and code review on the changes (covering commits including
d6b9071...0155c0c). Provided a PR Report Card with grades for Security, Reliability, Complexity, and Hygiene, plus inline issue comments.
(No visible contributions from @dependabot or similar dependency bots in this PR.)
@ikostan Contributions (Human Maintainer)
@ikostan is the sole human author and primary contributor:
- Authored and iterated on all code changes through multiple commits.
- Core work:
- Centralized SFX directory configuration (
SFX_DIR_PATH) inscripts/resources/audio_constants.gd. - Updated path resolution logic in
scripts/managers/audio_manager.gd. - Added a full GUT test suite (
test/gut/test_audio_constants_discoverability.gd) validating constants, asset maps, bus configs, and referential integrity.
- Centralized SFX directory configuration (
- Drove the PR forward, applied bot feedback, added labels/milestone, and triggered bot reviews.
These bot contributions helped refine the code quality, documentation, and test coverage while @ikostan handled the architectural implementation.