From 325066326e5a8fade9adf40c59bec94fe694c9ee Mon Sep 17 00:00:00 2001 From: extrawurst Date: Sat, 15 Mar 2025 23:33:24 +0100 Subject: [PATCH] special case gamepad --- src/controls.rs | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/controls.rs b/src/controls.rs index 5b49636..ec0e3f9 100644 --- a/src/controls.rs +++ b/src/controls.rs @@ -1,6 +1,7 @@ use bevy::{ input::{ ButtonState, + gamepad::{GamepadConnection, GamepadEvent}, mouse::{MouseButtonInput, MouseMotion}, }, prelude::*, @@ -27,6 +28,7 @@ pub fn plugin(app: &mut App) { app.add_systems(PreUpdate, clear_mouse_delta); app.add_systems(Update, (gamepad_controls, keyboard_controls, mouse_rotate)); app.add_systems(Update, mouse_click.run_if(on_event::)); + app.add_systems(Update, gamepad_connections.run_if(on_event::)); } fn gamepad_controls( @@ -49,9 +51,9 @@ fn gamepad_controls( const EPSILON: f32 = 0.015; - let state = ControlState { - move_dir: gamepad.left_stick(), - look_dir: Vec2::new( + //8BitDo Ultimate wireless Controller for PC + let look_dir = if gamepad.vendor_id() == Some(11720) && gamepad.product_id() == Some(12306) { + Vec2::new( if rotate < 0.5 - EPSILON { 40. * (rotate - 0.5) } else if rotate > 0.5 + EPSILON { @@ -60,7 +62,14 @@ fn gamepad_controls( 0. }, 0., - ), + ) + } else { + gamepad.right_stick() * 40. + }; + + let state = ControlState { + move_dir: gamepad.left_stick(), + look_dir, jump: gamepad.pressed(GamepadButton::South), }; @@ -133,3 +142,27 @@ fn mouse_click(mut events: EventReader, mut commands: Commands } } } + +fn gamepad_connections(mut evr_gamepad: EventReader) { + for ev in evr_gamepad.read() { + // we only care about connection events + let GamepadEvent::Connection(ev_conn) = ev else { + continue; + }; + match &ev_conn.connection { + GamepadConnection::Connected { + name, + vendor_id, + product_id, + } => { + info!( + "New gamepad connected: {:?}, name: {name}, vendor: {vendor_id:?}, product: {product_id:?}", + ev_conn.gamepad + ); + } + GamepadConnection::Disconnected => { + info!("Lost connection with gamepad: {:?}", ev_conn.gamepad); + } + } + } +}