feat: adds adjustable reading speed/display time

This commit is contained in:
Duncan Brown
2022-11-11 20:50:49 -05:00
committed by Julian Murgia
parent 42e22f579b
commit a3da01e4cc
5 changed files with 63 additions and 24 deletions

View File

@@ -67,7 +67,8 @@ const _SIMPLE_DIALOG_ROOT = "dialog_simple"
const AVATARS_PATH = "%s/%s/avatars_path" % [_ESCORIA_SETTINGS_ROOT, _SIMPLE_DIALOG_ROOT]
const TEXT_SPEED_PER_CHARACTER = "%s/%s/text_speed_per_character" % [_ESCORIA_SETTINGS_ROOT, _SIMPLE_DIALOG_ROOT]
const FAST_TEXT_SPEED_PER_CHARACTER = "%s/%s/fast_text_speed_per_character" % [_ESCORIA_SETTINGS_ROOT, _SIMPLE_DIALOG_ROOT]
const MAX_TIME_TO_DISAPPEAR = "%s/%s/max_time_to_disappear" % [_ESCORIA_SETTINGS_ROOT, _SIMPLE_DIALOG_ROOT]
const READING_SPEED_IN_WPM = "%s/%s/reading_speed_in_wpm" % [_ESCORIA_SETTINGS_ROOT, _SIMPLE_DIALOG_ROOT]
# Godot Windows project settings
const DISPLAY = "display"

View File

@@ -37,7 +37,7 @@ func disable_plugin():
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.MAX_TIME_TO_DISAPPEAR,
ESCProjectSettingsManager.READING_SPEED_IN_WPM,
null,
{}
)
@@ -83,10 +83,10 @@ func enable_plugin():
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.MAX_TIME_TO_DISAPPEAR,
1.0,
ESCProjectSettingsManager.READING_SPEED_IN_WPM,
200,
{
"type": TYPE_REAL
"type": TYPE_INT
}
)
else:

View File

@@ -12,8 +12,12 @@ var _text_speed_per_character
# The text speed per character if the dialog line is skipped
var _fast_text_speed_per_character
# The time to wait before the dialog is finished
var _max_time_to_text_disappear
# The reading speed to be used in determining the length of time text remains
# on the screen.
var _reading_speed_in_wpm: int
# Used to extract words from lines of text.
var _word_regex: RegEx = RegEx.new()
# Whether the current dialog is speeding up
var _is_speeding_up: bool = false
@@ -42,9 +46,12 @@ func _ready():
_fast_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/fast_text_speed_per_character"
)
_max_time_to_text_disappear = ProjectSettings.get_setting(
"escoria/dialog_simple/max_time_to_disappear"
_reading_speed_in_wpm = ProjectSettings.get_setting(
"escoria/dialog_simple/reading_speed_in_wpm"
)
_word_regex.compile("\\S+")
text_node.bbcode_enabled = true
tween.connect(
"tween_completed",
@@ -111,11 +118,20 @@ func speedup():
# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
var time_to_disappear: float = _calculate_time_to_disappear()
text_node.visible_characters = -1
$Timer.start(_max_time_to_text_disappear)
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")
func _calculate_time_to_disappear() -> float:
return (_get_number_of_words() / _reading_speed_in_wpm as float) * 60
func _get_number_of_words() -> int:
return _word_regex.search_all(text_node.get_text()).size()
# Ending the dialog
func _on_dialog_finished():
emit_signal("say_finished")

View File

@@ -12,8 +12,12 @@ var _text_speed_per_character
# The text speed per character if the dialog line is skipped
var _fast_text_speed_per_character
# The time to wait before the dialog is finished
var _max_time_to_text_disappear
# The reading speed to be used in determining the length of time text remains
# on the screen.
var _reading_speed_in_wpm: int
# Used to extract words from lines of text.
var _word_regex: RegEx = RegEx.new()
# Current character speaking, to keep track of reference for animation purposes
@@ -41,9 +45,12 @@ func _ready():
_fast_text_speed_per_character = ProjectSettings.get_setting(
"escoria/dialog_simple/fast_text_speed_per_character"
)
_max_time_to_text_disappear = ProjectSettings.get_setting(
"escoria/dialog_simple/max_time_to_disappear"
_reading_speed_in_wpm = ProjectSettings.get_setting(
"escoria/dialog_simple/reading_speed_in_wpm"
)
_word_regex.compile("\\S+")
bbcode_enabled = true
$Tween.connect("tween_completed", self, "_on_dialog_line_typed")
@@ -134,11 +141,20 @@ func speedup():
# The dialog line was printed, start the waiting time and then finish
# the dialog
func _on_dialog_line_typed(object, key):
var time_to_disappear: float = _calculate_time_to_disappear()
text_node.visible_characters = -1
$Timer.start(_max_time_to_text_disappear)
$Timer.start(time_to_disappear)
$Timer.connect("timeout", self, "_on_dialog_finished")
func _calculate_time_to_disappear() -> float:
return (_get_number_of_words() / _reading_speed_in_wpm as float) * 60
func _get_number_of_words() -> int:
return _word_regex.search_all(text_node.get_text()).size()
# Ending the dialog
func _on_dialog_finished():
# Make the speaking item animation stop talking, if it is still alive