Support full controller input

This commit is contained in:
2024-11-05 00:07:48 -05:00
parent 75fa3be25c
commit 5c5d56cb12
7 changed files with 109 additions and 21 deletions
+9 -11
View File
@@ -9,13 +9,13 @@ use winit::platform::windows::{CornerPreference, WindowAttributesExtWindows as _
use winit::{
application::ApplicationHandler,
dpi::{LogicalSize, PhysicalSize},
event::{ElementState, Event, WindowEvent},
event::{Event, WindowEvent},
event_loop::ActiveEventLoop,
keyboard::Key,
window::Window,
};
use crate::{
controller::ControllerState,
emulator::{EmulatorClient, EmulatorCommand},
renderer::GameRenderer,
};
@@ -270,13 +270,17 @@ impl AppWindow {
pub struct App {
window: Option<AppWindow>,
client: EmulatorClient,
controller: ControllerState,
}
impl App {
pub fn new(client: EmulatorClient) -> Self {
let controller = ControllerState::new();
client.send_command(EmulatorCommand::SetKeys(controller.pressed()));
Self {
window: None,
client,
controller,
}
}
}
@@ -305,15 +309,9 @@ impl ApplicationHandler for App {
}
WindowEvent::CloseRequested => event_loop.exit(),
WindowEvent::KeyboardInput { event, .. } => {
if let Key::Character("s") = event.logical_key.as_ref() {
match event.state {
ElementState::Pressed => {
self.client.send_command(EmulatorCommand::PressStart)
}
ElementState::Released => {
self.client.send_command(EmulatorCommand::ReleaseStart)
}
}
if self.controller.key_event(event) {
self.client
.send_command(EmulatorCommand::SetKeys(self.controller.pressed()));
}
}
WindowEvent::RedrawRequested => {