Skip to content

Added Queues and BGM/BGS looping

Divided by Zer0 requested to merge dbyzer0/sound-manager:queuing into master

I wanted to create functionality to specify a number of tracks on my game to loop through as background music. I could do it externally in my own game, but I felt this functionality might be useful to other people.

Unfortunately due to the nature of the code and using the index of the children nodes, this was impossible to do with the current codebase. So I had to refactor things quite a bit. In the process I simplified the workflow and switched to some more simplified code.

  • I removed the index-based arrays
  • To discover playing tracks, I just check the existing children in runtime.
  • I class-named the Sounds.gd as SoundManagerAudioStreamPlayer. This avoids having to check if the node has a script.
  • I renamed sound_name to sound_path and added a new sound_name which stores the key the developer has given to this file in Audio_Files_Dictionary. This makes it more obvious what the variable stores.
  • Instead of having to keep track of children index, I am now using the sound.gd class directly. I have extended it to store more properties
  • Removed redundant self. pointers.
  • Added extra function get_all_playing_streams() which returns an Array of SoundManagerAudioStreamPlayer currently playing
  • Added extra function find_audiostream() which returns a SoundManagerAudioStreamPlayer which has that sound_name of sound_path
  • Added extra function get_sound_name_from_path() which returns the Audio_Files_Dictionary key which matches the sound_path provided
  • Added more static typing

On top of those I added 2 extra features

  • You can now queue sounds, and they will be played after the current sound ends, in a FIFO order.
    • Added functions queue_bgm and queue_bgs which handle this for these two types. I don't expect anyone will want to queue SE/ME types.
    • Queuing a sound when there's nothing in the queue already,will automatically start playing it.
    • Added function clear_queue() to empty the specified sound_type queue
  • Can now loop queues. A queue marked for looping will put any finished sound to the back of the queue.
    • Added function toggle_queue_repeat() which accepts a sound_type argument as string

PS: This includes the mp3 support, you you can skip that merge

Merge request reports