split scenes and subscenes enum

This commit is contained in:
Nickiel12 2021-12-18 22:58:39 -08:00
parent 8f48d213bc
commit f26b7b8a5e
4 changed files with 75 additions and 60 deletions

View file

@ -1,6 +1,6 @@
#[derive(PartialEq, Debug, Clone, Copy)] #[derive(PartialEq, Debug, Clone, Copy)]
pub enum Scenes { pub enum SubScenes {
CameraDefault, CameraDefault,
CameraWithUpperRight, CameraWithUpperRight,
CameraWithLargeUpperRight, CameraWithLargeUpperRight,
@ -10,6 +10,12 @@ pub enum Scenes {
ScreenWithUpperRight, ScreenWithUpperRight,
ScreenWithLowerRight, ScreenWithLowerRight,
}
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum Scenes {
Camera,
Screen,
Augmented Augmented
} }

View file

@ -1,4 +1,4 @@
use super::enums::Scenes; use super::enums::{SubScenes, Scenes};
use super::state_update::StateUpdate; use super::state_update::StateUpdate;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@ -15,8 +15,8 @@ pub struct StreamState {
pub timer_text: String, pub timer_text: String,
pub current_scene: Scenes, pub current_scene: Scenes,
pub camera_sub_scene: Scenes, pub camera_sub_scene: SubScenes,
pub screen_sub_scene: Scenes, pub screen_sub_scene: SubScenes,
} }
impl Default for StreamState { impl Default for StreamState {
@ -33,9 +33,9 @@ impl Default for StreamState {
timer_length: 15.0, timer_length: 15.0,
timer_text: String::from("0.0"), timer_text: String::from("0.0"),
current_scene: Scenes::CameraDefault, current_scene: Scenes::Camera,
camera_sub_scene: Scenes::CameraDefault, camera_sub_scene: SubScenes::CameraDefault,
screen_sub_scene: Scenes::ScreenDefault, 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::ChangeSceneOnChangeSlideHotkey(new_val) => {self.change_scene_on_change_slide_hotkey = new_val;},
StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;}, StateUpdate::TimerCanRun(new_val) => {self.timer_can_run = new_val;},
StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;}, StateUpdate::TimerLength(new_val) => {self.timer_length = new_val;},
StateUpdate::TimerText(new_val) => {self.timer_text = new_val;}, StateUpdate::TimerText(new_val) => {self.timer_text = new_val;},
StateUpdate::Scene(new_val) => {self.change_scene(&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) => { StateUpdate::SceneIsAugmented(new_val) => {
self.scene_is_augmented = new_val; self.scene_is_augmented = new_val;
self.change_scene(&Scenes::Augmented)}, self.change_scene(&Scenes::Augmented)},
StateUpdate::UpdateClient => todo!(),
} }
} }
pub fn change_scene(&mut self, scene: &Scenes) { pub fn change_scene(&mut self, scene: &Scenes) {
match scene { match scene {
Scenes::CameraDefault | Scenes::CameraWithUpperRight | Scenes::Augmented => {self.current_scene = *scene;}
Scenes::CameraWithLargeUpperRight | Scenes::CameraWithLowerRight Scenes::Camera => {self.current_scene = *scene},
=> {StreamState::set_camera_scene(self, scene)}, Scenes::Screen => {self.current_scene = *scene},
Scenes::ScreenDefault | Scenes::ScreenWithUpperRight |
Scenes::ScreenWithLowerRight
=> {StreamState::set_screen_scene(self, scene)},
Scenes::Augmented => {self.current_scene = *scene;}
} }
} }
fn set_camera_scene(&mut self, scene: &Scenes) { pub fn change_sub_scene(&mut self, scene: &SubScenes) {
self.camera_sub_scene = scene.clone(); match scene {
self.current_scene = scene.clone(); 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.screen_sub_scene = scene.clone();
self.current_scene = scene.clone(); self.current_scene = Scenes::Screen;
} }
} }

View file

@ -1,6 +1,6 @@
use std::{sync::mpsc::{self, Receiver}, thread::{self, JoinHandle}}; 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] #[test]
@ -53,7 +53,7 @@ fn message_handler_can_handle_multiple_messages() {
assert_eq!(handler.computer_sound_is_on, false); 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.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); assert_eq!(handler.timer_can_run, false);
}) })
} }

View file

@ -8,18 +8,18 @@ use crate::modules::stream_states::state_update::StateUpdate;
fn has_all_enums() { fn has_all_enums() {
{ {
let members = [ let members = [
s_s::enums::Scenes::CameraDefault, s_s::enums::SubScenes::CameraDefault,
s_s::enums::Scenes::CameraWithUpperRight, s_s::enums::SubScenes::CameraWithUpperRight,
s_s::enums::Scenes::CameraWithLowerRight, s_s::enums::SubScenes::CameraWithLowerRight,
s_s::enums::Scenes::CameraWithLargeUpperRight, s_s::enums::SubScenes::CameraWithLargeUpperRight,
]; ];
assert_eq!(members.len(), 4); assert_eq!(members.len(), 4);
} }
{ {
let members = [ let members = [
s_s::enums::Scenes::ScreenDefault, s_s::enums::SubScenes::ScreenDefault,
s_s::enums::Scenes::ScreenWithUpperRight, s_s::enums::SubScenes::ScreenWithUpperRight,
s_s::enums::Scenes::ScreenWithLowerRight, s_s::enums::SubScenes::ScreenWithLowerRight,
]; ];
assert_eq!(members.len(), 3); 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_length, 15.0);
assert_eq!(stream_state.timer_can_run, true); assert_eq!(stream_state.timer_can_run, true);
assert_eq!(stream_state.current_scene, s_s::enums::Scenes::CameraDefault); assert_eq!(stream_state.current_scene, s_s::enums::SubScenes::CameraDefault);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraDefault); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraDefault);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault);
} }
#[test] #[test]
fn scene_correctness(){ fn scene_correctness(){
let mut stream_state = s_s::stream_states_class::StreamState::new(); 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.current_scene, s_s::enums::SubScenes::CameraDefault);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraDefault); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraDefault);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); 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.current_scene, s_s::enums::SubScenes::CameraWithUpperRight);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithUpperRight); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithUpperRight);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); 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.current_scene, s_s::enums::SubScenes::CameraWithLargeUpperRight);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLargeUpperRight); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLargeUpperRight);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); 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.current_scene, s_s::enums::SubScenes::CameraWithLowerRight);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); 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.current_scene, s_s::enums::SubScenes::ScreenDefault);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenDefault); assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenDefault);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); 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.current_scene, s_s::enums::SubScenes::ScreenWithLowerRight);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenWithLowerRight); assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenWithLowerRight);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); 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.current_scene, s_s::enums::SubScenes::ScreenWithUpperRight);
assert_eq!(stream_state.screen_sub_scene, s_s::enums::Scenes::ScreenWithUpperRight); assert_eq!(stream_state.screen_sub_scene, s_s::enums::SubScenes::ScreenWithUpperRight);
assert_eq!(stream_state.camera_sub_scene, s_s::enums::Scenes::CameraWithLowerRight); assert_eq!(stream_state.camera_sub_scene, s_s::enums::SubScenes::CameraWithLowerRight);
} }