From 11684b80a9d8e782fbda65b6d3525466e7df3e34 Mon Sep 17 00:00:00 2001 From: PROMETHIA-27 <42193387+PROMETHIA-27@users.noreply.github.com> Date: Wed, 8 Oct 2025 18:54:39 -0400 Subject: [PATCH] move clientside gated parts of `control` to the client (#70) --- .../src/control/controls.rs | 79 +++++---------- crates/client/src/control/mod.rs | 28 ++++++ crates/client/src/main.rs | 2 + crates/client/src/ui/pause.rs | 4 +- .../shared/src/control/controller_common.rs | 2 +- .../shared/src/control/controller_running.rs | 2 +- crates/shared/src/control/mod.rs | 99 +++++++++---------- crates/shared/src/protocol/mod.rs | 3 +- 8 files changed, 104 insertions(+), 115 deletions(-) rename crates/{shared => client}/src/control/controls.rs (87%) create mode 100644 crates/client/src/control/mod.rs diff --git a/crates/shared/src/control/controls.rs b/crates/client/src/control/controls.rs similarity index 87% rename from crates/shared/src/control/controls.rs rename to crates/client/src/control/controls.rs index f2f45dd..7633a50 100644 --- a/crates/shared/src/control/controls.rs +++ b/crates/client/src/control/controls.rs @@ -1,21 +1,15 @@ -use super::{ControlState, Controls}; -#[cfg(feature = "client")] -use crate::control::ControllerSet; +use super::Controls; use crate::{GameState, control::CharacterInputEnabled}; -#[cfg(feature = "client")] use bevy::input::{ ButtonState, gamepad::{GamepadConnection, GamepadEvent}, mouse::{MouseButtonInput, MouseMotion}, }; use bevy::prelude::*; -#[cfg(feature = "client")] use lightyear::input::client::InputSet; -#[cfg(feature = "client")] use lightyear::prelude::input::native::{ActionState, InputMarker}; -use serde::{Deserialize, Serialize}; +use shared::control::{ControlState, ControllerSet}; use std::collections::HashMap; -#[cfg(feature = "client")] use std::hash::Hash; pub fn plugin(app: &mut App) { @@ -24,37 +18,32 @@ pub fn plugin(app: &mut App) { app.register_required_components::>(); - app.register_type::(); - app.add_systems(PreUpdate, (cache_keyboard_state, cache_gamepad_state)); - #[cfg(feature = "client")] - { - app.add_systems( - FixedPreUpdate, - ( - gamepad_controls, - keyboard_controls, - mouse_rotate, - mouse_click, - gamepad_connections.run_if(on_event::), - combine_controls, - clear_keyboard_state, - clear_gamepad_state, - ) - .chain() - .in_set(ControllerSet::CollectInputs) - .before(InputSet::WriteClientInputs) - .run_if( - in_state(GameState::Playing) - .and(resource_exists_and_equals(CharacterInputEnabled::On)), - ), + app.add_systems( + FixedPreUpdate, + ( + gamepad_controls, + keyboard_controls, + mouse_rotate, + mouse_click, + gamepad_connections.run_if(on_event::), + combine_controls, + clear_keyboard_state, + clear_gamepad_state, ) - .add_systems( - FixedPreUpdate, - buffer_inputs.in_set(InputSet::WriteClientInputs), - ); - } + .chain() + .in_set(ControllerSet::CollectInputs) + .before(InputSet::WriteClientInputs) + .run_if( + in_state(GameState::Playing) + .and(resource_exists_and_equals(CharacterInputEnabled::On)), + ), + ) + .add_systems( + FixedPreUpdate, + buffer_inputs.in_set(InputSet::WriteClientInputs), + ); app.add_systems( Update, @@ -62,14 +51,6 @@ pub fn plugin(app: &mut App) { ); } -#[derive(Component, Clone, PartialEq, Reflect, Serialize, Deserialize)] -#[reflect(Component)] -pub struct ControllerSettings { - pub deceleration_factor: f32, - pub jump_force: f32, -} - -#[cfg(feature = "client")] /// Write inputs from combined keyboard/gamepad state into the networked input buffer /// for the local player. fn buffer_inputs( @@ -104,7 +85,6 @@ impl