2020-02-29 03:59:11 +00:00
|
|
|
#![deny(unsafe_code)]
|
2020-06-14 16:48:07 +00:00
|
|
|
#![allow(clippy::option_map_unit_fn)]
|
2020-04-11 06:33:06 +00:00
|
|
|
#![feature(drain_filter, bool_to_option)]
|
2020-02-29 03:59:11 +00:00
|
|
|
#![recursion_limit = "2048"]
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
pub mod ui;
|
|
|
|
pub mod anim;
|
|
|
|
pub mod audio;
|
2020-03-10 21:00:13 +00:00
|
|
|
pub mod controller;
|
2020-02-29 03:59:11 +00:00
|
|
|
mod ecs;
|
|
|
|
pub mod error;
|
|
|
|
pub mod hud;
|
|
|
|
pub mod i18n;
|
|
|
|
pub mod key_state;
|
|
|
|
pub mod logging;
|
|
|
|
pub mod menu;
|
2020-01-09 06:05:20 +00:00
|
|
|
pub mod mesh;
|
|
|
|
pub mod render;
|
2020-02-29 03:59:11 +00:00
|
|
|
pub mod scene;
|
|
|
|
pub mod session;
|
|
|
|
pub mod settings;
|
|
|
|
#[cfg(feature = "singleplayer")]
|
|
|
|
pub mod singleplayer;
|
|
|
|
pub mod window;
|
2020-01-26 19:29:46 +00:00
|
|
|
|
2020-02-29 03:59:11 +00:00
|
|
|
// Reexports
|
|
|
|
pub use crate::error::Error;
|
|
|
|
|
2020-05-09 15:41:25 +00:00
|
|
|
use crate::{audio::AudioFrontend, settings::Settings, singleplayer::Singleplayer, window::Window};
|
2020-02-29 03:59:11 +00:00
|
|
|
|
|
|
|
/// A type used to store state that is shared between all play states.
|
|
|
|
pub struct GlobalState {
|
|
|
|
pub settings: Settings,
|
|
|
|
pub window: Window,
|
|
|
|
pub audio: AudioFrontend,
|
|
|
|
pub info_message: Option<String>,
|
|
|
|
pub singleplayer: Option<Singleplayer>,
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
/// 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<dyn PlayState>),
|
|
|
|
/// Switch the current play state with a new play state.
|
|
|
|
Switch(Box<dyn PlayState>),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A trait representing a playable game state. This may be a menu, a game
|
|
|
|
/// session, the title screen, etc.
|
|
|
|
pub trait PlayState {
|
|
|
|
/// Play the state until some change of state is required (i.e: a menu is
|
|
|
|
/// opened or the game is closed).
|
|
|
|
fn play(&mut self, direction: Direction, global_state: &mut GlobalState) -> PlayStateResult;
|
|
|
|
|
|
|
|
/// Get a descriptive name for this state type.
|
|
|
|
fn name(&self) -> &'static str;
|
|
|
|
}
|