From ef8fbbd444e5216da36461af4da58cac07b85f1a Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Sat, 11 Dec 2021 14:33:37 -0800 Subject: [PATCH] added start of next module --- src/modules/stream_states/enums.rs | 13 ++++++++ .../stream_states/stream_states_class.rs | 15 +-------- src/tests/stream_states_tests.rs | 33 ++++++++++--------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/modules/stream_states/enums.rs b/src/modules/stream_states/enums.rs index d3f0a8d..652cbdd 100644 --- a/src/modules/stream_states/enums.rs +++ b/src/modules/stream_states/enums.rs @@ -11,4 +11,17 @@ pub enum Scenes { ScreenWithLowerRight, Augmented +} + +#[derive(Debug, PartialEq, Clone)] +pub enum StateUpdate { + StreamRunning(bool), + StreamIsMuted(bool), + ComputerSoundIsOn(bool), + ChangeSceneOnChangeSlideHotkey(bool), + SceneIsAugmented(bool), + TimerCanRun(bool), + TimerLength(f32), + TimerText(String), + Scene(Scenes), } \ No newline at end of file diff --git a/src/modules/stream_states/stream_states_class.rs b/src/modules/stream_states/stream_states_class.rs index 0d3604a..34c71b6 100644 --- a/src/modules/stream_states/stream_states_class.rs +++ b/src/modules/stream_states/stream_states_class.rs @@ -1,17 +1,4 @@ -use super::enums::{self}; - -#[derive(Debug, PartialEq, Clone)] -pub enum StateUpdate { - StreamRunning(bool), - StreamIsMuted(bool), - ComputerSoundIsOn(bool), - ChangeSceneOnChangeSlideHotkey(bool), - SceneIsAugmented(bool), - TimerCanRun(bool), - TimerLength(f32), - TimerText(String), - Scene(enums::Scenes), -} +use super::enums::{self, StateUpdate}; #[derive(Debug)] pub struct StreamStates { diff --git a/src/tests/stream_states_tests.rs b/src/tests/stream_states_tests.rs index d023cc1..4072729 100644 --- a/src/tests/stream_states_tests.rs +++ b/src/tests/stream_states_tests.rs @@ -2,6 +2,7 @@ use std::sync::mpsc; use std::thread; use crate::modules::stream_states as s_s; +use crate::modules::stream_states::enums::{StateUpdate}; #[test] fn has_all_enums() { @@ -50,37 +51,37 @@ fn scene_correctness(){ assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraDefault); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenDefault); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::CameraWithUpperRight)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithUpperRight)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::CameraWithUpperRight); assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraWithUpperRight); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenDefault); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::CameraWithLargeUpperRight)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithLargeUpperRight)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::CameraWithLargeUpperRight); assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraWithLargeUpperRight); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenDefault); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::CameraWithLowerRight)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::CameraWithLowerRight)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::CameraWithLowerRight); assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraWithLowerRight); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenDefault); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::ScreenDefault)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenDefault)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::ScreenDefault); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenDefault); assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraWithLowerRight); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::ScreenWithLowerRight)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenWithLowerRight)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::ScreenWithLowerRight); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenWithLowerRight); assert_eq!(stream_state.get_current_camera_sub_scene(), s_s::enums::Scenes::CameraWithLowerRight); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::Scene(s_s::enums::Scenes::ScreenWithUpperRight)); + stream_state = stream_state.update(StateUpdate::Scene(s_s::enums::Scenes::ScreenWithUpperRight)); assert_eq!(stream_state.get_current_scene(), s_s::enums::Scenes::ScreenWithUpperRight); assert_eq!(stream_state.get_current_screen_sub_scene(), s_s::enums::Scenes::ScreenWithUpperRight); @@ -93,35 +94,35 @@ fn test_updating() { let mut stream_state = s_s::stream_states_class::StreamStates::new(); assert_eq!(stream_state.timer_can_run, true); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::TimerCanRun(false)); + stream_state = stream_state.update(StateUpdate::TimerCanRun(false)); assert_eq!(stream_state.timer_can_run, false); assert_eq!(stream_state.timer_length, 15.0); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::TimerLength(7.5)); + stream_state = stream_state.update(StateUpdate::TimerLength(7.5)); assert_eq!(stream_state.timer_length, 7.5); assert_eq!(stream_state.timer_text, "0.0"); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::TimerText(String::from("7.5"))); + stream_state = stream_state.update(StateUpdate::TimerText(String::from("7.5"))); assert_eq!(stream_state.timer_text, "7.5"); assert_eq!(stream_state.stream_running, false); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::StreamRunning(true)); + stream_state = stream_state.update(StateUpdate::StreamRunning(true)); assert_eq!(stream_state.stream_running, true); assert_eq!(stream_state.stream_is_muted, false); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::StreamIsMuted(true)); + stream_state = stream_state.update(StateUpdate::StreamIsMuted(true)); assert_eq!(stream_state.stream_is_muted, true); assert_eq!(stream_state.computer_sound_is_on, true); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::ComputerSoundIsOn(false)); + stream_state = stream_state.update(StateUpdate::ComputerSoundIsOn(false)); assert_eq!(stream_state.computer_sound_is_on, false); assert_eq!(stream_state.change_scene_on_change_slide_hotkey, true); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::ChangeSceneOnChangeSlideHotkey(false)); + stream_state = stream_state.update(StateUpdate::ChangeSceneOnChangeSlideHotkey(false)); assert_eq!(stream_state.change_scene_on_change_slide_hotkey, false); assert_eq!(stream_state.scene_is_augmented, false); - stream_state = stream_state.update(s_s::stream_states_class::StateUpdate::SceneIsAugmented(true)); + stream_state = stream_state.update(StateUpdate::SceneIsAugmented(true)); assert_eq!(stream_state.scene_is_augmented, true); } @@ -133,14 +134,14 @@ fn can_run_in_thread() { let rx_thread = thread::spawn(move || { let mut stream_state = s_s::stream_states_class::StreamStates::new(); for received in rx { - assert_eq!(received, s_s::stream_states_class::StateUpdate::StreamRunning(true)); + assert_eq!(received, StateUpdate::StreamRunning(true)); stream_state = stream_state.update(received); assert_eq!(stream_state.stream_running, true); break; } }); - tx.send(s_s::stream_states_class::StateUpdate::StreamRunning(true)).unwrap(); + tx.send(StateUpdate::StreamRunning(true)).unwrap(); let result = rx_thread.join(); match result { Ok(_) => return,