use std::collections::HashMap; use std::path::{Path, PathBuf}; pub struct Scene { pub title: String, pub world: hecs::World, pub skybox_texture_path: Option, } impl Scene { pub fn new(title: String, skybox_texture_path: Option) -> Self { Self { title, world: hecs::World::new(), skybox_texture_path, } } } impl Scene {} impl AsRef for Scene { fn as_ref(&self) -> &Scene { &self } } impl AsMut for Scene { fn as_mut(&mut self) -> &mut Scene { self } } type SceneID = &'static str; pub struct SceneManager { scenes: HashMap, active_scene: Option, } impl SceneManager { pub fn new() -> Self { let scenes = HashMap::new(); Self { scenes, active_scene: None, } } pub fn current(&self) -> &Scene { match &self.active_scene { Some(id) => self.scenes[id].as_ref(), None => panic!("No active scene"), } } pub fn current_mut(&mut self) -> &mut Scene { match &mut self.active_scene { Some(id) => self.scenes.get_mut(id).unwrap().as_mut(), None => panic!("No active scene"), } } pub fn set_active_scene(&mut self, scene: SceneID) { self.active_scene = Some(scene); } pub fn add_scene(&mut self, id: SceneID, scene: Scene) { self.scenes.insert(id, scene); } pub fn remove_scene(&mut self, id: SceneID) { self.scenes.remove(&id); } }