This commit is contained in:
Nickiel12 2021-12-30 10:35:32 -08:00
parent 6d8ed3f64b
commit 79ea70e819
3 changed files with 20 additions and 19 deletions

View file

@ -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<StateUpdate>;
fn get_states(&self) -> StreamState;
fn tick(&mut self) -> ();
fn tick(&mut self) -> (Option<StateUpdate>, Option<StateUpdate>);
}
impl MessageHandler for StreamState {
fn handle_update(&mut self, update: StateUpdate) {
fn handle_update(&mut self, update: StateUpdate) -> Option<StateUpdate> {
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<StateUpdate>, Option<StateUpdate>) {
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)
}
}

View file

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

View file

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