♻️ refactor: state structs to their own module

main
_ 2021-10-29 11:58:53 -05:00
parent d4847f2239
commit 614787b94b
2 changed files with 58 additions and 52 deletions

View File

@ -1,3 +1,7 @@
mod state;
pub use state::State;
fn print_help () -> Response {
Response::PrintMany (vec! [
"All commands are ASCII and case-insensitive.",
@ -144,33 +148,6 @@ macro_rules! require_detection {
};
}
#[derive (Clone)]
enum RoomName {
/// Starting room with the dead-simple note and keypad puzzle.
Room1,
/// Duplicate of starting room so I can change things around a little.
_Room2,
SortingRoom,
}
impl Default for RoomName {
fn default () -> Self {
Self::Room1
}
}
#[derive (Clone, Default)]
struct StateRoom1 {
detected_keypad: bool,
detected_note: bool,
read_note: bool,
}
#[derive (Clone, Default)]
struct StateSortingRoom {
}
/// Commands that the game will ask the runtime to execute.
#[derive (PartialEq)]
@ -196,39 +173,19 @@ pub enum Response {
Nonsense,
}
#[derive (Clone, Copy)]
enum IntroState {
Stage1,
Stage2,
Stage3,
}
impl Default for IntroState {
fn default () -> Self {
Self::Stage1
}
}
/// The entire game state
#[derive (Clone, Default)]
pub struct State {
intro_state: IntroState,
current_room: RoomName,
room_1: StateRoom1,
room_sorting: StateSortingRoom,
}
impl State {
pub fn cheat (&mut self) {
self.current_room = RoomName::SortingRoom;
self.current_room = state::RoomName::SortingRoom;
}
/// Send a line of player input (e.g. "look table") into the game and return
/// a Vec of Responses. The runtime should process these responses in order.
pub fn step (&mut self, input: &str) -> Vec <Response> {
use RoomName::*;
use state::{
IntroState,
RoomName::*,
};
match self.intro_state {
IntroState::Stage1 => {

49
game/src/state.rs Normal file
View File

@ -0,0 +1,49 @@
/// The entire game state
#[derive (Clone, Default)]
pub struct State {
pub intro_state: IntroState,
pub current_room: RoomName,
pub room_1: StateRoom1,
pub room_sorting: StateSortingRoom,
}
#[derive (Clone, Copy)]
pub enum IntroState {
Stage1,
Stage2,
Stage3,
}
impl Default for IntroState {
fn default () -> Self {
Self::Stage1
}
}
#[derive (Clone)]
pub enum RoomName {
/// Starting room with the dead-simple note and keypad puzzle.
Room1,
/// Duplicate of starting room so I can change things around a little.
_Room2,
SortingRoom,
}
impl Default for RoomName {
fn default () -> Self {
Self::Room1
}
}
#[derive (Clone, Default)]
pub struct StateRoom1 {
pub detected_keypad: bool,
pub detected_note: bool,
pub read_note: bool,
}
#[derive (Clone, Default)]
pub struct StateSortingRoom {
}