From f137d84a4673b9744ba9d1a883412b26686f8c0b Mon Sep 17 00:00:00 2001 From: Alula Date: Sat, 5 Sep 2020 04:08:59 +0200 Subject: [PATCH] save prev bgm song id as well --- src/sound/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sound/mod.rs b/src/sound/mod.rs index b2e6b00..256e0c4 100644 --- a/src/sound/mod.rs +++ b/src/sound/mod.rs @@ -22,6 +22,7 @@ mod wav; pub struct SoundManager { tx: Sender, + prev_song_id: usize, current_song_id: usize, } @@ -92,6 +93,7 @@ impl SoundManager { Ok(SoundManager { tx: tx.clone(), + prev_song_id: 0, current_song_id: 0, }) } @@ -110,6 +112,7 @@ impl SoundManager { let org = organya::Song::load_from(filesystem::open(ctx, ["/base/Org/", &song_name.to_lowercase(), ".org"].join(""))?)?; log::info!("Playing BGM: {}", song_name); + self.prev_song_id = self.current_song_id; self.current_song_id = song_id; self.tx.send(PlaybackMessage::SaveState)?; self.tx.send(PlaybackMessage::PlaySong(Box::new(org)))?; @@ -119,12 +122,14 @@ impl SoundManager { pub fn save_state(&mut self) -> GameResult { self.tx.send(PlaybackMessage::SaveState)?; + self.prev_song_id = self.current_song_id; Ok(()) } pub fn restore_state(&mut self) -> GameResult { self.tx.send(PlaybackMessage::RestoreState)?; + self.current_song_id = self.prev_song_id; Ok(()) }