Add config reload system

This commit is contained in:
Tony Klink 2024-03-26 22:44:34 -06:00
commit 3e76d7c248
Signed by: klink
GPG key ID: 85175567C4D19231
21 changed files with 4065 additions and 0 deletions

64
src/module/mod.rs Normal file
View file

@ -0,0 +1,64 @@
use std::time::Duration;
use anyhow::Result;
use flax::World;
use crate::core::events::Events;
pub trait Module {
fn on_update(&mut self, world: &mut World, events: &mut Events, frame_time: Duration) -> Result<()>;
}
pub struct ModulesStack {
modules: Vec<Box<dyn Module>>,
}
impl ModulesStack {
pub fn new() -> Self {
Self { modules: Vec::new() }
}
pub fn iter(&self) -> std::slice::Iter<Box<dyn Module>> {
self.modules.iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<Box<dyn Module>> {
self.modules.iter_mut()
}
pub fn push<T: 'static + Module>(&mut self, layer: T) {
let layer = Box::new(layer);
self.modules.push(layer);
}
pub fn insert<T: 'static + Module>(&mut self, index: usize, layer: T) {
let layer = Box::new(layer);
self.modules.insert(index, layer);
}
}
impl Default for ModulesStack {
fn default() -> Self {
Self::new()
}
}
impl<'a> IntoIterator for &'a ModulesStack {
type Item = &'a Box<dyn Module>;
type IntoIter = std::slice::Iter<'a, Box<dyn Module>>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a> IntoIterator for &'a mut ModulesStack {
type Item = &'a mut Box<dyn Module>;
type IntoIter = std::slice::IterMut<'a, Box<dyn Module>>;
fn into_iter(self) -> Self::IntoIter {
self.iter_mut()
}
}