Support full controller input
This commit is contained in:
+9
-11
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user