2025-03-11 12:49:23 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
|
|
|
|
use ecs::*;
|
|
|
|
use engine::prelude::*;
|
|
|
|
|
|
|
|
use crate::game::Game;
|
|
|
|
|
2025-04-06 07:36:21 +00:00
|
|
|
#[derive(Default, Resource)]
|
2025-03-11 12:49:23 +00:00
|
|
|
pub enum GameState {
|
|
|
|
#[default]
|
|
|
|
Startup,
|
|
|
|
|
|
|
|
Game(Game),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl GameState {
|
|
|
|
pub fn update(world: &mut World) -> Result<bool> {
|
|
|
|
let me = world.resources.get_mut_unchecked::<Self>();
|
|
|
|
|
|
|
|
match me {
|
|
|
|
GameState::Startup => *me = GameState::Game(Game),
|
|
|
|
GameState::Game(game) => game.update(world)?,
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EventConsumer for GameState {
|
|
|
|
fn event(&mut self, world: &mut World, event: EngineEvent<'_>) -> Result<()> {
|
|
|
|
match self {
|
|
|
|
GameState::Startup => (),
|
|
|
|
GameState::Game(game) => game.event(world, event)?,
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|