fixed and implemented #8
This commit is contained in:
parent
21c38e275a
commit
cce730a57f
1 changed files with 33 additions and 13 deletions
|
@ -105,20 +105,22 @@ 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));
|
||||||
instruction = Some(vec![StateUpdate::TimerText("0.0".to_string())]);
|
if self.timer_paused_length.is_none() {
|
||||||
|
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");
|
||||||
|
|
||||||
// update timer_start, taking into account the amount of time already run
|
// if camera scene, don't reset the time_start
|
||||||
self.timer_start = SystemTime::now() -
|
if self.current_scene.is_camera() {
|
||||||
std::time::Duration::from_millis(
|
instruction = Some(vec![StateUpdate::TimerText("0.0".to_string())]);
|
||||||
// first get the decimal back from timer_paused_length, get the amount of time already run
|
self.timer_start += std::time::Duration::from_secs(self.timer_length as u64);
|
||||||
// then convert that to milliseconds, then from f32 to u64
|
} else {
|
||||||
((self.timer_length - (timer_paused_length as f32 / 10.0)) * 1000.0) as u64);
|
// update timer_start, taking into account the amount of time already run
|
||||||
|
self.timer_start = SystemTime::now() -
|
||||||
|
std::time::Duration::from_millis(
|
||||||
|
// 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
|
||||||
|
((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> {
|
||||||
|
|
Loading…
Reference in a new issue