add a command-line tool to jump to a certain timestamp

This commit is contained in:
Michael Zhang 2021-01-09 16:01:50 -06:00
parent d372c50ecf
commit a21bdbcafe
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B
2 changed files with 14 additions and 1 deletions

View file

@ -76,12 +76,18 @@ impl Game {
let dir = path.parent().unwrap();
let song = Sound::create(dir.join(&self.beatmap.inner.audio_filename))?;
song.set_position(65.0)?;
self.song = Some(song);
Ok(())
}
pub fn jump_to_time(&mut self, time: f64) -> Result<()> {
if let Some(song) = &self.song {
song.set_position(time)?;
}
Ok(())
}
pub fn toggle_playing(&mut self) {
if self.is_playing {
self.is_playing = false;

View file

@ -24,6 +24,9 @@ use crate::game::Game;
#[derive(StructOpt)]
struct Opt {
#[structopt(short = "s")]
start_time: Option<f64>,
path: Option<PathBuf>,
/// Verbose mode (-v, -vv, -vvv, etc)
@ -53,6 +56,10 @@ fn main() -> Result<()> {
game.load_beatmap(path)?;
}
if let Some(start_time) = opt.start_time {
game.jump_to_time(start_time)?;
}
event::run(&mut ctx, &mut event_loop, &mut game)?;
Ok(())