//! Keyboard input state.

/// Keyboard input state tracking key presses.
#[derive(Default)]
pub struct Keyboard {
    /// Current state of each key (pressed or released).
    pub keystates: std::collections::HashMap<winit::keyboard::KeyCode, winit::event::ElementState>,
    /// Characters typed this frame (for text input).
    pub frame_chars: Vec<char>,
    /// Keys pressed/released this frame as (keycode, is_pressed) pairs.
    pub frame_keys: Vec<(winit::keyboard::KeyCode, bool)>,
}

impl Keyboard {
    /// Returns true if the specified key is currently held down.
    pub fn is_key_pressed(&self, keycode: winit::keyboard::KeyCode) -> bool {
        self.keystates
            .get(&keycode)
            .is_some_and(|state| *state == winit::event::ElementState::Pressed)
    }

    /// Clears per-frame input (called at frame start).
    pub fn clear_frame_input(&mut self) {
        self.frame_chars.clear();
        self.frame_keys.clear();
    }
}
