rust-sokoban/src/resources.rs

60 lines
1.1 KiB
Rust
Raw Permalink Normal View History

2020-07-23 18:12:52 -04:00
use ggez::event::KeyCode;
use specs::World;
2020-07-23 20:25:16 -04:00
use std::fmt;
use std::fmt::Display;
2020-07-24 18:56:48 -04:00
use std::time::Duration;
2020-07-23 18:12:52 -04:00
2020-07-27 09:59:14 -04:00
use crate::audio::AudioStore;
use crate::events::Event;
2020-07-23 18:12:52 -04:00
#[derive(Default)]
pub struct InputQueue {
pub keys_pressed: Vec<KeyCode>,
}
2020-07-23 20:25:16 -04:00
#[derive(Default)]
pub struct Gameplay {
pub state: GameplayState,
pub moves_count: usize,
}
2020-07-24 18:56:48 -04:00
#[derive(Default)]
pub struct Time {
pub delta: Duration,
}
2020-07-23 20:25:16 -04:00
pub enum GameplayState {
Playing,
Won,
}
impl Default for GameplayState {
fn default() -> Self {
Self::Playing
}
}
impl Display for GameplayState {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str(match self {
GameplayState::Playing => "Playing",
GameplayState::Won => "Won",
})?;
Ok(())
}
}
2020-07-27 09:59:14 -04:00
#[derive(Default)]
pub struct EventQueue {
pub events: Vec<Event>,
}
2020-07-23 18:12:52 -04:00
pub fn register_resources(world: &mut World) {
2020-07-23 20:25:16 -04:00
world.insert(InputQueue::default());
world.insert(Gameplay::default());
2020-07-24 18:56:48 -04:00
world.insert(Time::default());
2020-07-27 09:59:14 -04:00
world.insert(EventQueue::default());
world.insert(AudioStore::default());
2020-07-23 18:12:52 -04:00
}