From 79ea70e819be6c1e701bced9067804101a0173df Mon Sep 17 00:00:00 2001 From: Nickiel12 <35903114+Nickiel12@users.noreply.github.com> Date: Thu, 30 Dec 2021 10:35:32 -0800 Subject: [PATCH] stuff --- src/modules/message_handler.rs | 29 +++++++++++++++++------------ src/tests/main_tests.rs | 6 ++---- src/tests/message_handler_tests.rs | 4 +--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/modules/message_handler.rs b/src/modules/message_handler.rs index e676f73..a8d7b7a 100644 --- a/src/modules/message_handler.rs +++ b/src/modules/message_handler.rs @@ -1,15 +1,15 @@ use std::time::{SystemTime, Duration}; -use super::{stream_states::{state_update::StateUpdate, stream_states_class::StreamState, enums::{SlideChange, Scenes}}, external_interface}; +use super::{stream_states::{state_update::StateUpdate, stream_states_class::StreamState, enums::{SlideChange, Scenes}}, external_interface, socket_handler::Socket}; pub trait MessageHandler { - fn handle_update(&mut self, update: StateUpdate) -> (); + fn handle_update(&mut self, update: StateUpdate) -> Option; fn get_states(&self) -> StreamState; - fn tick(&mut self) -> (); + fn tick(&mut self) -> (Option, Option); } impl MessageHandler for StreamState { - fn handle_update(&mut self, update: StateUpdate) { + fn handle_update(&mut self, update: StateUpdate) -> Option { self.update(update.clone()); match update { @@ -17,7 +17,9 @@ impl MessageHandler for StreamState { if self.timer_can_run { self.timer_finished = false; self.timer_start = SystemTime::now(); - self.tick(); + } + if self.change_scene_on_change_slide_hotkey { + self.handle_update(StateUpdate::Scene(Scenes::Screen)); } match direction { SlideChange::Next => { @@ -30,25 +32,28 @@ impl MessageHandler for StreamState { } _ => {} } + None } - fn tick(&mut self) { + fn tick(&mut self) -> (Option, Option) { if self.timer_finished == false { let change = self.timer_start.elapsed(); match change { - Err(_) => {}, + Err(_) => {(None, None)}, Ok(change) => { if change.as_secs_f32() >= self.timer_length { - self.handle_update(StateUpdate::TimerText(String::from("0.0"))); - self.handle_update(StateUpdate::Scene(Scenes::Camera)); self.timer_finished = true; + (Some(StateUpdate::TimerText(String::from("0.0"))), + Some(StateUpdate::Scene(Scenes::Camera))) } else { - self.handle_update(StateUpdate::TimerText( + (Some(StateUpdate::TimerText( format!("{:.1}", self.timer_length - ((change.as_secs_f32() * 10.0).round() / 10.0)) - )); + )), None) } } - }; + } + } else { + (None, None) } } diff --git a/src/tests/main_tests.rs b/src/tests/main_tests.rs index fcaa4c9..ba9fdd3 100644 --- a/src/tests/main_tests.rs +++ b/src/tests/main_tests.rs @@ -16,15 +16,13 @@ fn can_make_ctrl_c_handler() { drop(_control_c_called_flag_rx); } -/* + #[test] fn test_updating_state_from_state_update() { let mut state = StreamState::new(); let update = StateUpdate::Scene(Scenes::Augmented); //Update handled extensivly in stream_state_tests - state.handle_update(&update); + state.handle_update(update); assert_eq!(state.current_scene, Scenes::Augmented); } - -*/ \ No newline at end of file diff --git a/src/tests/message_handler_tests.rs b/src/tests/message_handler_tests.rs index c31aaa7..0d5ea9a 100644 --- a/src/tests/message_handler_tests.rs +++ b/src/tests/message_handler_tests.rs @@ -1,11 +1,9 @@ use crate::modules::{message_handler::{MessageHandler}, stream_states::{state_update::StateUpdate, enums::{Scenes}, stream_states_class::StreamState}}; -/* + #[test] fn does_stream_state_implement_message_handler() { let mut state = StreamState::new(); state.handle_update(StateUpdate::ToggleComputerSoundOn(false)); assert_eq!(state.computer_sound_is_on, false); } - -*/ \ No newline at end of file