diff options
Diffstat (limited to 'addons/escoria-core/game/scenes/sound')
12 files changed, 422 insertions, 0 deletions
diff --git a/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd b/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd new file mode 100644 index 0000000..298e7db --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd @@ -0,0 +1,61 @@ +## Background ambient sound player +extends Control +class_name ESCAmbientPlayer + +## Global id of the background ambient sound player. +@export var global_id: String = "_ambient" + +## The state of the music player. "default" or "off" disable music. Any other +## state refers to a music stream that should be played. +var state: String = "default" + +## Reference to the audio player. +@onready var stream: AudioStreamPlayer = $AudioStreamPlayer + +## Sets the state of this player.[br] +## [br] +## #### Parameters[br] +## [br] +## - p_state: New state to use.[br] +## - from_seconds: Sets the starting playback position.[br] +## - p_force: Override the existing state even if the stream is still playing. +func set_state(p_state: String, from_seconds: float = 0.0, p_force: bool = false) -> void: + # If already playing this stream, keep playing, unless p_force + if p_state == state and not p_force and stream.is_playing(): + return + + state = p_state + + # If state is "off"/"default", turn off music + if state == "off" or state == "default": + stream.stream = null + return + + var resource = load(p_state) + + stream.stream = resource + + if stream.stream: + if resource is AudioStreamWAV: + resource.loop_mode = AudioStreamWAV.LOOP_FORWARD + resource.loop_end = resource.mix_rate * resource.get_length() + elif "loop" in resource: + resource.loop = true + stream.play(from_seconds) + + +## Registers this music player to the object registry. +func _ready(): + process_mode = Node.PROCESS_MODE_PAUSABLE + escoria.object_manager.register_object( + ESCObject.new(global_id, self), + null, + true + ) + + +## Returns the playback position of the audio stream in seconds.[br] +## [br] +## *Returns* the playback position as a float value. +func get_playback_position() -> float: + return $AudioStreamPlayer.get_playback_position() diff --git a/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd.uid b/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd.uid new file mode 100644 index 0000000..7a20f5b --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_ambient_player.gd.uid @@ -0,0 +1 @@ +uid://b6kjfij1s1lpb diff --git a/addons/escoria-core/game/scenes/sound/esc_ambient_player.tscn b/addons/escoria-core/game/scenes/sound/esc_ambient_player.tscn new file mode 100644 index 0000000..ca4f039 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_ambient_player.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=3 uid="uid://wsdpiju6bxqd"] + +[ext_resource type="Script" uid="uid://b6kjfij1s1lpb" path="res://addons/escoria-core/game/scenes/sound/esc_ambient_player.gd" id="1_ih1im"] + +[node name="bg_ambient" type="Control"] +process_mode = 3 +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1680.0 +offset_bottom = -1050.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +script = ExtResource("1_ih1im") + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = &"Ambient" diff --git a/addons/escoria-core/game/scenes/sound/esc_music_player.gd b/addons/escoria-core/game/scenes/sound/esc_music_player.gd new file mode 100644 index 0000000..b8f6c45 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_music_player.gd @@ -0,0 +1,81 @@ +## Background music player +extends Control +class_name ESCMusicPlayer + +## Global id of the background music player. +@export var global_id: String = "_music" + +## The state of the music player. "default" or "off" disable music. Any other +## state refers to a music stream that should be played. +var state: String = "default" + +## Reference to the audio player. +@onready var stream: AudioStreamPlayer = $AudioStreamPlayer + +## Sets the state of this player.[br] +## [br] +## #### Parameters[br] +## [br] +## | Name | Type | Description | Required? |[br] +## |:-----|:-----|:------------|:----------|[br] +## |p_state|`String`|New state to use.|yes|[br] +## |from_seconds|`float`|Sets the starting playback position.|no|[br] +## |p_force|`bool`|Override the existing state even if the stream is still playing.|no|[br] +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func set_state(p_state: String, from_seconds: float = 0.0, p_force: bool = false) -> void: + # If already playing this stream, keep playing, unless p_force + if p_state == state and not p_force and stream.is_playing(): + return + + state = p_state + + # If state is "off"/"default", turn off music + if state == "off" or state == "default": + stream.stream = null + return + + var resource = load(p_state) + + stream.stream = resource + + if stream.stream: + if resource is AudioStreamWAV: + resource.loop_mode = AudioStreamWAV.LOOP_FORWARD + resource.loop_end = resource.mix_rate * resource.get_length() + elif "loop" in resource: + resource.loop = true + stream.play(from_seconds) + + +## Registers this music player to the object registry.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func _ready(): + process_mode = Node.PROCESS_MODE_PAUSABLE + escoria.object_manager.register_object( + ESCObject.new(global_id, self), + null, + true + ) + + +## The playback position of the audio stream in seconds.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns the playback position of the audio stream in seconds. the playback position as a float value. (`float`) +func get_playback_position() -> float: + return $AudioStreamPlayer.get_playback_position() diff --git a/addons/escoria-core/game/scenes/sound/esc_music_player.gd.uid b/addons/escoria-core/game/scenes/sound/esc_music_player.gd.uid new file mode 100644 index 0000000..50d1f36 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_music_player.gd.uid @@ -0,0 +1 @@ +uid://ch8x1lue4qy34 diff --git a/addons/escoria-core/game/scenes/sound/esc_music_player.tscn b/addons/escoria-core/game/scenes/sound/esc_music_player.tscn new file mode 100644 index 0000000..5e71381 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_music_player.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=2 format=3 uid="uid://c1txn45mpksqd"] + +[ext_resource type="Script" uid="uid://ch8x1lue4qy34" path="res://addons/escoria-core/game/scenes/sound/esc_music_player.gd" id="1"] + +[node name="bg_music" type="Control"] +process_mode = 3 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1680.0 +offset_bottom = -1050.0 +mouse_filter = 2 +script = ExtResource("1") + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = "Music" diff --git a/addons/escoria-core/game/scenes/sound/esc_sound_player.gd b/addons/escoria-core/game/scenes/sound/esc_sound_player.gd new file mode 100644 index 0000000..2a9fa64 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_sound_player.gd @@ -0,0 +1,93 @@ +## Background sound player +extends Control +class_name ESCSoundPlayer + +## Global id of the sfx sound player. +@export var global_id: String = "_sound" + +## The state of the sound player. "default" or "off" disable sound. Any other +## state refers to a sound stream that should be played. +var state: String = "default" + +## Reference to the audio player. +@onready var stream: AudioStreamPlayer = $AudioStreamPlayer + +## Sets the state of this player.[br] +## [br] +## #### Parameters[br] +## [br] +## | Name | Type | Description | Required? |[br] +## |:-----|:-----|:------------|:----------|[br] +## |p_state|`String`|New state to use.|yes|[br] +## |from_seconds|`float`|Sets the starting playback position.|no|[br] +## |p_force|`bool`|Override the existing state even if the stream is still playing.|no|[br] +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func set_state(p_state: String, from_seconds: float = 0.0, p_force: bool = false): + # If already playing this stream, keep playing, unless p_force + if p_state == state and not p_force and stream.is_playing(): + return + + state = p_state + + # If state is "off"/"default", turn off music + if state == "off" or state == "default": + stream.stream = null + return + + var resource = load(p_state) + + stream.stream = resource + + if stream.stream: + if resource is AudioStreamWAV: + resource.loop_mode = AudioStreamWAV.LOOP_DISABLED + elif "loop" in resource: + resource.loop = false + stream.play(from_seconds) + + +## Registers this sound player to the object registry.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func _ready(): + process_mode = Node.PROCESS_MODE_PAUSABLE + escoria.object_manager.register_object( + ESCObject.new(global_id, self), + null, + true + ) + + +## Sets state to default when finished playing.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func _on_sound_finished(): + state = "default" + + +## The playback position of the audio stream in seconds.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns the playback position of the audio stream in seconds. The playback position in seconds. (`float`) +func get_playback_position() -> float: + return $AudioStreamPlayer.get_playback_position() diff --git a/addons/escoria-core/game/scenes/sound/esc_sound_player.gd.uid b/addons/escoria-core/game/scenes/sound/esc_sound_player.gd.uid new file mode 100644 index 0000000..2831142 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_sound_player.gd.uid @@ -0,0 +1 @@ +uid://b4fkhx0prl41e diff --git a/addons/escoria-core/game/scenes/sound/esc_sound_player.tscn b/addons/escoria-core/game/scenes/sound/esc_sound_player.tscn new file mode 100644 index 0000000..984e040 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_sound_player.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=3 uid="uid://uwqpnwjmp6aq"] + +[ext_resource type="Script" uid="uid://b4fkhx0prl41e" path="res://addons/escoria-core/game/scenes/sound/esc_sound_player.gd" id="1"] + +[node name="bg_sound" type="Control"] +process_mode = 3 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1680.0 +offset_bottom = -1050.0 +mouse_filter = 2 +script = ExtResource("1") +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = "SFX" + +[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_sound_finished"] diff --git a/addons/escoria-core/game/scenes/sound/esc_speech_player.gd b/addons/escoria-core/game/scenes/sound/esc_speech_player.gd new file mode 100644 index 0000000..31fc668 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_speech_player.gd @@ -0,0 +1,111 @@ +## Speech player +extends Control +class_name ESCSpeechPlayer + +## Global id of the speech player. +@export var global_id: String = "_speech" + +## Reference to the audio player. +@onready var stream: AudioStreamPlayer = $AudioStreamPlayer + +## Sets the state of this player.[br] +## [br] +## #### Parameters[br] +## [br] +## | Name | Type | Description | Required? |[br] +## |:-----|:-----|:------------|:----------|[br] +## |p_state|`String`|New state to use.|yes|[br] +## |from_seconds|`float`|Sets the starting playback position.|no|[br] +## |p_force|`bool`|Override the existing state even if the stream is still playing.|no|[br] +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func set_state(p_state: String, from_seconds: float = 0.0, p_force: bool = false) -> void: + # If speech is disabled, return + if not ESCProjectSettingsManager.get_setting( + ESCProjectSettingsManager.SPEECH_ENABLED + ): + return + + # If state is "off"/"default", turn off speech + if p_state in ["off", "default"]: + stream.stream = null + return + + var resource = load(p_state) + stream.stream = resource + + if stream.stream: + stream.stream.set_loop(false) + $AudioStreamPlayer.play(from_seconds) + + +## Registers this speech player to the object registry.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func _ready(): + process_mode = Node.PROCESS_MODE_PAUSABLE + escoria.object_manager.register_object( + ESCObject.new(global_id, self), + null, + true + ) + + +## Callback called when the audio stream player finished playing.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func _on_AudioStreamPlayer_finished() -> void: + set_state("off") + + +## Pauses the speech player.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func pause(): + stream.stream_paused = true + + +## Unpauses the speech player.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns nothing. +func resume(): + stream.stream_paused = false + + +## The playback position of the audio stream in seconds.[br] +## [br] +## #### Parameters[br] +## [br] +## None. +## [br] +## #### Returns[br] +## [br] +## Returns the playback position of the audio stream in seconds. The playback position in seconds. (`float`) +func get_playback_position() -> float: + return $AudioStreamPlayer.get_playback_position() diff --git a/addons/escoria-core/game/scenes/sound/esc_speech_player.gd.uid b/addons/escoria-core/game/scenes/sound/esc_speech_player.gd.uid new file mode 100644 index 0000000..63a6af9 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_speech_player.gd.uid @@ -0,0 +1 @@ +uid://6aijk4hl0t0o diff --git a/addons/escoria-core/game/scenes/sound/esc_speech_player.tscn b/addons/escoria-core/game/scenes/sound/esc_speech_player.tscn new file mode 100644 index 0000000..2142df8 --- /dev/null +++ b/addons/escoria-core/game/scenes/sound/esc_speech_player.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=2 format=3 uid="uid://c8ecyitwga1dx"] + +[ext_resource type="Script" uid="uid://6aijk4hl0t0o" path="res://addons/escoria-core/game/scenes/sound/esc_speech_player.gd" id="1"] + +[node name="Control" type="Control"] +process_mode = 3 +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +script = ExtResource("1") +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."] +bus = "Speech" + +[connection signal="finished" from="AudioStreamPlayer" to="." method="_on_AudioStreamPlayer_finished"] |
