aboutsummaryrefslogtreecommitdiff
path: root/game
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-08-24 09:20:38 +0200
committer Spartan322 <Megacake1234@gmail.com>2023-08-24 09:30:19 +0200
commit31ea2b89222599b9282804191a673973bdad35b7 (patch)
tree8f307fd93d25c52d7aa85e8f962d8775bfc527e8 /game
parentf59424ee1223bd509efdb2162b16415708a1ff6a (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')
-rw-r--r--game/src/Game/GameStart.gd8
-rw-r--r--game/src/Game/MusicConductor/MusicConductor.gd13
-rw-r--r--game/src/Game/MusicConductor/MusicPlayer.gd24
3 files changed, 27 insertions, 18 deletions
diff --git a/game/src/Game/GameStart.gd b/game/src/Game/GameStart.gd
index bfbbfb1..fa7568b 100644
--- a/game/src/Game/GameStart.gd
+++ b/game/src/Game/GameStart.gd
@@ -1,11 +1,19 @@
extends Control
const LoadingScreen = preload("res://src/Game/LoadingScreen.gd")
+const SoundTabScene = preload("res://src/Game/Menu/OptionMenu/SoundTab.tscn")
@export_subgroup("Nodes")
@export var loading_screen : LoadingScreen
func _ready() -> void:
+ # Hack to ensure Sound Options load
+ var sound_tab := SoundTabScene.instantiate()
+ sound_tab.visible = false
+ add_child(sound_tab)
+ Events.Options.load_settings_from_file()
+ sound_tab.queue_free()
+
loading_screen.start_loading_screen(_initialize_game)
# REQUIREMENTS
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()
diff --git a/game/src/Game/MusicConductor/MusicPlayer.gd b/game/src/Game/MusicConductor/MusicPlayer.gd
index e0a9006..e83ab9b 100644
--- a/game/src/Game/MusicConductor/MusicPlayer.gd
+++ b/game/src/Game/MusicConductor/MusicPlayer.gd
@@ -12,55 +12,47 @@ var _is_user_dragging_progress_slider : bool = false
func _ready():
for songName in MusicConductor.get_all_song_names():
_song_selector_button.add_item(songName, _song_selector_button.item_count)
- _update_song_name_visual()
- _update_play_pause_button()
+ _on_song_set(MusicConductor.get_current_song_index())
+ MusicConductor.song_started.connect(_on_song_set)
+ MusicConductor.song_paused.connect(_update_play_pause_button)
+ MusicConductor.song_scrubbed.connect(_update_play_pause_button)
_set_music_player_visible(MusicConductor.is_music_player_visible)
+func _on_song_set(track_id : int) -> void:
+ _song_selector_button.selected = track_id
+ _update_play_pause_button()
func _process(_delta):
if !_is_user_dragging_progress_slider:
_progress_slider.value = MusicConductor.get_current_song_progress_percentage()
-func _update_song_name_visual():
- _song_selector_button.selected = MusicConductor.get_current_song_index()
-
-func _update_play_pause_button():
+func _update_play_pause_button(_arg1 = null, _arg2 = null):
_play_pause_button.text = "◼" if MusicConductor.is_paused() else "▶"
func _on_play_pause_button_pressed():
MusicConductor.toggle_play_pause()
- _update_play_pause_button()
# REQUIREMENTS
# * UIFUN-93
func _on_next_song_button_pressed():
MusicConductor.select_next_song()
- _update_song_name_visual()
- _update_play_pause_button()
# REQUIREMENTS
# * UIFUN-94
func _on_previous_song_button_pressed():
MusicConductor.select_previous_song()
- _update_song_name_visual()
- _update_play_pause_button()
# REQUIREMENTS
# * UIFUN-95
func _on_option_button_item_selected(index):
MusicConductor.start_song_by_index(index)
- _update_song_name_visual()
- _update_play_pause_button()
-
func _on_progress_slider_drag_started():
_is_user_dragging_progress_slider = true
-
func _on_progress_slider_drag_ended(_value_changed):
MusicConductor.scrub_song_by_percentage(_progress_slider.value)
_is_user_dragging_progress_slider = false
- _update_play_pause_button()
func _set_music_player_visible(is_player_visible : bool) -> void:
MusicConductor.is_music_player_visible = is_player_visible