Skip to content

Commit

Permalink
feat: support changing speed in exercise mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Mivik committed Apr 21, 2023
1 parent e16b966 commit ad3afd0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions prpr/locales/en-US/game.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ adjust-offset = Adjust offset
offset-cancel = Cancel
offset-reset = Reset
offset-save = Save
speed = Speed
ex-time-out-of-range = Time is out of range
ex-invalid-format = Invalid format
Expand Down
1 change: 1 addition & 0 deletions prpr/locales/zh-CN/game.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ adjust-offset = 调整延迟
offset-cancel = 取消
offset-reset = 重置
offset-save = 保存
speed = 速度
ex-time-out-of-range = 时间不在范围内
ex-invalid-format = 格式有误
Expand Down
20 changes: 19 additions & 1 deletion prpr/src/scene/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,17 @@ impl GameScene {
}
Some(1) => {
let mut pos = self.music.position();
if (tm.speed - res.config.speed as f64).abs() > 0.01 {
debug!("recreating music");
self.music = res.audio.create_music(
res.music.clone(),
MusicParams {
amplifier: res.config.volume_music as _,
playback_rate: res.config.speed as _,
..Default::default()
},
)?;
}
if self.mode == GameMode::Exercise && tm.now() > self.exercise_range.end as f64 {
tm.seek_to(self.exercise_range.start as f64);
self.music.seek_to(self.exercise_range.start)?;
Expand All @@ -532,14 +543,21 @@ impl GameScene {
} else {
self.music.seek_to(dst)?;
}
let now = tm.now();
tm.speed = res.config.speed as _;
tm.resume();
tm.seek_to(tm.now() - 3.);
tm.seek_to(now - 3.);
self.pause_rewind = Some(tm.now() - 0.2);
}
_ => {}
}
}
if self.mode == GameMode::Exercise {
ui.scope(|ui| {
ui.dx(0.3);
ui.dy(-0.3);
ui.slider(tl!("speed"), 0.5..2.0, 0.05, &mut self.res.config.speed, Some(0.5));
});
ui.dy(0.06);
let hw = 0.7;
let h = 0.06;
Expand Down

0 comments on commit ad3afd0

Please sign in to comment.