changed json standards

This commit is contained in:
Nickiel12 2021-12-20 14:30:34 -08:00
parent dfeee75297
commit dd11b732e4
2 changed files with 18 additions and 19 deletions

View file

@ -36,6 +36,10 @@ 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())},
@ -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());
}

View file

@ -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);
}