Issue 377 (#383)

* feat: Implements speech fixes #377

* docs: Automatic update of API docs

* chore: Updated speech translation.

Co-authored-by: Dennis Ploeger <develop@dieploegers.de>
Co-authored-by: dploeger <dploeger@users.noreply.github.com>
This commit is contained in:
Dennis Ploeger
2021-09-06 08:52:16 +02:00
committed by GitHub
parent 3dc779311c
commit c8958e7454
54 changed files with 279 additions and 85 deletions

View File

@@ -50,6 +50,31 @@ func _input(event):
if event is InputEventMouseButton and \
event.pressed:
finish_fast()
func _get_voice_file(key: String, start: String = "") -> String:
if start == "":
start = ProjectSettings.get("escoria/sound/speech_folder")
var _dir = Directory.new()
if _dir.open(start) == OK:
_dir.list_dir_begin(true, true)
var file_name = _dir.get_next()
while file_name != "":
if _dir.current_is_dir():
var _voice_file = _get_voice_file(
key,
start.plus_file(file_name)
)
if _voice_file != "":
return _voice_file
else:
if file_name == "%s.%s" % [
key,
ProjectSettings.get("escoria/sound/speech_extension")
]:
return start.plus_file(file_name)
file_name = _dir.get_next()
return ""
# A short one line dialog
@@ -63,7 +88,15 @@ func say(character: String, ui: String, line: String) -> void:
is_speaking = true
_dialog_ui = get_resource(ui).instance()
get_parent().add_child(_dialog_ui)
_dialog_ui.say(character, line)
var _key_line = line.split(":")
if _key_line.size() == 2:
var _speech_resource = _get_voice_file(_key_line[0])
if _speech_resource != "":
(
escoria.object_manager.get_object("_speech").node\
as ESCSpeechPlayer
).set_state(_speech_resource)
_dialog_ui.say(character, _key_line[1])
yield(_dialog_ui, "dialog_line_finished")
is_speaking = false
emit_signal("dialog_line_finished")

View File

@@ -2,7 +2,7 @@
[ext_resource path="res://game/ui/commons/dialogs/dialog_label.tscn" type="PackedScene" id=1]
[ext_resource path="res://game/ui/commons/dialogs/text_dialog_choice.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/dialog_player.gd" type="Script" id=3]
[ext_resource path="res://addons/escoria-core/game/scenes/dialogs/esc_dialog_player.gd" type="Script" id=3]
[ext_resource path="res://game/ui/commons/dialogs/dialog_box_inset.tscn" type="PackedScene" id=4]
[node name="dialog_player" type="ResourcePreloader"]

View File

@@ -1,10 +1,10 @@
# Background music player
extends Control
class_name ESCBackgroundMusic
class_name ESCMusicPlayer
# Global id of the background music player
export var global_id: String = "bg_music"
export var global_id: String = "_music"
# The state of the music player. "default" or "off" disable music

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_music.gd" type="Script" id=1]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/esc_music_player.gd" type="Script" id=1]
[node name="bg_music" type="Control"]
anchor_right = 1.0

View File

@@ -1,10 +1,10 @@
# Background sound player
extends Control
class_name ESCBackgroundSound
class_name ESCSoundPlayer
# Global id of the background sound player
export var global_id: String = "bg_sound"
export var global_id: String = "_sound"
# The state of the sound player. "default" or "off" disable sound

View File

@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/bg_sound.gd" type="Script" id=1]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/esc_sound_player.gd" type="Script" id=1]
[node name="bg_sound" type="Control"]
anchor_right = 1.0

View File

@@ -0,0 +1,44 @@
# Speech player
extends Control
class_name ESCSpeechPlayer
# Global id of the background music player
export var global_id: String = "_speech"
# Set the state of this player
#
# #### Parameters
#
# - p_state: New state to use
# - p_force: Override the existing state even if the stream is still playing
func set_state(p_state: String, p_force: bool = false) -> void:
# If speech is disabled, return
if not escoria.settings.speech_enabled:
return
# If state is "off"/"default", turn off speech
if p_state in ["off", "default"]:
$AudioStreamPlayer.stream = null
return
var resource = load(p_state)
$AudioStreamPlayer.stream = resource
if $AudioStreamPlayer.stream:
resource.set_loop(false)
$AudioStreamPlayer.play()
# Register to the object registry
func _ready():
escoria.object_manager.register_object(
ESCObject.new(global_id, self),
true
)
func _on_AudioStreamPlayer_finished() -> void:
set_state("off")

View File

@@ -0,0 +1,17 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://addons/escoria-core/game/scenes/sound/esc_speech_player.gd" type="Script" id=1]
[node name="Control" type="Control"]
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"]