From c1501e2f6e2a21cf773a8a9341f140357739c541 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Sat, 18 Mar 2023 14:35:00 +1030 Subject: [PATCH] slight refactor on menu sound playback --- scripts/TouchMenu.gd | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/TouchMenu.gd b/scripts/TouchMenu.gd index bfa18ab..149ce7f 100644 --- a/scripts/TouchMenu.gd +++ b/scripts/TouchMenu.gd @@ -496,48 +496,51 @@ func set_menu_mode(mode): menu_mode = mode menu_mode_prev_fade_timer = menu_mode_prev_fade_timer_duration +func play_sound(sound: AudioStream, volume_db: float = 0.0, pitch_scale: float = 1.0): + SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, sound, volume_db, pitch_scale) + func touch_select_song(touchdict): if (self.selected_genre == touchdict.genre_idx) and (self.selected_song_idx == touchdict.song_idx): - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0) + play_sound(snd_interact) # var songslist = genres[genres.keys()[selected_genre]] # selected_song_key = songslist[self.target_song_idx % len(songslist)] set_menu_mode(MenuMode.CHART_SELECT) else: self.selected_genre = touchdict.genre_idx self.target_song_idx = touchdict.song_idx - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, -4.5) + play_sound(snd_interact, -4.5) load_preview() func touch_select_chart(touchdict): if touchdict.chart_idx == selected_difficulty: if touchdict.enabled: - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0) + play_sound(snd_interact) set_menu_mode(MenuMode.GAMEPLAY) else: - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_error, 0.0) + play_sound(snd_error) elif touchdict.chart_idx < 0: - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, -3.0, 0.7) + play_sound(snd_interact, -3.0, 0.7) set_menu_mode(MenuMode.SONG_SELECT) else: self.selected_difficulty = touchdict.chart_idx - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, -4.5) + play_sound(snd_interact, -4.5) func touch_gameplay(touchdict): if touchdict.has('action'): - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0) + play_sound(snd_interact) if touchdict.action == 'stop': NoteHandler.stop() func touch_score_screen(touchdict): if touchdict.has('next_menu'): - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0) + play_sound(snd_interact) set_menu_mode(touchdict.next_menu) ScoreText.score = '' ScoreText.score_sub = '' # TODO: time this to coincide with the menu going fully offscreen ScoreText.update() elif touchdict.has('action'): - SoundPlayer.play(SoundPlayer.Type.NON_POSITIONAL, self, snd_interact, 0.0) + play_sound(snd_interact) if touchdict.action == 'save': save_score()