Files
HEDZReloaded/crates/hedz_reloaded/src/loading_map.rs
extrawurst 7cfae285ed Crate unification (#88)
* move client/server/config into shared

* move platforms into shared

* move head drops into shared

* move tb_entities to shared

* reduce server to just a call into shared

* get solo play working

* fix server opening window

* fix fmt

* extracted a few more modules from client

* near completely migrated client

* fixed duplicate CharacterInputEnabled definition

* simplify a few things related to builds

* more simplifications

* fix warnings/check

* ci update

* address comments

* try fixing macos steam build

* address comments

* address comments

* CI tweaks with default client feature

---------

Co-authored-by: PROMETHIA-27 <electriccobras@gmail.com>
2025-12-18 12:31:22 -05:00

53 lines
1.7 KiB
Rust

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<AssetServer>) {
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<SceneCollidersReady>,
children: Query<&Children>,
map_entities: Query<&TbMapEntityId>,
mut commands: Commands,
mut next_game_state: ResMut<NextState<GameState>>| {
info!("map loaded");
for child in children.get(t.event().scene_root_entity).unwrap() {
commands.entity(*child).remove::<ChildOf>();
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()
},
));
}