Synchronize Trenchbroom map entities (#65)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use crate::{cash::Cash, loading_assets::GameAssets, physics_layers::GameLayer};
|
||||
use crate::{
|
||||
cash::Cash, loading_assets::GameAssets, physics_layers::GameLayer, protocol::TbMapIdCounter,
|
||||
};
|
||||
use avian3d::prelude::*;
|
||||
use bevy::{
|
||||
ecs::{component::HookContext, world::DeferredWorld},
|
||||
@@ -7,6 +9,7 @@ use bevy::{
|
||||
};
|
||||
use bevy_trenchbroom::prelude::*;
|
||||
use happy_feet::prelude::PhysicsMover;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
#[derive(PointClass, Component, Reflect, Default)]
|
||||
@@ -72,7 +75,7 @@ pub struct PlatformTarget {
|
||||
pub targetname: String,
|
||||
}
|
||||
|
||||
#[derive(SolidClass, Component, Reflect, Default)]
|
||||
#[derive(SolidClass, Component, Reflect, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[reflect(QuakeClass, Component)]
|
||||
#[base(Transform, Target)]
|
||||
#[spawn_hooks(SpawnHooks::new().convex_collider())]
|
||||
@@ -202,4 +205,15 @@ pub fn plugin(app: &mut App) {
|
||||
app.register_type::<EnemySpawn>();
|
||||
app.register_type::<CashSpawn>();
|
||||
app.register_type::<SecretHead>();
|
||||
|
||||
app.add_observer(tb_component_setup::<CashSpawn>);
|
||||
app.add_observer(tb_component_setup::<Platform>);
|
||||
app.add_observer(tb_component_setup::<PlatformTarget>);
|
||||
app.add_observer(tb_component_setup::<Movable>);
|
||||
}
|
||||
|
||||
fn tb_component_setup<C: Component>(trigger: Trigger<OnAdd, C>, world: &mut World) {
|
||||
let id = world.resource_mut::<TbMapIdCounter>().alloc();
|
||||
|
||||
world.entity_mut(trigger.target()).insert_if_new(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user