Update
This commit is contained in:
parent
b361965033
commit
f4694157ab
8 changed files with 143 additions and 3 deletions
54
src/core/app/app.rs
Normal file
54
src/core/app/app.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use std::error::Error;
|
||||
|
||||
use bevy_ecs::{schedule::Schedules, world::World};
|
||||
|
||||
pub enum AppExit {
|
||||
Success,
|
||||
Error(Box<dyn Error>),
|
||||
}
|
||||
|
||||
pub type RunnerFn = Box<dyn FnOnce() -> AppExit>;
|
||||
|
||||
pub struct App {
|
||||
world: World,
|
||||
runner: Option<RunnerFn>,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
fn default() -> Self {
|
||||
let mut world = World::new();
|
||||
world.init_resource::<Schedules>();
|
||||
|
||||
Self {
|
||||
world,
|
||||
runner: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn world_mut(&mut self) -> &mut World {
|
||||
&mut self.world
|
||||
}
|
||||
|
||||
pub fn world(&self) -> &World {
|
||||
&self.world
|
||||
}
|
||||
|
||||
pub fn run(&mut self) -> Result<(), Box<dyn Error>> {
|
||||
match self.runner.take() {
|
||||
Some(runner) => match runner() {
|
||||
AppExit::Success => Ok(()),
|
||||
AppExit::Error(e) => Err(e),
|
||||
},
|
||||
None => Err(Box::new(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"runner is not set",
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_runner(&mut self, runner: RunnerFn) {
|
||||
self.runner = Some(runner);
|
||||
}
|
||||
}
|
4
src/core/app/mod.rs
Normal file
4
src/core/app/mod.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
mod app;
|
||||
pub mod plugin;
|
||||
|
||||
pub use app::App;
|
5
src/core/app/plugin.rs
Normal file
5
src/core/app/plugin.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
use super::app::App;
|
||||
|
||||
pub trait Plugin {
|
||||
fn build(&self, app: &mut App);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue