goud_engine/core/input_manager/mod.rs
1//! Input management system for ECS integration.
2//!
3//! The `InputManager` resource provides a centralized interface for querying input state
4//! within the ECS. It tracks keyboard keys, mouse buttons, mouse position, and gamepad state
5//! across frames, enabling queries for:
6//! - Current state (is pressed)
7//! - Just pressed (pressed this frame, not last frame)
8//! - Just released (released this frame, was pressed last frame)
9//!
10//! # Architecture
11//!
12//! The InputManager sits between the platform layer (GLFW) and the game systems:
13//!
14//! ```text
15//! GLFW Events → InputHandler → InputManager → Game Systems
16//! (platform) (ECS resource) (queries)
17//! ```
18//!
19//! # Usage
20//!
21//! ## Raw Input Queries
22//!
23//! ```ignore
24//! use goud_engine::ecs::{InputManager, Resource};
25//! use glfw::Key;
26//!
27//! // In your setup system:
28//! world.insert_resource(InputManager::new());
29//!
30//! // In a system:
31//! fn player_movement_system(input: Res<InputManager>) {
32//! if input.key_pressed(Key::W) {
33//! // Move forward continuously while held
34//! }
35//! if input.key_just_pressed(Key::Space) {
36//! // Jump only once per press
37//! }
38//! }
39//! ```
40//!
41//! ## Action Mapping
42//!
43//! Action mapping allows semantic names for input, supporting multiple bindings:
44//!
45//! ```ignore
46//! use goud_engine::ecs::{InputManager, InputBinding};
47//! use glfw::Key;
48//!
49//! let mut input = InputManager::new();
50//!
51//! // Map "Jump" to Space, W key, or gamepad button 0
52//! input.map_action("Jump", InputBinding::Key(Key::Space));
53//! input.map_action("Jump", InputBinding::Key(Key::W));
54//! input.map_action("Jump", InputBinding::GamepadButton { gamepad_id: 0, button: 0 });
55//!
56//! // Query action state (returns true if ANY binding is pressed)
57//! if input.action_pressed("Jump") {
58//! player.jump();
59//! }
60//!
61//! if input.action_just_pressed("Attack") {
62//! player.attack();
63//! }
64//! ```
65//!
66//! # Frame Management
67//!
68//! Call `update()` at the start of each frame to advance the input state:
69//!
70//! ```ignore
71//! fn input_update_system(mut input: ResMut<InputManager>) {
72//! input.update();
73//! }
74//! ```
75
76mod actions;
77mod buffer;
78mod gamepad;
79mod manager;
80mod types;
81
82#[cfg(test)]
83mod tests;
84
85pub use manager::InputManager;
86pub use types::InputBinding;