fixed and implemented #8

This commit is contained in:
Nickiel12 2022-06-29 21:10:20 -07:00
parent 21c38e275a
commit cce730a57f

View file

@ -106,19 +106,21 @@ impl MessageHandler for StreamState {
StateUpdate::Scene(value) => { StateUpdate::Scene(value) => {
println!("handling scene: {:?}", value); println!("handling scene: {:?}", value);
let mut instruction = None; let mut instruction = None;
if self.current_scene != value { if self.current_scene != value {
match value { match value {
Scenes::Camera => { Scenes::Camera => {
hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene)); hotkey_handler.change_scene(Scenes::Camera, Some(self.camera_sub_scene));
if self.timer_paused_length.is_none() {
instruction = Some(vec![StateUpdate::TimerText("0.0".to_string())]); instruction = Some(vec![StateUpdate::TimerText("0.0".to_string())]);
}
self.timer_finished = true; self.timer_finished = true;
}, },
Scenes::Screen => { Scenes::Screen => {
hotkey_handler.change_scene(Scenes::Screen, Some(self.screen_sub_scene)); hotkey_handler.change_scene(Scenes::Screen, Some(self.screen_sub_scene));
self.timer_start = SystemTime::now(); self.timer_start = SystemTime::now();
self.timer_finished = false; self.timer_finished = false;
}, },
Scenes::Augmented => { Scenes::Augmented => {
hotkey_handler.change_scene(Scenes::Augmented, None); hotkey_handler.change_scene(Scenes::Augmented, None);
@ -126,6 +128,13 @@ impl MessageHandler for StreamState {
} }
} }
} }
// if the current scene was tapped again
else {
// current scene can only be the same as value, and timer is paused
if value.is_screen() && self.timer_paused_length.is_some() {
instruction = Some(vec![StateUpdate::PauseTimer(false)]);
}
}
self.current_scene = value; self.current_scene = value;
return (Some(update), instruction); return (Some(update), instruction);
@ -141,10 +150,17 @@ impl MessageHandler for StreamState {
} }
fn pause_timer(&mut self, do_pause: bool) -> (Option<StateUpdate>, Option<Vec<StateUpdate>>) { fn pause_timer(&mut self, do_pause: bool) -> (Option<StateUpdate>, Option<Vec<StateUpdate>>) {
let instruction: StateUpdate; let output: StateUpdate;
let mut instruction: Option<Vec<StateUpdate>> = None;
// if do pause, // if do pause,
if do_pause { if do_pause {
// if camera scene, don't allow it!
if self.current_scene.is_camera() {
return (None, None)
}
// stop tick from running, // stop tick from running,
self.timer_can_run = false; self.timer_can_run = false;
@ -171,20 +187,24 @@ impl MessageHandler for StreamState {
// Some fancy check to not have to use a match statement. The 'expect' should never be called, worry if it does // Some fancy check to not have to use a match statement. The 'expect' should never be called, worry if it does
let timer_paused_length: u16 = self.timer_paused_length.or(Some(0)).expect("timer_paused 'Some' unwrap somehow failed"); let timer_paused_length: u16 = self.timer_paused_length.or(Some(0)).expect("timer_paused 'Some' unwrap somehow failed");
// if camera scene, don't reset the time_start
if self.current_scene.is_camera() {
instruction = Some(vec![StateUpdate::TimerText("0.0".to_string())]);
self.timer_start += std::time::Duration::from_secs(self.timer_length as u64);
} else {
// update timer_start, taking into account the amount of time already run // update timer_start, taking into account the amount of time already run
self.timer_start = SystemTime::now() - self.timer_start = SystemTime::now() -
std::time::Duration::from_millis( std::time::Duration::from_millis(
// first get the decimal back from timer_paused_length, get the amount of time already run // first get the decimal back from timer_paused_length, get the amount of time already run
// then convert that to milliseconds, then from f32 to u64 // then convert that to milliseconds, then from f32 to u64
((self.timer_length - (timer_paused_length as f32 / 10.0)) * 1000.0) as u64); ((self.timer_length - (timer_paused_length as f32 / 10.0)) * 1000.0) as u64);
}
// Clear the paused time // Clear the paused time
self.timer_paused_length = None; self.timer_paused_length = None;
instruction = StateUpdate::PauseTimer(false); output = StateUpdate::PauseTimer(false);
} }
return (Some(instruction), None) return (Some(output), instruction)
} }
fn tick(&mut self) -> Vec<StateUpdate> { fn tick(&mut self) -> Vec<StateUpdate> {