use crate::{GameState, physics_layers::GameLayer, protocol::TbMapEntityId}; use avian3d::prelude::*; use bevy::prelude::*; use bevy_replicon::prelude::Replicated; use bevy_trenchbroom::physics::SceneCollidersReady; pub fn plugin(app: &mut App) { app.add_systems(OnEnter(GameState::MapLoading), setup_scene); } fn setup_scene(mut commands: Commands, asset_server: Res) { commands .spawn(( Name::new("LevelRoot"), CollisionLayers::new(LayerMask(GameLayer::Level.to_bits()), LayerMask::ALL), SceneRoot(asset_server.load("maps/map1.map#Scene")), )) .observe( |t: On, children: Query<&Children>, map_entities: Query<&TbMapEntityId>, mut commands: Commands, mut next_game_state: ResMut>| { info!("map loaded"); for child in children.get(t.event().scene_root_entity).unwrap() { commands.entity(*child).remove::(); if map_entities.contains(*child) { commands.entity(*child).insert(Replicated); } } commands.entity(t.scene_root_entity).insert(Replicated); next_game_state.set(GameState::Waiting); }, ); commands.spawn(( DirectionalLight { illuminance: light_consts::lux::OVERCAST_DAY, shadows_enabled: true, ..default() }, Transform { translation: Vec3::new(0.0, 2.0, 0.0), rotation: Quat::from_rotation_x(-1.7), ..default() }, )); }