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