Skip to content

Commit a7b61ff

Browse files
committedMar 25, 2024·
Fix global entity persistence with new loading system
1 parent 076ffb4 commit a7b61ff

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed
 

‎src/map.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_hash::FxHashMap;
77

88
use crate::{
99
discord,
10-
ecs::Scene,
10+
ecs::{components::Global, Scene},
1111
mapload_temporary::{self, LoadMapData},
1212
render::{dcs::DcsShared, renderer::RendererShared, EntityRenderer},
1313
resources::Resources,
@@ -40,8 +40,21 @@ impl Map {
4040
if let Some(promise) = self.promise.take() {
4141
if promise.ready().is_some() {
4242
match promise.block_and_take() {
43-
Ok(map) => {
44-
self.scene = map.scene;
43+
Ok(mut map) => {
44+
let mut ent_list = vec![];
45+
46+
// Get all non-global entities
47+
for (entity, global) in map.scene.query::<Option<&Global>>().iter() {
48+
if !global.map_or(false, |g| g.0) {
49+
ent_list.push(entity);
50+
}
51+
}
52+
53+
// Insert all entities from the loaded map into the current scene
54+
for entity in ent_list {
55+
self.scene.spawn(map.scene.take(entity).ok().unwrap());
56+
}
57+
4558
self.entity_renderers = map.entity_renderers;
4659
self.load_state = MapLoadState::Loaded;
4760
}

0 commit comments

Comments
 (0)
Please sign in to comment.