Add addons

This commit is contained in:
Joey Yakimowich-Payne 2023-01-03 16:53:53 -07:00
commit 3367bad24f
No known key found for this signature in database
GPG key ID: 6BFE655FA5ABD1E1
527 changed files with 36197 additions and 0 deletions

View file

@ -0,0 +1,86 @@
@tool
class_name DialogicMusicEvent
extends DialogicEvent
## Event that can change the currently playing background music.
### Settings
## The file to play. If empty, the previous music will be faded out.
var file_path: String = ""
## The length of the fade. If 0 (by default) it's an instant change.
var fade_length: float = 0
## The volume the music will be played at.
var volume: float = 0
## The audio bus the music will be played at.
var audio_bus: String = "Master"
## If true, the audio will loop, otherwise only play once.
var loop: bool = true
################################################################################
## EXECUTE
################################################################################
func _execute() -> void:
dialogic.Audio.update_music(file_path, volume, audio_bus, fade_length, loop)
finish()
################################################################################
## INITIALIZE
################################################################################
func _init() -> void:
event_name = "Music"
set_default_color('Color5')
event_category = Category.AudioVisual
event_sorting_index = 2
expand_by_default = false
func _get_icon() -> Resource:
return load(self.get_script().get_path().get_base_dir().path_join('icon_music.png'))
################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "music"
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_info
"path" : {"property": "file_path", "default": ""},
"fade" : {"property": "fade_length", "default": 0},
"volume" : {"property": "volume", "default": 0},
"bus" : {"property": "audio_bus", "default": "Master",
"suggestions": get_bus_suggestions},
"loop" : {"property": "loop", "default": true,
"suggestions": func(): return {'True':{'value':'true'}, 'False':{'value':'false'}}},
}
################################################################################
## EDITOR REPRESENTATION
################################################################################
func build_event_editor():
add_header_edit('file_path', ValueType.File, 'Play', '',
{'file_filter' : "*.mp3, *.ogg, *.wav",
'placeholder' : "No music",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_body_edit('fade_length', ValueType.Float, 'Fade Time:')
add_body_edit('volume', ValueType.Decibel, 'volume:', '', {}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SinglelineText, 'audio_bus:', '', {}, '!file_path.is_empty()')
add_body_edit('loop', ValueType.Bool, 'loop:', '', {}, '!file_path.is_empty()')
func get_bus_suggestions() -> Dictionary:
var bus_name_list := {}
for i in range(AudioServer.bus_count):
bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
return bus_name_list

View file

@ -0,0 +1,81 @@
@tool
class_name DialogicSoundEvent
extends DialogicEvent
## Event that allows to play a sound effect. Requires the Audio subsystem!
### Settings
## The path to the file to play.
var file_path: String = ""
## The volume to play the sound at.
var volume: float = 0
## The bus to play the sound on.
var audio_bus: String = "Master"
## If true, the sound will loop infinitely. Not recommended (as there is no way to stop it).
var loop: bool = false
################################################################################
## EXECUTE
################################################################################
func _execute() -> void:
dialogic.Audio.play_sound(file_path, volume, audio_bus, loop)
finish()
################################################################################
## INITIALIZE
################################################################################
func _init() -> void:
event_name = "Sound"
set_default_color('Color5')
event_category = Category.AudioVisual
event_sorting_index = 3
expand_by_default = false
help_page_path = "https://dialogic.coppolaemilio.com"
func _get_icon() -> Resource:
return load(self.get_script().get_path().get_base_dir().path_join('icon_sound.png'))
################################################################################
## SAVING/LOADING
################################################################################
func get_shortcode() -> String:
return "sound"
func get_shortcode_parameters() -> Dictionary:
return {
#param_name : property_name
"path" : {"property": "file_path", "default": "",},
"volume" : {"property": "volume", "default": 0},
"bus" : {"property": "audio_bus", "default": "Master",
"suggestions": get_bus_suggestions},
"loop" : {"property": "loop", "default": false,
"suggestions": func(): return {'True':{'value':'true'}, 'False':{'value':'false'}}},
}
################################################################################
## EDITOR REPRESENTATION
################################################################################
func build_event_editor():
add_header_edit('file_path', ValueType.File, '', '',
{'file_filter' : '*.mp3, *.ogg, *.wav',
'placeholder' : "Select file",
'editor_icon' : ["AudioStreamPlayer", "EditorIcons"]})
add_body_edit('volume', ValueType.Decibel, 'volume:', '', {}, '!file_path.is_empty()')
add_body_edit('audio_bus', ValueType.SinglelineText, 'audio_bus:', '', {}, '!file_path.is_empty()')
func get_bus_suggestions() -> Dictionary:
var bus_name_list := {}
for i in range(AudioServer.bus_count):
bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
return bus_name_list

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://buvpjsvdt4evk"
path="res://.godot/imported/icon_music.png-9629b0cbb1d40f2776216a2874ccbd27.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/dialogic/Events/Audio/icon_music.png"
dest_files=["res://.godot/imported/icon_music.png-9629b0cbb1d40f2776216a2874ccbd27.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://d3ookrkto0yh6"
path="res://.godot/imported/icon_sound.png-00b9f09aba60dcc77e5ef32a9d1ac490.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/dialogic/Events/Audio/icon_sound.png"
dest_files=["res://.godot/imported/icon_sound.png-00b9f09aba60dcc77e5ef32a9d1ac490.ctex"]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,10 @@
@tool
extends DialogicIndexer
func _get_events() -> Array:
return [this_folder.path_join('event_music.gd'), this_folder.path_join('event_sound.gd')]
func _get_subsystems() -> Array:
return [{'name':'Audio', 'script':this_folder.path_join('subsystem_audio.gd')}]

View file

@ -0,0 +1,7 @@
class_name DialogicNode_MusicPlayer
extends AudioStreamPlayer
## An audio stream player that is used by dialogic to play music.
func _ready():
add_to_group('dialogic_music_player')

View file

@ -0,0 +1,7 @@
class_name DialogicNode_SoundPlayer
extends AudioStreamPlayer
## An audio stream player that is used by dialogic to play sounds.
func _ready():
add_to_group('dialogic_sound_player')

View file

@ -0,0 +1,95 @@
extends DialogicSubsystem
## Subsystem that manages music and sounds.
####################################################################################################
## STATE
####################################################################################################
func clear_game_state():
update_music()
stop_all_sounds()
func load_game_state():
var info = dialogic.current_state_info.get('music')
if info == null or info.path.is_empty():
update_music()
else:
update_music(info.path, info.volume, info.audio_bus, 0, info.loop)
func pause() -> void:
for node in get_tree().get_nodes_in_group('dialogic_music_player'):
node.stream_paused = true
for child in get_children():
child.stream_paused = true
func resume() -> void:
for node in get_tree().get_nodes_in_group('dialogic_music_player'):
node.stream_paused = false
for child in get_children():
child.stream_paused = false
####################################################################################################
## MAIN METHODS
####################################################################################################
## Updates the background music. Will fade out previous music.
func update_music(path:String = '', volume:float = 0.0, audio_bus:String = "Master", fade_time:float = 0.0, loop:bool = true) -> void:
dialogic.current_state_info['music'] = {'path':path, 'volume':volume, 'audio_bus':audio_bus, 'loop':loop}
for node in get_tree().get_nodes_in_group('dialogic_music_player'):
var fader: Tween = null
if node.playing or path:
fader = create_tween()
var prev_node = null
if node.playing:
prev_node = node.duplicate()
add_child(prev_node)
prev_node.play(node.get_playback_position())
prev_node.remove_from_group('dialogic_music_player')
fader.tween_method(interpolate_volume_linearly.bind(prev_node), db_to_linear(prev_node.volume_db),0.0,fade_time)
if path:
node.stream = load(path)
node.volume_db = volume
node.bus = audio_bus
if "loop" in node.stream:
node.stream.loop = loop
elif "loop_mode" in node.stream:
if loop:
node.stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
else:
node.stream.loop_mode = AudioStreamWAV.LOOP_DISABLED
node.play()
fader.parallel().tween_method(interpolate_volume_linearly.bind(node), 0.0,db_to_linear(volume),fade_time)
else:
node.stop()
if prev_node:
fader.tween_callback(prev_node.queue_free)
## Plays a given sound file.
func play_sound(path:String, volume:float = 0.0, audio_bus:String = "Master", loop :bool= false) -> void:
var sound_node: DialogicNode_SoundPlayer = get_tree().get_nodes_in_group('dialogic_sound_player').front()
if sound_node != null and !path.is_empty():
var new_sound_node: DialogicNode_SoundPlayer = sound_node.duplicate()
new_sound_node.stream = load(path)
if "loop" in new_sound_node.stream:
new_sound_node.stream.loop = loop
elif "loop_mode" in new_sound_node.stream:
if loop:
new_sound_node.stream.loop_mode = AudioStreamWAV.LOOP_FORWARD
else:
new_sound_node.stream.loop_mode = AudioStreamWAV.LOOP_DISABLED
new_sound_node.volume_db = volume
new_sound_node.bus = audio_bus
add_child(new_sound_node)
new_sound_node.play()
new_sound_node.finished.connect(new_sound_node.queue_free)
func stop_all_sounds() -> void:
var sound_nodes: Array = get_tree().get_nodes_in_group('dialogic_sound_player')
if !sound_nodes.is_empty():
for sound_player in sound_nodes.front().get_children():
sound_player.queue_free()
func interpolate_volume_linearly(value :float, node:Node) -> void:
node.volume_db = linear_to_db(value)