From f26b7b8a5ec27a3519120a8a66d99f93eb041486 Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Sat, 18 Dec 2021 22:58:39 -0800 Subject: [PATCH] split scenes and subscenes enum --- src/modules/stream_states/enums.rs | 8 +- .../stream_states/stream_states_class.rs | 49 +++++++----- src/tests/message_handler_tests.rs | 4 +- src/tests/stream_states_tests.rs | 74 +++++++++---------- 4 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/modules/stream_states/enums.rs b/src/modules/stream_states/enums.rs index 5354452..7793630 100644 --- a/src/modules/stream_states/enums.rs +++ b/src/modules/stream_states/enums.rs @@ -1,6 +1,6 @@ #[derive(PartialEq, Debug, Clone, Copy)] -pub enum Scenes { +pub enum SubScenes { CameraDefault, CameraWithUpperRight, CameraWithLargeUpperRight, @@ -10,6 +10,12 @@ pub enum Scenes { ScreenWithUpperRight, ScreenWithLowerRight, +} + +#[derive(PartialEq, Debug, Clone, Copy)] +pub enum Scenes { + Camera, + Screen, Augmented } diff --git a/src/modules/stream_states/stream_states_class.rs b/src/modules/stream_states/stream_states_class.rs index b740b46..c702a28 100644 --- a/src/modules/stream_states/stream_states_class.rs +++ b/src/modules/stream_states/stream_states_class.rs @@ -1,4 +1,4 @@ -use super::enums::Scenes; +use super::enums::{SubScenes, Scenes}; use super::state_update::StateUpdate; #[derive(Debug, Clone)] @@ -15,8 +15,8 @@ pub struct StreamState { pub timer_text: String, pub current_scene: Scenes, - pub camera_sub_scene: Scenes, - pub screen_sub_scene: Scenes, + pub camera_sub_scene: SubScenes, + pub screen_sub_scene: SubScenes, } impl Default for StreamState { @@ -33,9 +33,9 @@ impl Default for StreamState { timer_length: 15.0, timer_text: String::from("0.0"), - current_scene: Scenes::CameraDefault, - camera_sub_scene: Scenes::CameraDefault, - screen_sub_scene: Scenes::ScreenDefault, + current_scene: Scenes::Camera, + camera_sub_scene: SubScenes::CameraDefault, + screen_sub_scene: SubScenes::ScreenDefault, } } } @@ -53,33 +53,42 @@ impl StreamState { StateUpdate::ChangeSceneOnChangeSlideHotkey(new_val) => {self.change_scene_on_change_slide_hotkey = new_val;}, StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;}, StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;}, - StateUpdate::TimerText(new_val) => {self.timer_text = new_val;}, - StateUpdate::Scene(new_val) => {self.change_scene(&new_val)}, + StateUpdate::TimerText(new_val) => {self.timer_text = new_val;}, + StateUpdate::Scene(new_val) => {self.change_scene(&new_val)}, + StateUpdate::SubScene(new_val) => {self.change_sub_scene(&new_val)}, StateUpdate::SceneIsAugmented(new_val) => { self.scene_is_augmented = new_val; self.change_scene(&Scenes::Augmented)}, + StateUpdate::UpdateClient => todo!(), } } pub fn change_scene(&mut self, scene: &Scenes) { match scene { - Scenes::CameraDefault | Scenes::CameraWithUpperRight | - Scenes::CameraWithLargeUpperRight | Scenes::CameraWithLowerRight - => {StreamState::set_camera_scene(self, scene)}, - Scenes::ScreenDefault | Scenes::ScreenWithUpperRight | - Scenes::ScreenWithLowerRight - => {StreamState::set_screen_scene(self, scene)}, - Scenes::Augmented => {self.current_scene = *scene;} + Scenes::Augmented => {self.current_scene = *scene;} + Scenes::Camera => {self.current_scene = *scene}, + Scenes::Screen => {self.current_scene = *scene}, } } - fn set_camera_scene(&mut self, scene: &Scenes) { - self.camera_sub_scene = scene.clone(); - self.current_scene = scene.clone(); + pub fn change_sub_scene(&mut self, scene: &SubScenes) { + match scene { + SubScenes::CameraDefault | SubScenes::CameraWithUpperRight | + SubScenes::CameraWithLargeUpperRight | SubScenes::CameraWithLowerRight + => {StreamState::set_camera_scene(self, scene)}, + SubScenes::ScreenDefault | SubScenes::ScreenWithUpperRight | + SubScenes::ScreenWithLowerRight + => {StreamState::set_screen_scene(self, scene)}, + } } - fn set_screen_scene(&mut self, scene: &Scenes) { + fn set_camera_scene(&mut self, scene: &SubScenes) { + self.camera_sub_scene = scene.clone(); + self.current_scene = Scenes::Camera; + } + + fn set_screen_scene(&mut self, scene: &SubScenes) { self.screen_sub_scene = scene.clone(); - self.current_scene = scene.clone(); + self.current_scene = Scenes::Screen; } } diff --git a/src/tests/message_handler_tests.rs b/src/tests/message_handler_tests.rs index f5d7c16..0aa61fd 100644 --- a/src/tests/message_handler_tests.rs +++ b/src/tests/message_handler_tests.rs @@ -1,6 +1,6 @@ use std::{sync::mpsc::{self, Receiver}, thread::{self, JoinHandle}}; -use crate::modules::{message_handler::{MessageHandler, StateMessage}, stream_states::{state_update::StateUpdate, enums::Scenes, stream_states_class::StreamState}}; +use crate::modules::{message_handler::{MessageHandler, StateMessage}, stream_states::{state_update::StateUpdate, enums::SubScenes, stream_states_class::StreamState}}; #[test] @@ -53,7 +53,7 @@ fn message_handler_can_handle_multiple_messages() { assert_eq!(handler.computer_sound_is_on, false); assert_eq!(handler.scene_is_augmented, true); assert_eq!(handler.scene_is_augmented, true); - assert_eq!(handler.current_scene, Scenes::Augmented); + assert_eq!(handler.current_scene, SubScenes::Augmented); assert_eq!(handler.timer_can_run, false); }) } diff --git a/src/tests/stream_states_tests.rs b/src/tests/stream_states_tests.rs index 52701c8..67ba2b8 100644 --- a/src/tests/stream_states_tests.rs +++ b/src/tests/stream_states_tests.rs @@ -8,18 +8,18 @@ use crate::modules::stream_states::state_update::StateUpdate; fn has_all_enums() { { let members = [ - s_s::enums::Scenes::CameraDefault, - s_s::enums::Scenes::CameraWithUpperRight, - s_s::enums::Scenes::CameraWithLowerRight, - s_s::enums::Scenes::CameraWithLargeUpperRight, + s_s::enums::SubScenes::CameraDefault, + s_s::enums::SubScenes::CameraWithUpperRight, + s_s::enums::SubScenes::CameraWithLowerRight, + s_s::enums::SubScenes::CameraWithLargeUpperRight, ]; assert_eq!(members.len(), 4); } { let members = [ - s_s::enums::Scenes::ScreenDefault, - s_s::enums::Scenes::ScreenWithUpperRight, - s_s::enums::Scenes::ScreenWithLowerRight, + s_s::enums::SubScenes::ScreenDefault, + s_s::enums::SubScenes::ScreenWithUpperRight, + s_s::enums::SubScenes::ScreenWithLowerRight, ]; assert_eq!(members.len(), 3); } @@ -38,54 +38,54 @@ fn create_stream_states_class() { assert_eq!(stream_state.timer_length, 15.0); assert_eq!(stream_state.timer_can_run, true); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraDefault); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraDefault); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraDefault); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraDefault); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); } #[test] fn scene_correctness(){ let mut stream_state = s_s::stream_states_class::StreamState::new(); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraDefault); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraDefault); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraDefault); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraDefault); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithUpperRight)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::CameraWithUpperRight)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraWithUpperRight); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithUpperRight); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraWithUpperRight); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithUpperRight); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithLargeUpperRight)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::CameraWithLargeUpperRight)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraWithLargeUpperRight); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLargeUpperRight); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraWithLargeUpperRight); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLargeUpperRight); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithLowerRight)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::CameraWithLowerRight)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraWithLowerRight); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraWithLowerRight); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenDefault)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::ScreenDefault)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::ScreenDefault); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::ScreenDefault); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenWithLowerRight)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::ScreenWithLowerRight)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::ScreenWithLowerRight); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenWithLowerRight); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::ScreenWithLowerRight); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenWithLowerRight); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight); - stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenWithUpperRight)); + stream_state.update(StateUpdate::Scene(s_s::enums::SubScenes::ScreenWithUpperRight)); - assert_eq!(stream_state.current_scene, s_s::enums::Scenes::ScreenWithUpperRight); - assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenWithUpperRight); - assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); + assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::ScreenWithUpperRight); + assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenWithUpperRight); + assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight); }