From 614787b94b9b2d69b213fcb7a458084330a16eeb Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Fri, 29 Oct 2021 11:58:53 -0500 Subject: [PATCH] :recycle: refactor: state structs to their own module --- game/src/lib.rs | 61 +++++++---------------------------------------- game/src/state.rs | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 52 deletions(-) create mode 100644 game/src/state.rs diff --git a/game/src/lib.rs b/game/src/lib.rs index f223279..8769fef 100644 --- a/game/src/lib.rs +++ b/game/src/lib.rs @@ -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 { - use RoomName::*; + use state::{ + IntroState, + RoomName::*, + }; match self.intro_state { IntroState::Stage1 => { diff --git a/game/src/state.rs b/game/src/state.rs new file mode 100644 index 0000000..748a916 --- /dev/null +++ b/game/src/state.rs @@ -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 { + +}