Client/Server Feature Split (#63)
This commit is contained in:
@@ -15,7 +15,6 @@ use crate::{
|
||||
npc::SpawnCharacter,
|
||||
sounds::PlaySound,
|
||||
tb_entities::SpawnPoint,
|
||||
utils::commands::EntityCommandExt,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{
|
||||
@@ -23,9 +22,9 @@ use bevy::{
|
||||
prelude::*,
|
||||
window::{CursorGrabMode, PrimaryWindow},
|
||||
};
|
||||
use lightyear::prelude::{
|
||||
ControlledBy, Lifetime, NetworkTarget, PredictionTarget, Replicate, input::native::ActionState,
|
||||
};
|
||||
use lightyear::prelude::input::native::ActionState;
|
||||
#[cfg(feature = "server")]
|
||||
use lightyear::prelude::{ControlledBy, Lifetime, NetworkTarget, PredictionTarget, Replicate};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Component, Default, Serialize, Deserialize, PartialEq)]
|
||||
@@ -53,7 +52,7 @@ pub fn plugin(app: &mut App) {
|
||||
|
||||
pub fn spawn(
|
||||
mut commands: Commands,
|
||||
owner: Entity,
|
||||
#[cfg(feature = "server")] owner: Entity,
|
||||
query: Query<&Transform, With<SpawnPoint>>,
|
||||
asset_server: Res<AssetServer>,
|
||||
heads_db: Res<HeadsDatabase>,
|
||||
@@ -64,17 +63,18 @@ pub fn spawn(
|
||||
|
||||
let transform = Transform::from_translation(spawn.translation + Vec3::new(0., 3., 0.));
|
||||
|
||||
commands
|
||||
.spawn(player_bundle(transform, &heads_db))
|
||||
.insert_server((
|
||||
Replicate::to_clients(NetworkTarget::All),
|
||||
PredictionTarget::to_clients(NetworkTarget::All),
|
||||
ControlledBy {
|
||||
owner,
|
||||
lifetime: Lifetime::SessionBased,
|
||||
},
|
||||
))
|
||||
.observe(on_kill);
|
||||
let mut player = commands.spawn(player_bundle(transform, &heads_db));
|
||||
player.observe(on_kill);
|
||||
|
||||
#[cfg(feature = "server")]
|
||||
player.insert((
|
||||
Replicate::to_clients(NetworkTarget::All),
|
||||
PredictionTarget::to_clients(NetworkTarget::All),
|
||||
ControlledBy {
|
||||
owner,
|
||||
lifetime: Lifetime::SessionBased,
|
||||
},
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/heads/angry demonstrator.ogg")),
|
||||
|
||||
Reference in New Issue
Block a user