Skip to content

Commit

Permalink
Add check preventing restarting the same audio resource. (#2002)
Browse files Browse the repository at this point in the history
* Add check preventing restarting the same audio resource.

* Fix docs.

* Move resource check to the Audio subsystem.
  • Loading branch information
CakeVR committed Jan 9, 2024
1 parent 1a2dc04 commit 918bf06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions addons/dialogic/Modules/Audio/event_music.gd
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@tool
## Event that can change the currently playing background music.
## This event won't play new music if it's already playing.
class_name DialogicMusicEvent
extends DialogicEvent

## Event that can change the currently playing background music.


### Settings

Expand All @@ -24,9 +24,10 @@ var loop: bool = true
################################################################################

func _execute() -> void:
dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop)
finish()
if not dialogic.Audio.is_music_playing_resource():
dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop)

finish()

################################################################################
## INITIALIZE
Expand Down Expand Up @@ -66,7 +67,7 @@ func get_shortcode_parameters() -> Dictionary:
## EDITOR REPRESENTATION
################################################################################

func build_event_editor():
func build_event_editor() -> void:
add_header_edit('file_path', ValueType.FILE, {
'left_text' : 'Play',
'file_filter' : "*.mp3, *.ogg, *.wav; Supported Audio Files",
Expand Down
10 changes: 10 additions & 0 deletions addons/dialogic/Modules/Audio/subsystem_audio.gd
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,15 @@ func stop_all_sounds() -> void:
if "Sound" in node.name:
node.queue_free()


func interpolate_volume_linearly(value :float, node:Node) -> void:
node.volume_db = linear_to_db(value)


## Returns whether the currently playing audio resource is the same as this
## event's [param resource_path].
func is_music_playing_resource(resource_path: String) -> bool:
var is_playing_resource: bool = (base_music_player.is_playing()
and base_music_player.stream.resource_path == resource_path)

return is_playing_resource

0 comments on commit 918bf06

Please sign in to comment.