Feature/input bindings contexts - #37
Conversation
Qodana Community for JVM9 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at qodana-support@jetbrains.com
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a context-based command input system that decouples raw keystroke handling from game logic, making input handling more maintainable and allowing each game state to define its own key-to-command mappings. The refactor replaces direct KeyStroke processing with semantic InputCommand handling throughout the engine and game states.
- Adds core input abstractions (InputCommand enum, KeyBinding record, InputContext interface, InputResult wrapper)
- Implements three state-specific input contexts (MainMenu, Gameplay, Pause) with their own key bindings
- Refactors all game states to use command-based input via InputManager.pollCommand()
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/resources/logging.properties | Changed logging level from WARNING to INFO for increased development visibility |
| src/main/java/net/luxsolari/engine/input/InputCommand.java | Added enum defining all game commands (navigation, gameplay, debug, audio, UI) |
| src/main/java/net/luxsolari/engine/input/KeyBinding.java | Added immutable record for key bindings with modifier support and case-normalization |
| src/main/java/net/luxsolari/engine/input/InputContext.java | Added interface for state-specific key-to-command mapping |
| src/main/java/net/luxsolari/engine/input/InputResult.java | Added wrapper record containing raw keystroke and resolved command |
| src/main/java/net/luxsolari/engine/manager/InputManager.java | Extended manager to support context management and command-based polling |
| src/main/java/net/luxsolari/game/input/MainMenuInputContext.java | Added main menu key bindings (navigation, quit, confirm) |
| src/main/java/net/luxsolari/game/input/GameplayInputContext.java | Added gameplay key bindings (blackjack actions, debug, audio controls) |
| src/main/java/net/luxsolari/game/input/PauseInputContext.java | Added pause menu key bindings (resume, back to menu, navigation) |
| src/main/java/net/luxsolari/game/states/MainMenuState.java | Refactored to set input context and use pollCommand() instead of raw keystrokes |
| src/main/java/net/luxsolari/game/states/GameplayState.java | Refactored to use command-based input handling with switch on InputCommand |
| src/main/java/net/luxsolari/game/states/PauseState.java | Refactored to use command-based input with state-level command handling |
| src/main/java/net/luxsolari/engine/ui/Menu.java | Added handleCommand() method for semantic command-based menu navigation |
| src/main/java/net/luxsolari/engine/systems/internal/InputSubsystem.java | Changed from blocking readInput() to non-blocking pollInput() |
|
@luxsolari I've opened a new pull request, #38, to work on those changes. Once the pull request is ready, I'll request review from you. |
Pull Request Review: Feature/Input Bindings ContextsSummaryThis PR introduces a well-architected command-based input system that decouples raw keystroke handling from game logic. The refactor provides a clean, extensible foundation for context-sensitive input handling. Overall, this is high-quality work with good design patterns and documentation. ✅ StrengthsArchitecture & Design
Code Quality
|
…ty in InputManager
Pull Request Review: Feature/input bindings contextsOverviewThis PR introduces a well-architected command-based input system that significantly improves the maintainability and extensibility of input handling across the game. The refactoring successfully decouples raw keystroke handling from game logic by introducing semantic commands and context-specific key mappings. ✅ Strengths1. Excellent Architecture & Design Patterns
2. Code Quality
3. State Management Integration
4. User Experience Improvements
|
| Category | Rating | Notes |
|---|---|---|
| Architecture | ⭐⭐⭐⭐⭐ | Excellent use of design patterns |
| Code Quality | ⭐⭐⭐⭐☆ | Very clean, minor issues noted |
| Security | ⭐⭐⭐⭐⭐ | No concerns |
| Performance | ⭐⭐⭐⭐⭐ | Efficient implementation |
| Test Coverage | ⭐☆☆☆☆ | No tests present |
| Documentation | ⭐⭐⭐⭐☆ | Good JavaDoc, could add design docs |
🎯 Verdict
Recommendation: ✅ Approve with minor changes
This is a solid refactoring that significantly improves the codebase. The critical NPE issue should be fixed before merging, but otherwise this is production-ready code.
Required Changes:
- Fix the null pointer exception risk in
InputManager.pollCommand()
Suggested Changes (non-blocking):
- Add unit tests for the new input system
- Standardize KeyBinding creation across input contexts
- Review key binding choices for consistency with user expectations
- Add architecture documentation
Great work on this refactoring! The command-based input system is a significant improvement that will make future development much easier.
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com
Pull Request Review: Input Bindings & ContextsOverall AssessmentThis is a well-designed refactor that introduces a clean abstraction layer for input handling. The command pattern implementation successfully decouples game logic from raw keystroke handling, making the codebase more maintainable and extensible. The code quality is high with good documentation and naming conventions. ✅ Strengths1. Excellent Architecture Design
2. Code Quality
3. Good Integration
|
…nd architecture details
Pull Request Review: Feature/input bindings contextsOverviewThis PR introduces a well-architected command-based input system that successfully decouples input handling from game logic. The implementation follows solid design principles and integrates cleanly with the existing codebase. ✅ StrengthsArchitecture & Design
Code Quality
Integration
|
Pull Request Review: Feature/input bindings contextsSummaryThis PR introduces a well-architected command-based input system that successfully decouples raw keystroke handling from game logic. The implementation follows solid design principles and significantly improves the maintainability and extensibility of input handling across the game engine. ✅ StrengthsArchitecture & Design
Code Quality
Integration
|
This pull request introduces a new, context-based command input system for the game engine, allowing game states to define their own key-to-command mappings and handle user input at a higher semantic level. The changes decouple raw keystroke handling from game logic, making input handling more maintainable, extensible, and testable. Three new input context classes are added for main menu, gameplay, and pause states, and the core input flow is refactored to use commands instead of raw keystrokes.
Core Input System Refactor:
InputCommandenum to represent all possible game commands, such as navigation, game actions, debug, audio, and UI commands.KeyBindingrecord to encapsulate key strokes with modifiers, and provide static constructors for common key binding patterns.InputContextinterface, allowing each game state to define its own key-to-command mapping.InputResultrecord to wrap both the raw keystroke and the resolved command for each input event.InputManagerto manage the current input context, providepollCommand()for high-level input, and allow states to set/reset their context.Game State Integration:
MainMenuInputContext,GameplayInputContext, andPauseInputContext, each specifying key-to-command mappings for their respective states. [1] [2] [3]MainMenuStateandGameplayStateto set/reset their input context on start/resume, and to useInputManager.pollCommand()for handling input. [1] [2] [3] [4] [5] [6]handleInput()methods to process semantic commands instead of raw keystrokes, delegating menu navigation to the new command-based API. [1] [2]UI and Menu Improvements:
handleCommand(InputCommand)method to theMenuclass, enabling menus to respond to high-level navigation and action commands.Subsystem and Internal Adjustments:
InputSubsystemto use non-blockingpollInput()instead ofreadInput().These changes lay the groundwork for a more robust, extensible, and context-aware input system across the game engine.