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