diff --git a/content/config.toml b/content/config.toml index 7ffc156..e3c5a3b 100644 --- a/content/config.toml +++ b/content/config.toml @@ -39,6 +39,8 @@ zoom_max = 2000.0 # TODO: move to user config file ui_scale = 2 -ui_landed_scene = "ui/landed.rhai" -ui_flying_scene = "ui/flying.rhai" -ui_outfitter_scene = "ui/outfitter.rhai" + +start_ui_scene = "landed" +ui_scene.landed = "ui/landed.rhai" +ui_scene.flying = "ui/flying.rhai" +ui_scene.outfitter = "ui/outfitter.rhai" diff --git a/crates/content/src/part/config.rs b/crates/content/src/part/config.rs index 451360d..e220073 100644 --- a/crates/content/src/part/config.rs +++ b/crates/content/src/part/config.rs @@ -1,4 +1,4 @@ -use std::{num::NonZeroU32, path::PathBuf}; +use std::{collections::HashMap, num::NonZeroU32, path::PathBuf}; use rhai::AST; @@ -7,7 +7,10 @@ pub(crate) mod syntax { use galactica_packer::SpriteAtlas; use rhai::Engine; use serde::Deserialize; - use std::path::{Path, PathBuf}; + use std::{ + collections::HashMap, + path::{Path, PathBuf}, + }; // Raw serde syntax structs. // These are never seen by code outside this crate. @@ -20,9 +23,8 @@ pub(crate) mod syntax { pub zoom_min: f32, pub zoom_max: f32, pub ui_scale: f32, - pub ui_flying_scene: PathBuf, - pub ui_landed_scene: PathBuf, - pub ui_outfitter_scene: PathBuf, + pub ui_scene: HashMap, + pub start_ui_scene: String, } impl Config { @@ -59,18 +61,19 @@ pub(crate) mod syntax { }; let engine = Engine::new(); - let ui_landed_scene = engine - .compile_file(content_root.join(self.ui_landed_scene)) - .with_context(|| format!("while loading `landed` scene")) - .with_context(|| format!("while loading config"))?; - let ui_outfitter_scene = engine - .compile_file(content_root.join(self.ui_outfitter_scene)) - .with_context(|| format!("while loading `outfitter` scene")) - .with_context(|| format!("while loading config"))?; - let ui_flying_scene = engine - .compile_file(content_root.join(self.ui_flying_scene)) - .with_context(|| format!("while loading `flying` scene")) - .with_context(|| format!("while loading config"))?; + let mut ui_scenes = HashMap::new(); + for (n, p) in self.ui_scene { + ui_scenes.insert( + n.clone(), + engine + .compile_file(content_root.join(p)) + .with_context(|| format!("while loading scene script `{}`", n))?, + ); + } + + if !ui_scenes.contains_key(&self.start_ui_scene) { + bail!("starting ui scene `{}` doesn't exist", self.start_ui_scene) + } return Ok(super::Config { sprite_root: asset_root.join(self.sprite_root), @@ -98,9 +101,8 @@ pub(crate) mod syntax { zoom_max: self.zoom_max, zoom_min: self.zoom_min, ui_scale: self.ui_scale, - ui_landed_scene, - ui_flying_scene, - ui_outfitter_scene, + ui_scenes, + start_ui_scene: self.start_ui_scene, }); } } @@ -187,12 +189,10 @@ pub struct Config { /// Ui scale factor pub ui_scale: f32, - /// Ui landed scene script - pub ui_landed_scene: AST, + /// Ui scene scripts + pub ui_scenes: HashMap, - /// Ui flying scene script - pub ui_flying_scene: AST, - - /// Ui outfitter scene script - pub ui_outfitter_scene: AST, + /// The UI scene we start in. + /// This is guaranteed to be a key in ui_scenes. + pub start_ui_scene: String, }