tirbofish/dropbear · diff
Merge pull request #53 from 4tkbytes/scene
feature: scene switching and multiple scene support
Signature present but could not be verified.
Unverified
@@ -8,7 +8,6 @@ package.readme = "README.md" resolver = "3" members = [ "dropbear-engine", "dropbear-shader", "dropbear_future-queue", "eucalyptus-core", "eucalyptus-editor", "magna-carta", "redback-runtime"] - [workspace.dependencies] anyhow = { version = "1.0", features = ["backtrace"] } app_dirs2 = "2.5" @@ -34,6 +34,57 @@ pub static SOURCE: Lazy<RwLock<SourceConfig>> = Lazy::new(|| RwLock::new(SourceC pub static SCENES: Lazy<RwLock<Vec<SceneConfig>>> = Lazy::new(|| RwLock::new(Vec::new())); +/// Removes a scene with the provided name from the in-memory scene cache. +/// Returns `true` when a scene was removed and `false` when no matching scene existed. +pub fn unload_scene(scene_name: &str) -> bool { + let mut scenes = SCENES.write(); + let initial_len = scenes.len(); + scenes.retain(|scene| scene.scene_name != scene_name); + let removed = scenes.len() != initial_len; + + if removed { + log::info!("Unloaded scene '{}' from memory", scene_name); + } else { + log::debug!("Scene '{}' was not loaded; nothing to unload", scene_name); + } + + removed +} + +/// Reads a scene configuration from disk based on the active project's path. +pub fn load_scene(scene_name: &str) -> anyhow::Result<SceneConfig> { + let scene_path = { + let project = PROJECT.read(); + if project.project_path.as_os_str().is_empty() { + return Err(anyhow::anyhow!("Project path is not set; cannot load scenes")); + } + + project + .project_path + .join("scenes") + .join(format!("{}.eucs", scene_name)) + };
Large diffs are not rendered by default. Showing the first 50 of 667 lines. Show full diff