switched from strange function to as_bool

This commit is contained in:
Nickiel12 2022-01-02 21:50:07 -08:00
parent 16554e409e
commit a33a6f7b37

View file

@ -37,7 +37,7 @@ impl StateUpdate {
} }
} }
"Scene_Is_Augmented" => {StateUpdate::SceneIsAugmented(string_to_bool(incoming_json["data"].as_str().unwrap()))}, "Scene_Is_Augmented" => {StateUpdate::SceneIsAugmented(incoming_json["data"].as_bool().unwrap())},
//SubScenes //SubScenes
"SubScene" => { "SubScene" => {
@ -55,22 +55,22 @@ impl StateUpdate {
} }
//Slide changing behavior //Slide changing behavior
"Timer_Can_Run" => {StateUpdate::TimerCanRun(string_to_bool(incoming_json["data"].as_str().unwrap()))} "Timer_Can_Run" => {StateUpdate::TimerCanRun(incoming_json["data"].as_bool().unwrap())}
"Change_With_Clicker" => {StateUpdate::ChangeSceneOnChangeSlide(string_to_bool(incoming_json["data"].as_str().unwrap()))}, "Change_With_Clicker" => {StateUpdate::ChangeSceneOnChangeSlide(incoming_json["data"].as_bool().unwrap())},
"Timer_Length" => { "Timer_Length" => {
let new_timer_length = &incoming_json["data"]; let new_timer_length = &incoming_json["data"];
StateUpdate::TimerLength(new_timer_length.as_str().unwrap().parse::<f32>().unwrap()) StateUpdate::TimerLength(new_timer_length.as_str().unwrap().parse::<f32>().unwrap())
}, },
//Extra Toggles //Extra Toggles
"Toggle_Computer_Volume" => {StateUpdate::ToggleComputerSoundOn(string_to_bool(incoming_json["data"].as_str().unwrap()))}, "Toggle_Computer_Volume" => {StateUpdate::ToggleComputerSoundOn(incoming_json["data"].as_bool().unwrap())},
"Toggle_Stream_Volume" => {StateUpdate::StreamSoundToggleOn(string_to_bool(incoming_json["data"].as_str().unwrap()))}, "Toggle_Stream_Volume" => {StateUpdate::StreamSoundToggleOn(incoming_json["data"].as_bool().unwrap())},
"Media_Pause_Play" => {StateUpdate::ComputerMediaDoPause}, "Media_Pause_Play" => {StateUpdate::ComputerMediaDoPause},
"Timer_Text" => {StateUpdate::TimerText(incoming_json["data"].as_str().unwrap().to_string())} "Timer_Text" => {StateUpdate::TimerText(incoming_json["data"].as_str().unwrap().to_string())}
"all" => {StateUpdate::UpdateClient}, "all" => {StateUpdate::UpdateClient},
"Stream_Running" => {StateUpdate::StreamRunning(string_to_bool(incoming_json["data"].as_str().unwrap()))} "Stream_Running" => {StateUpdate::StreamRunning(incoming_json["data"].as_bool().unwrap())}
"Next_Slide" => {StateUpdate::ChangeSlide(SlideChange::Next)}, "Next_Slide" => {StateUpdate::ChangeSlide(SlideChange::Next)},
"Prev_Slide" => {StateUpdate::ChangeSlide(SlideChange::Previous)} "Prev_Slide" => {StateUpdate::ChangeSlide(SlideChange::Previous)}
@ -124,14 +124,4 @@ impl StateUpdate {
"data": data, "data": data,
}) })
} }
}
fn string_to_bool(input: &str) -> bool{
if input == "true" {
true
} else if input == "false" {
false
} else {
panic!("string to bool doesn't recognize the input: {}", input);
}
} }