Skip to content

Commit

Permalink
Fix global entity persistence with new loading system
Browse files Browse the repository at this point in the history
  • Loading branch information
cohaereo committed Mar 25, 2024
1 parent 076ffb4 commit a7b61ff
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_hash::FxHashMap;

use crate::{
discord,
ecs::Scene,
ecs::{components::Global, Scene},
mapload_temporary::{self, LoadMapData},
render::{dcs::DcsShared, renderer::RendererShared, EntityRenderer},
resources::Resources,
Expand Down Expand Up @@ -40,8 +40,21 @@ impl Map {
if let Some(promise) = self.promise.take() {
if promise.ready().is_some() {
match promise.block_and_take() {
Ok(map) => {
self.scene = map.scene;
Ok(mut map) => {
let mut ent_list = vec![];

// Get all non-global entities
for (entity, global) in map.scene.query::<Option<&Global>>().iter() {
if !global.map_or(false, |g| g.0) {
ent_list.push(entity);
}
}

// Insert all entities from the loaded map into the current scene
for entity in ent_list {
self.scene.spawn(map.scene.take(entity).ok().unwrap());
}

self.entity_renderers = map.entity_renderers;
self.load_state = MapLoadState::Loaded;
}
Expand Down

0 comments on commit a7b61ff

Please sign in to comment.