Switch to replicon (#80)

This commit is contained in:
PROMETHIA-27
2025-12-08 19:22:17 -05:00
committed by GitHub
parent 7a5d2e6914
commit ff52258ad2
55 changed files with 1212 additions and 2951 deletions

View File

@@ -8,10 +8,6 @@ use bevy::{
},
prelude::*,
};
use lightyear::{
input::client::InputSystems,
prelude::input::native::{ActionState, InputMarker},
};
use shared::{
control::{ControllerSet, LookDirMovement},
player::PlayerBodyMesh,
@@ -27,7 +23,7 @@ pub fn plugin(app: &mut App) {
app.add_systems(PreUpdate, (cache_keyboard_state, cache_gamepad_state));
app.add_systems(
FixedPreUpdate,
PreUpdate,
(
reset_lookdir,
gamepad_controls,
@@ -39,18 +35,14 @@ pub fn plugin(app: &mut App) {
get_lookdir,
clear_keyboard_just,
clear_gamepad_just,
send_inputs,
)
.chain()
.in_set(ControllerSet::CollectInputs)
.before(InputSystems::WriteClientInputs)
.run_if(
in_state(GameState::Playing)
.and(resource_exists_and_equals(CharacterInputEnabled::On)),
),
)
.add_systems(
FixedPreUpdate,
buffer_inputs.in_set(InputSystems::WriteClientInputs),
);
app.add_systems(
@@ -61,11 +53,8 @@ pub fn plugin(app: &mut App) {
/// Write inputs from combined keyboard/gamepad state into the networked input buffer
/// for the local player.
fn buffer_inputs(
mut player: Single<&mut ActionState<ControlState>, With<InputMarker<ControlState>>>,
controls: Res<ControlState>,
) {
player.0 = *controls;
fn send_inputs(mut writer: MessageWriter<ControlState>, controls: Res<ControlState>) {
writer.write(*controls);
}
fn reset_lookdir(mut look_dir: ResMut<LookDirMovement>) {
@@ -177,7 +166,7 @@ fn combine_controls(controls: Res<Controls>, mut combined_controls: ResMut<Contr
let keyboard = controls.keyboard_state;
let gamepad = controls.gamepad_state.unwrap_or_default();
combined_controls.look_dir = Dir3::NEG_Z;
combined_controls.look_dir = Vec3::NEG_Z;
combined_controls.move_dir = gamepad.move_dir + keyboard.move_dir;
combined_controls.jump = gamepad.jump | keyboard.jump;
combined_controls.view_mode = gamepad.view_mode | keyboard.view_mode;
@@ -197,9 +186,9 @@ fn get_lookdir(
rig_transform: Option<Single<&GlobalTransform, With<PlayerBodyMesh>>>,
) {
controls.look_dir = if let Some(ref rig_transform) = rig_transform {
rig_transform.forward()
rig_transform.forward().as_vec3()
} else {
Dir3::NEG_Z
Vec3::NEG_Z
};
}
@@ -252,7 +241,7 @@ fn gamepad_controls(
let state = ControlState {
move_dir,
look_dir: Dir3::NEG_Z,
look_dir: Vec3::NEG_Z,
jump: gamepad.pressed(GamepadButton::South),
view_mode: gamepad.pressed(GamepadButton::LeftTrigger2),
trigger: gamepad.pressed(GamepadButton::RightTrigger2),