#![deny(unsafe_code)] #![allow(clippy::option_map_unit_fn)] #![feature(drain_filter, bool_to_option)] #![recursion_limit = "2048"] #[macro_use] pub mod ui; pub mod audio; pub mod controller; mod ecs; pub mod error; pub mod hud; pub mod i18n; pub mod key_state; pub mod logging; pub mod menu; pub mod mesh; pub mod profile; pub mod render; pub mod run; pub mod scene; pub mod session; pub mod settings; #[cfg(feature = "singleplayer")] pub mod singleplayer; pub mod window; // Reexports pub use crate::error::Error; use crate::{ audio::AudioFrontend, profile::Profile, render::Renderer, settings::Settings, singleplayer::Singleplayer, window::{Event, Window}, }; use common::{assets::watch, clock::Clock}; /// A type used to store state that is shared between all play states. pub struct GlobalState { pub settings: Settings, pub profile: Profile, pub window: Window, pub audio: AudioFrontend, pub info_message: Option, pub clock: Clock, #[cfg(feature = "singleplayer")] pub singleplayer: Option, // TODO: redo this so that the watcher doesn't have to exist for reloading to occur pub localization_watcher: watch::ReloadIndicator, } impl GlobalState { /// Called after a change in play state has occurred (usually used to /// reverse any temporary effects a state may have made). pub fn on_play_state_changed(&mut self) { self.window.grab_cursor(false); self.window.needs_refresh_resize(); } pub fn maintain(&mut self, dt: f32) { self.audio.maintain(dt); } } pub enum Direction { Forwards, Backwards, } /// States can either close (and revert to a previous state), push a new state /// on top of themselves, or switch to a totally different state. pub enum PlayStateResult { /// Keep running this play state. Continue, /// Pop all play states in reverse order and shut down the program. Shutdown, /// Close the current play state and pop it from the play state stack. Pop, /// Push a new play state onto the play state stack. Push(Box), /// Switch the current play state with a new play state. Switch(Box), } /// A trait representing a playable game state. This may be a menu, a game /// session, the title screen, etc. pub trait PlayState { /// Get a descriptive name for this state type. /// Called when entering this play state from another fn enter(&mut self, global_state: &mut GlobalState, direction: Direction); /// Tick the play state fn tick(&mut self, global_state: &mut GlobalState, events: Vec) -> PlayStateResult; /// Get a descriptive name for this state type. fn name(&self) -> &'static str; /// Draw the play state. fn render(&mut self, renderer: &mut Renderer, settings: &Settings); }