aboutsummaryrefslogtreecommitdiff
path: root/game/src/MusicConductor/MusicConductor.gd
diff options
context:
space:
mode:
author Spartan322 <Megacake1234@gmail.com>2023-03-08 23:15:15 +0100
committer Spartan322 <Megacake1234@gmail.com>2023-03-09 02:18:39 +0100
commit99c99ce56bb3e73e65ff70352d4c9eef3d7f0f86 (patch)
treef3808a85792e5d58db8297211e5887b0c92d29d5 /game/src/MusicConductor/MusicConductor.gd
parentec0584d9fafd96753aed73e7c388da8e2f5b3833 (diff)
Fix up MusicPlayer for future work
Add music import files Rename MusicUIController to MusicPlayer Adjust MusicPlayer node position, offset, and anchors Adjust MusicConductor, MusicPlayer, and SongInfo style to conform with other GDScript files Correct capability for MusicPlayer to desync from the MusicConductor Adjusted MusicPlayer button text to use media player unicode symbols Adjust MusicPlayer to correct mouse filter problems Adjust MusicPlayer to appear more consistent Correct lack of path_join use in SongInfo Correct mouse filter problems in OptionsMenu
Diffstat (limited to 'game/src/MusicConductor/MusicConductor.gd')
-rw-r--r--game/src/MusicConductor/MusicConductor.gd75
1 files changed, 39 insertions, 36 deletions
diff --git a/game/src/MusicConductor/MusicConductor.gd b/game/src/MusicConductor/MusicConductor.gd
index a463d6d..1dfa95d 100644
--- a/game/src/MusicConductor/MusicConductor.gd
+++ b/game/src/MusicConductor/MusicConductor.gd
@@ -1,68 +1,71 @@
extends Node
# SS-67
-@export_dir var musicDir : String
-@export_file var firstSongName : String
+@export_dir var music_directory : String
+@export var first_song_name : String
-var selectedTrack = 0
-var availableSongs : Array[SongInfo] = []
-var autoPlayNextSong : bool = true
+var _selected_track = 0
+var _available_songs : Array[SongInfo] = []
+var _auto_play_next_song : bool = true
-func getAllSongNames() -> Array[String]:
+## True if music player should be visible.
+## Used to keep keep consistency between scene changes
+var is_music_player_visible : bool = true
+
+func get_all_song_names() -> Array[String]:
var songNames : Array[String] = []
- for si in availableSongs:
- songNames.append(si.readableName)
+ for si in _available_songs:
+ songNames.append(si.song_name)
return songNames
-func getCurrentSongIndex() -> int:
- return selectedTrack
+func get_current_song_index() -> int:
+ return _selected_track
-func getCurrentSongName() -> String:
- return availableSongs[selectedTrack].readableName
+func get_current_song_name() -> String:
+ return _available_songs[_selected_track].song_name
-func scrubSongByPercentage(percentage: float) -> void:
+func scrub_song_by_percentage(percentage: float) -> void:
var percentInSeconds : float = (percentage / 100.0) * $AudioStreamPlayer.stream.get_length()
$AudioStreamPlayer.play(percentInSeconds)
-func getCurrentSongProgressPercentage() -> float:
+func get_current_song_progress_percentage() -> float:
return 100 * ($AudioStreamPlayer.get_playback_position() / $AudioStreamPlayer.stream.get_length())
-func isPaused() -> bool:
+func is_paused() -> bool:
return $AudioStreamPlayer.stream_paused
-func togglePlayPause() -> void:
+func toggle_play_pause() -> void:
$AudioStreamPlayer.stream_paused = !$AudioStreamPlayer.stream_paused
-func startCurrentSong() -> void:
- $AudioStreamPlayer.stream = availableSongs[selectedTrack].loadedStream
+func start_current_song() -> void:
+ $AudioStreamPlayer.stream = _available_songs[_selected_track].song_stream
$AudioStreamPlayer.play()
# SS-70
-func startSongByIndex(id: int) -> void:
- selectedTrack = id
- startCurrentSong()
+func start_song_by_index(id: int) -> void:
+ _selected_track = id
+ start_current_song()
# SS-69
-func nextSong() -> void:
- selectedTrack = (selectedTrack + 1) % len(availableSongs)
- startCurrentSong()
+func select_next_song() -> void:
+ _selected_track = (_selected_track + 1) % len(_available_songs)
+ start_current_song()
-func prevSong() -> void:
- selectedTrack = (len(availableSongs) - 1) if (selectedTrack == 0) else (selectedTrack - 1)
- startCurrentSong()
+func select_previous_song() -> void:
+ _selected_track = (len(_available_songs) - 1) if (_selected_track == 0) else (_selected_track - 1)
+ start_current_song()
-# Called when the node enters the scene tree for the first time.
func _ready():
- var dir = DirAccess.open(musicDir)
+ var dir = DirAccess.open(music_directory)
for fname in dir.get_files():
if !fname.ends_with(".import"):
- if fname.get_basename() == firstSongName:
- selectedTrack = availableSongs.size()
- availableSongs.append(SongInfo.new(musicDir, fname))
- startCurrentSong()
+ if fname.get_basename() == first_song_name:
+ _selected_track = _available_songs.size()
+ _available_songs.append(SongInfo.new(music_directory, fname))
+ start_current_song()
func _on_audio_stream_player_finished():
- if autoPlayNextSong:
- nextSong()
- startCurrentSong()
+ if _auto_play_next_song:
+ select_next_song()
+ start_current_song()