Skip to content

Commit

Permalink
Go back to menu after song is finished (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex authored Jun 6, 2024
1 parent 9316d80 commit 873d84a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions midi-file/src/playback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ impl PlaybackState {
self.running = time;
}

pub fn is_finished(&self) -> bool {
self.time() >= self.length()
}

pub fn percentage(&self) -> f32 {
self.running.as_secs_f32() / self.length().as_secs_f32()
}
Expand Down
4 changes: 4 additions & 0 deletions neothesia/src/scene/playing_scene/midi_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ impl MidiPlayer {
self.playback.percentage()
}

pub fn is_finished(&self) -> bool {
self.playback.is_finished()
}

pub fn time(&self) -> Duration {
self.playback.time()
}
Expand Down
4 changes: 4 additions & 0 deletions neothesia/src/scene/playing_scene/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ impl Scene for PlayingScene {

self.bg_quad_pipeline.prepare(&ctx.gpu.queue);
self.fg_quad_pipeline.prepare(&ctx.gpu.queue);

if self.player.is_finished() {
ctx.proxy.send_event(NeothesiaEvent::MainMenu).ok();
}
}

fn render<'pass>(
Expand Down

0 comments on commit 873d84a

Please sign in to comment.