From ca4067406c39a4ee1a6063d793d37842196aadc9 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Sat, 22 Mar 2025 22:59:04 -0500 Subject: [PATCH] flip inputs --- crates/client/src/networking/mod.rs | 1 - crates/client/src/rendering/mod.rs | 66 ++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/crates/client/src/networking/mod.rs b/crates/client/src/networking/mod.rs index 047d421d2cca8f1d90a0b44433e301317a868f3e..c267da5de520ad5b7c59c592786931820fa1ce4a 100644 --- a/crates/client/src/networking/mod.rs +++ b/crates/client/src/networking/mod.rs @@ -44,7 +44,6 @@ pub fn process_packets( LandingThrusterSuspension => "landingleg.svg", }.to_string() }, ServerId(*id), Part)); - tracing::info!("here"); } PartPositions { parts } => { for (id, part) in parts { diff --git a/crates/client/src/rendering/mod.rs b/crates/client/src/rendering/mod.rs index b5022237a3592490e8bd681c77b60c467fd9a507..590de82a79a0203c90ac37314c897b2d59ee9e27 100644 --- a/crates/client/src/rendering/mod.rs +++ b/crates/client/src/rendering/mod.rs @@ -14,13 +14,15 @@ use glutin::surface::{Surface, WindowSurface, GlSurface, SwapInterval}; use glutin::{config::{ConfigTemplateBuilder, GlConfig}, context::{ContextApi, ContextAttributesBuilder, PossiblyCurrentContext}, display::GetGlDisplay, prelude::{GlDisplay, NotCurrentGlContext}}; #[cfg(not(target_arch = "wasm32"))] use glutin_winit::{DisplayBuilder, GlWindow}; +use starkingdoms_common::packet::Packet; use starkingdoms_common::PlanetType; #[cfg(target_arch = "wasm32")] use wasm_bindgen::{prelude::Closure, JsCast}; #[cfg(target_arch = "wasm32")] use web_sys::{Event, HtmlCanvasElement}; -use winit::event::MouseScrollDelta; +use winit::event::{ElementState, MouseScrollDelta}; use winit::event_loop::ControlFlow; +use winit::keyboard::{KeyCode, PhysicalKey}; #[cfg(target_arch = "wasm32")] use winit::platform::web::{WindowAttributesExtWebSys, WindowExtWebSys}; use winit::{application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, event_loop::ActiveEventLoop, raw_window_handle::HasWindowHandle, window::{Window, WindowAttributes}}; @@ -55,6 +57,11 @@ pub struct App { send_packet_events: Events, recv_packet_events: Events, planet_types: HashMap, // (world entity, server id) + + up: bool, + down: bool, + left: bool, + right: bool, } const VERTICES: [f32; 16] = [ @@ -259,6 +266,62 @@ impl ApplicationHandler for App { camera.zoom *= delta; } } + WindowEvent::KeyboardInput { ref event, .. } => { + match event.physical_key { + PhysicalKey::Code(key) => { + let matched: bool; + match event.state { + ElementState::Pressed => match key { + KeyCode::KeyW => { + self.up = true; + matched = true; + } + KeyCode::KeyS => { + self.down = true; + matched = true; + } + KeyCode::KeyA => { + self.left = true; + matched = true; + } + KeyCode::KeyD => { + self.right = true; + matched = true; + } + _ => matched = false + } + ElementState::Released => match key { + KeyCode::KeyW => { + self.up = false; + matched = true; + } + KeyCode::KeyS => { + self.down = false; + matched = true; + } + KeyCode::KeyA => { + self.left = false; + matched = true; + } + KeyCode::KeyD => { + self.right = false; + matched = true; + } + _ => matched = false + } + } + if matched { + self.send_packet_events.send(SendPacket(Packet::PlayerInput { + up: self.down, + down: self.up, + left: self.right, + right: self.left, + })); + } + } + PhysicalKey::Unidentified(_) => {} // unsupported + } + } _ => {} } let event_response = self.egui_glow.as_mut().unwrap() @@ -335,7 +398,6 @@ impl ApplicationHandler for App { glow::UNSIGNED_BYTE, PixelUnpackData::Slice(Some(&image.bytes))); gl.generate_mipmap(glow::TEXTURE_2D); - tracing::info!("{}", texture.name); self.textures.insert(texture.name.clone(), texture_object); } // now the texture must exist