]> Untitled Git - wolf-seeking-sheep.git/blob - addons/dialogic/Modules/Audio/event_sound.gd
Updated export config options
[wolf-seeking-sheep.git] / addons / dialogic / Modules / Audio / event_sound.gd
1 @tool
2 class_name DialogicSoundEvent
3 extends DialogicEvent
4
5 ## Event that allows to play a sound effect. Requires the Audio subsystem!
6
7
8 ### Settings
9
10 ## The path to the file to play.
11 var file_path := "":
12         set(value):
13                 if file_path != value:
14                         file_path = value
15                         ui_update_needed.emit()
16 ## The volume to play the sound at.
17 var volume: float = 0
18 ## The bus to play the sound on.
19 var audio_bus := ""
20 ## If true, the sound will loop infinitely. Not recommended (as there is no way to stop it).
21 var loop := false
22
23
24 ################################################################################
25 ##                                              EXECUTE
26 ################################################################################
27
28 func _execute() -> void:
29         dialogic.Audio.play_sound(file_path, volume, audio_bus, loop)
30         finish()
31
32
33 ################################################################################
34 ##                                              INITIALIZE
35 ################################################################################
36
37 func _init() -> void:
38         event_name = "Sound"
39         set_default_color('Color7')
40         event_category = "Audio"
41         event_sorting_index = 3
42         help_page_path = "https://dialogic.coppolaemilio.com"
43
44
45 func _get_icon() -> Resource:
46         return load(self.get_script().get_path().get_base_dir().path_join('icon_sound.png'))
47
48 ################################################################################
49 ##                                              SAVING/LOADING
50 ################################################################################
51
52 func get_shortcode() -> String:
53         return "sound"
54
55
56 func get_shortcode_parameters() -> Dictionary:
57         return {
58                 #param_name : property_name
59                 "path"          : {"property": "file_path",     "default": "",},
60                 "volume"        : {"property": "volume",                "default": 0},
61                 "bus"           : {"property": "audio_bus",     "default": "",
62                                                         "suggestions": get_bus_suggestions},
63                 "loop"          : {"property": "loop",                  "default": false},
64         }
65
66
67 ################################################################################
68 ##                                              EDITOR REPRESENTATION
69 ################################################################################
70
71 func build_event_editor() -> void:
72         add_header_edit('file_path', ValueType.FILE,
73                         {'left_text'    : 'Play',
74                         'file_filter'   : '*.mp3, *.ogg, *.wav; Supported Audio Files',
75                         'placeholder'   : "Select file",
76                         'editor_icon'   : ["AudioStreamPlayer", "EditorIcons"]})
77         add_header_edit('file_path', ValueType.AUDIO_PREVIEW)
78         add_body_edit('volume', ValueType.NUMBER, {'left_text':'Volume:', 'mode':2}, '!file_path.is_empty()')
79         add_body_edit('audio_bus', ValueType.SINGLELINE_TEXT, {'left_text':'Audio Bus:'}, '!file_path.is_empty()')
80
81
82 func get_bus_suggestions() -> Dictionary:
83         var bus_name_list := {}
84         for i in range(AudioServer.bus_count):
85                 bus_name_list[AudioServer.get_bus_name(i)] = {'value':AudioServer.get_bus_name(i)}
86         return bus_name_list