diff --git a/src/modules/stream_states/state_update.rs b/src/modules/stream_states/state_update.rs index 6ae8e07..6167334 100644 --- a/src/modules/stream_states/state_update.rs +++ b/src/modules/stream_states/state_update.rs @@ -36,7 +36,11 @@ impl StateUpdate { //Slide changing behavior "Timer_Can_Run" => {StateUpdate::TimerCanRun(incoming_json["data"].as_bool().unwrap())} "Change_With_Clicker" => {StateUpdate::ChangeSceneOnChangeSlide(incoming_json["data"].as_bool().unwrap())}, - + "Timer_Length" => { + let new_timer_length = &incoming_json["data"]; + StateUpdate::TimerLength(new_timer_length.as_f64().unwrap() as f32) + }, + //Extra Toggles "Toggle_Computer_Volume" => {StateUpdate::ComputerSoundIsOn(incoming_json["data"].as_bool().unwrap())}, "Toggle_Stream_Volume" => {StateUpdate::StreamIsMuted(incoming_json["data"].as_bool().unwrap())}, @@ -51,19 +55,14 @@ impl StateUpdate { "Screen_Top_Right" => {StateUpdate::SubScene(SubScenes::ScreenWithUpperRight)}, "Screen_Bottom_Right" => {StateUpdate::SubScene(SubScenes::ScreenWithLowerRight)}, + "all" => {StateUpdate::UpdateClient}, + //Unimplemented "Next_Slide" | "Prev_Slide" | _ => {panic!("trying to use a button type I don't know!: {}", value)} } }, - "Timer_Length" => { - let new_timer_length = &incoming_json["data"]; - StateUpdate::TimerLength(new_timer_length.as_f64().unwrap() as f32) - }, - "update" => { - StateUpdate::UpdateClient - }, _ => { panic!("State Update Could Not Cast the json: {:?}", incoming_json.as_str()); } diff --git a/src/tests/state_update_tests.rs b/src/tests/state_update_tests.rs index 10d09ef..ea3ccea 100644 --- a/src/tests/state_update_tests.rs +++ b/src/tests/state_update_tests.rs @@ -5,11 +5,11 @@ use crate::modules::stream_states::{state_update::StateUpdate, enums::{Scenes, S #[test] fn test_json_to_state_update() { assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Scene_Camera\"}" + "{\"type\": \"update\", \"update\": \"Scene\": \"data\": \"Scene_Camera\"}" ).unwrap()), StateUpdate::Scene(Scenes::Camera)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Scene_Screen\"}" + "{\"type\": \"update\", \"update\": \"Scene\": \"data\": \"Scene_Screen\"}" ).unwrap()), StateUpdate::Scene(Scenes::Screen)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( @@ -57,39 +57,39 @@ fn test_json_to_state_update() { ).unwrap()), StateUpdate::ComputerMediaDoPause(false)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Camera_None\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Camera_None\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::CameraDefault)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Camera_Top_Right\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Camera_Top_Right\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithUpperRight)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Camera_Bottom_Right\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Camera_Bottom_Right\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithLowerRight)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Camera_Bottom_Left\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Camera_Bottom_Left\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::CameraWithLargeUpperRight)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Screen_None\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Screen_None\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenDefault)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Screen_Top_Right\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\": \"Screen_Top_Right\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithUpperRight)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\", \"update\": \"Screen_Bottom_Right\"}" + "{\"type\": \"update\", \"update\": \"SubScene\": \"data\":\"Screen_Bottom_Right\"}" ).unwrap()), StateUpdate::SubScene(SubScenes::ScreenWithLowerRight)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"Timer_Length\", \"data\": 5.5}" + "{\"type\": \"update\", \"update\": \"Timer_Length\" \"data\": 5.5}" ).unwrap()), StateUpdate::TimerLength(5.5)); assert_eq!(StateUpdate::json_to_state_update(serde_json::from_str( - "{\"type\": \"update\"}" + "{\"type\": \"update\", \"update\":\"all\"}" ).unwrap()), StateUpdate::UpdateClient); }