fix seek when paused

This commit is contained in:
2026-02-27 08:10:16 -08:00
parent 3644dd7f15
commit a4c4f20bad
4 changed files with 18 additions and 4 deletions

View File

@@ -41,6 +41,9 @@ impl PlaybackHead{
pub fn time(&self,time:SessionTime)->Time{
self.timer.time(time)
}
pub fn timer(&self)->&Timer<Scaled<SessionTimeInner,TimeInner>>{
&self.timer
}
pub fn set_paused(&mut self,time:SessionTime,paused:bool){
_=self.timer.set_paused(time,paused);
}
@@ -60,6 +63,9 @@ impl PlaybackHead{
self.state=PlaybackState::new();
self.state.process_head(bot.timelines(),&self.head);
}
pub fn get_scale(&self)->strafesnet_common::integer::Ratio64{
self.timer.get_scale()
}
pub fn set_scale(&mut self,time:SessionTime,new_scale:strafesnet_common::integer::Ratio64){
self.timer.set_scale(time,new_scale);
}

View File

@@ -1,5 +1,6 @@
use strafesnet_common::instruction::TimedInstruction;
use strafesnet_common::session::Time as SessionTime;
use strafesnet_common::timer::TimerState;
use strafesnet_roblox_bot_player::{bot::CompleteBot,graphics::Graphics,head::{PlaybackHead,Time as PlaybackTime}};
pub enum SessionControlInstruction{
@@ -57,11 +58,11 @@ impl<'a> PlayerWorker<'a>{
self.playback_head.set_time(bot,ins.time,PlaybackTime::ZERO);
},
Instruction::SessionControl(SessionControlInstruction::SkipForward)=>if let Some(bot)=&self.bot{
let head_time=self.playback_head.time(ins.time+SessionTime::from_secs(2));
let head_time=self.playback_head.timer().clone().into_state().0.get_time(ins.time+SessionTime::from_secs(2));
self.playback_head.set_time(bot,ins.time,head_time);
},
Instruction::SessionControl(SessionControlInstruction::SkipBack)=>if let Some(bot)=&self.bot{
let head_time=self.playback_head.time(ins.time-SessionTime::from_secs(2));
let head_time=self.playback_head.timer().clone().into_state().0.get_time(ins.time-SessionTime::from_secs(2));
self.playback_head.set_time(bot,ins.time,head_time);
},
Instruction::SessionControl(SessionControlInstruction::DecreaseTimescale)=>{

View File

@@ -122,6 +122,11 @@ impl PlaybackHead{
self.head.set_paused(time,paused);
}
#[wasm_bindgen]
pub fn get_scale(&mut self)->f64{
let scale=self.head.get_scale();
scale.num() as f64/scale.den() as f64
}
#[wasm_bindgen]
pub fn set_scale(&mut self,time:f64,scale:f64){
let time=time::from_float(time).unwrap();
self.head.set_scale(time,scale.try_into().unwrap());

View File

@@ -54,6 +54,8 @@ function set_scale(new_scale) {
control_speed.value = `${scale.toPrecision(3)}x`;
}
const SEEK_DURATION = 1.0;
// Controls
document.getElementById("control_reset").addEventListener("click", (e) => {
playback.set_head_time(bot, elapsed(), 0.0);
@@ -64,12 +66,12 @@ document.getElementById("control_pause").addEventListener("click", (e) => {
});
document.getElementById("control_forward").addEventListener("click", (e) => {
const time_now = elapsed();
const playback_time = playback.get_head_time(time_now + 2.0);
const playback_time = playback.get_head_time(time_now) + playback.get_scale() * SEEK_DURATION;
playback.set_head_time(bot, time_now, playback_time);
});
document.getElementById("control_backward").addEventListener("click", (e) => {
const time_now = elapsed();
const playback_time = playback.get_head_time(time_now - 2.0);
const playback_time = playback.get_head_time(time_now) + playback.get_scale() * SEEK_DURATION;
playback.set_head_time(bot, time_now, playback_time);
});
document.getElementById("control_slower").addEventListener("click", (e) => {