Skip to content

Refactor: Implement Input Action Mapping System #148

Description

@MichaelFisher1997

Problem Statement

Input handling is tightly coupled to specific hardware keys (e.g., input.isKeyDown(.w)) throughout Player.zig, App.zig, and menus.zig. This makes key rebinding and gamepad support impossible without rewriting gameplay logic.

Proposed Architecture

Introduce an abstraction layer for Input Actions:

  1. Define Logical Actions: Create an enum GameAction (e.g., MoveForward, Jump, Inventory, MenuBack).
  2. InputMapper: A new struct responsible for mapping physical inputs (Key, MouseButton, GamepadButton) to logical GameActions.
  3. Update Usage: Refactor gameplay code to query input.isActionPressed(.Jump) instead of checking specific keys.

Benefits

  • Rebinding Support: Users can customize controls.
  • Hardware Agnostic: Seamlessly support Keyboard, Mouse, and Gamepad via a unified interface.
  • Clean Code (DIP): Gameplay logic depends on high-level intents, not low-level hardware details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions