diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-08-24 09:20:38 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-08-24 09:30:19 +0200 |
commit | 31ea2b89222599b9282804191a673973bdad35b7 (patch) | |
tree | 8f307fd93d25c52d7aa85e8f962d8775bfc527e8 /game/src/Game/MusicConductor/MusicConductor.gd | |
parent | f59424ee1223bd509efdb2162b16415708a1ff6a (diff) |
Add signals to MusicConductor
Used for streamlining MusicPlayer
Enable music on startup
Add sound option loading on startup
Fix MusicPlayer play button starting with incorrect text
Diffstat (limited to 'game/src/Game/MusicConductor/MusicConductor.gd')
-rw-r--r-- | game/src/Game/MusicConductor/MusicConductor.gd | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/game/src/Game/MusicConductor/MusicConductor.gd b/game/src/Game/MusicConductor/MusicConductor.gd index 1326a30..f298db6 100644 --- a/game/src/Game/MusicConductor/MusicConductor.gd +++ b/game/src/Game/MusicConductor/MusicConductor.gd @@ -1,5 +1,11 @@ extends Node +signal song_paused(paused : bool) +signal song_started(track_id : int) +## Only triggers when song naturally ends +signal song_finished(track_id : int) +signal song_scrubbed(percentage : float, seconds : float) + # REQUIREMENTS # * SS-67 @export_dir var music_directory : String @@ -32,6 +38,7 @@ func get_current_song_name() -> String: func scrub_song_by_percentage(percentage: float) -> void: var percentInSeconds : float = (percentage / 100.0) * _audio_stream_player.stream.get_length() _audio_stream_player.play(percentInSeconds) + song_scrubbed.emit(percentage, percentInSeconds) func get_current_song_progress_percentage() -> float: return 100 * (_audio_stream_player.get_playback_position() / _audio_stream_player.stream.get_length()) @@ -41,13 +48,15 @@ func is_paused() -> bool: func set_paused(paused : bool) -> void: _audio_stream_player.stream_paused = paused + song_paused.emit(paused) func toggle_play_pause() -> void: - _audio_stream_player.stream_paused = !_audio_stream_player.stream_paused + set_paused(not is_paused()) func start_current_song() -> void: _audio_stream_player.stream = _available_songs[_selected_track].song_stream _audio_stream_player.play() + song_started.emit(_selected_track) # REQUIREMENTS # * SS-70 @@ -76,7 +85,6 @@ func _ready(): _selected_track = _available_songs.size() _available_songs.append(SongInfo.new(music_directory, fname)) start_current_song() - set_paused(true) func set_startup_music(play : bool) -> void: if not _has_startup_happened: @@ -84,6 +92,7 @@ func set_startup_music(play : bool) -> void: set_paused(not play) func _on_audio_stream_player_finished(): + song_finished.emit(_selected_track) if _auto_play_next_song: select_next_song() start_current_song() |