47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use std::collections::HashSet;
|
|
use winit::keyboard::KeyCode;
|
|
|
|
pub struct InputState {
|
|
pub keys_held: HashSet<KeyCode>,
|
|
pub mouse_locked: bool,
|
|
|
|
// Touch input (read from JS on WASM)
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_move_x: f32,
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_move_z: f32,
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_y_up: bool,
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_y_down: bool,
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_look_dx: f32,
|
|
#[cfg(target_arch = "wasm32")]
|
|
pub touch_look_dy: f32,
|
|
}
|
|
|
|
impl InputState {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
keys_held: HashSet::new(),
|
|
mouse_locked: false,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_move_x: 0.0,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_move_z: 0.0,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_y_up: false,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_y_down: false,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_look_dx: 0.0,
|
|
#[cfg(target_arch = "wasm32")]
|
|
touch_look_dy: 0.0,
|
|
}
|
|
}
|
|
|
|
pub fn is_pressed(&self, key: KeyCode) -> bool {
|
|
self.keys_held.contains(&key)
|
|
}
|
|
}
|