fennel_engine/ecs/
scene.rs1use specs::{Entities, Join, LazyUpdate, Read, ReadExpect, ReadStorage, System};
2
3use crate::{
4 app::App,
5 ecs::sprite::HostPtr,
6 scenes::Scene,
7};
8
9pub struct SceneSystem;
11
12impl<'a> System<'a> for SceneSystem {
13 type SystemData = (ReadStorage<'a, Scene>, ReadExpect<'a, HostPtr>, Entities<'a>, Read<'a, LazyUpdate>);
14
15 fn run(&mut self, (scenes, host_ptr, entities, lazy): Self::SystemData) {
16 let runtime: &mut App = unsafe { &mut *host_ptr.0 };
17 for scene in scenes.join().filter(|s| s.name == runtime.active_scene.name) {
18 if !runtime.active_scene.loaded {
19 for ent_def in &scene.entities {
20 for component in &ent_def.components {
21 println!("loading component {} with parameters {:?}", component.id, component.config);
22 let entity = entities.create();
23 let factory = runtime.component_registry.get(&component.id)
24 .expect("no factory found");
25 factory.insert_lazy(&lazy, entity, &component.config);
26 }
27 }
28 runtime.active_scene.loaded = true;
29 }
30 }
31 }
32}