make player and client bound together
this cleansup and allows rejoining a running server
This commit is contained in:
@@ -14,7 +14,7 @@ use shared::{
|
|||||||
hitpoints::{Hitpoints, Kill},
|
hitpoints::{Hitpoints, Kill},
|
||||||
npc::SpawnCharacter,
|
npc::SpawnCharacter,
|
||||||
player::{Player, PlayerBodyMesh},
|
player::{Player, PlayerBodyMesh},
|
||||||
protocol::{PlaySound, PlayerId, events::ClientHeadChanged},
|
protocol::{OwnedByClient, PlaySound, PlayerId, events::ClientHeadChanged},
|
||||||
tb_entities::SpawnPoint,
|
tb_entities::SpawnPoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -24,7 +24,7 @@ pub fn plugin(app: &mut App) {
|
|||||||
|
|
||||||
pub fn spawn(
|
pub fn spawn(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
_owner: Entity,
|
owner: Entity,
|
||||||
query: Query<&Transform, With<SpawnPoint>>,
|
query: Query<&Transform, With<SpawnPoint>>,
|
||||||
heads_db: Res<HeadsDatabase>,
|
heads_db: Res<HeadsDatabase>,
|
||||||
) -> Option<Entity> {
|
) -> Option<Entity> {
|
||||||
@@ -58,6 +58,7 @@ pub fn spawn(
|
|||||||
UiActiveHeads::default(),
|
UiActiveHeads::default(),
|
||||||
Inputs::default(),
|
Inputs::default(),
|
||||||
Replicated,
|
Replicated,
|
||||||
|
OwnedByClient(owner),
|
||||||
))
|
))
|
||||||
.with_children(|c| {
|
.with_children(|c| {
|
||||||
c.spawn((
|
c.spawn((
|
||||||
|
|||||||
@@ -189,3 +189,11 @@ impl TbMapIdCounter {
|
|||||||
#[derive(Resource, Reflect, Default, Deref, DerefMut)]
|
#[derive(Resource, Reflect, Default, Deref, DerefMut)]
|
||||||
#[reflect(Resource)]
|
#[reflect(Resource)]
|
||||||
pub struct TbMapEntityMapping(pub HashMap<u64, Entity>);
|
pub struct TbMapEntityMapping(pub HashMap<u64, Entity>);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[relationship(relationship_target = ClientOwns)]
|
||||||
|
pub struct OwnedByClient(pub Entity);
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
#[relationship_target(relationship = OwnedByClient, linked_spawn)]
|
||||||
|
pub struct ClientOwns(Entity);
|
||||||
|
|||||||
Reference in New Issue
Block a user