feat: refactor numerous areas and tokenize string literals where possible; also fixes some small bugs (#487)

Co-authored-by: Duncan Brown <duncan@bhs-consultants.com>
This commit is contained in:
Duncan Brown
2022-02-04 11:10:40 -05:00
committed by GitHub
parent 7913aadb6d
commit 99dc1e0110
50 changed files with 1103 additions and 593 deletions

View File

@@ -23,7 +23,7 @@ func _ready():
_tween.connect("tween_all_completed", self, "_target_reached")
escoria.object_manager.register_object(
ESCObject.new(
"_camera",
escoria.object_manager.CAMERA,
self
),
true
@@ -134,7 +134,7 @@ func set_target(p_target, p_speed : float = 0.0):
func set_camera_zoom(p_zoom_level: float, p_time: float):
if p_zoom_level <= 0.0:
escoria.logger.report_errors(
"camera.gd:set_camera_zoom()",
"esc_camera.gd:set_camera_zoom()",
["Tried to set negative or zero zoom level"]
)

View File

@@ -58,8 +58,10 @@ func _input(event):
#
# *Returns* The path to the matching voice file
func _get_voice_file(key: String, start: String = "") -> String:
if start == "":
start = ProjectSettings.get("escoria/sound/speech_folder")
if start == "":
start = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.SPEECH_FOLDER
)
var _dir = Directory.new()
if _dir.open(start) == OK:
_dir.list_dir_begin(true, true)
@@ -75,7 +77,9 @@ func _get_voice_file(key: String, start: String = "") -> String:
else:
if file_name == "%s.%s.import" % [
key,
ProjectSettings.get("escoria/sound/speech_extension")
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.SPEECH_EXTENSION
)
]:
return start.plus_file(file_name.trim_suffix(".import"))
file_name = _dir.get_next()
@@ -90,11 +94,13 @@ func _get_voice_file(key: String, start: String = "") -> String:
# - type: UI to use for the dialog
# - text: Text to say
func say(character: String, type: String, text: String) -> void:
if type == "":
type = ProjectSettings.get_setting("escoria/ui/default_dialog_type")
is_speaking = true
for _manager_class in ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
if type == "":
type = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_DIALOG_TYPE
)
is_speaking = true
for _manager_class in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
):
if ResourceLoader.exists(_manager_class):
var _manager: ESCDialogManager = load(_manager_class).new()
@@ -126,7 +132,7 @@ func say(character: String, type: String, text: String) -> void:
)
if _speech_resource != "":
(
escoria.object_manager.get_object("_speech").node\
escoria.object_manager.get_object(escoria.object_manager.SPEECH).node\
as ESCSpeechPlayer
).set_state(_speech_resource)
text = tr(matches.get_string("key"))
@@ -158,14 +164,14 @@ func speedup() -> void:
func start_dialog_choices(dialog: ESCDialog, type: String = "simple"):
if dialog.options.empty():
escoria.logger.report_errors(
"dialog_player.gd:start_dialog_choices()",
"esc_dialog_player.gd:start_dialog_choices()",
["Received answers array was empty."]
)
var _dialog_chooser_ui: ESCDialogManager = null
for _manager_class in ProjectSettings.get_setting(
"escoria/ui/dialog_managers"
for _manager_class in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
):
if ResourceLoader.exists(_manager_class):
var _manager: ESCDialogManager = load(_manager_class).new()

View File

@@ -8,6 +8,13 @@ onready var past_actions = $VBoxContainer/past_actions
# Reference to the command input
onready var command = $VBoxContainer/command
# ESC commands kept around for references to their command names.
var _debug: DebugCommand
func _ready() -> void:
_debug = DebugCommand.new()
# Run a command
#
@@ -23,18 +30,16 @@ func _on_command_text_entered(p_command_str : String):
past_actions.text += "# " + p_command_str
past_actions.text += "\n"
var actual_command = ":debug\n" + p_command_str + "\n"
var errors = []
var script = escoria.esc_compiler.compile([
":debug",
"%s%s" % [ESCEvent.PREFIX, _debug.get_command_name()],
p_command_str
])
if script:
escoria.event_manager.queue_event(script.events["debug"])
escoria.event_manager.queue_event(script.events[escoria.event_manager.EVENT_DEBUG])
var ret = yield(escoria.event_manager, "event_finished")
while ret[1] != "debug":
while ret[1] != _debug.get_command_name():
ret = yield(escoria.event_manager, "event_finished")
past_actions.text += "Returned code: %d" % ret[0]

View File

@@ -43,8 +43,8 @@ func add_new_item_by_id(item_id: String) -> void:
if not escoria.object_manager.has(item_id) or not is_instance_valid( \
escoria.object_manager.get_object(item_id).node):
var inventory_file = "%s/%s.tscn" % [
ProjectSettings.get_setting(
"escoria/ui/items_autoregister_path"
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.ITEMS_AUTOREGISTER_PATH
).trim_suffix("/"),
item_id
]

View File

@@ -44,8 +44,10 @@ func set_state(p_state: String, p_force: bool = false) -> void:
resource.loop_end = resource.mix_rate * resource.get_length()
elif "loop" in resource:
resource.loop = true
if ProjectSettings.has_setting("escoria/sound/music_volume"):
stream.volume_db = ProjectSettings.get_setting("escoria/sound/music_volume")
if escoria.project_settings_manager.has_setting(escoria.project_settings_manager.MUSIC_VOLUME):
stream.volume_db = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.MUSIC_VOLUME
)
stream.play()

View File

@@ -42,9 +42,11 @@ func set_state(p_state: String, p_force: bool = false):
if resource is AudioStreamSample:
resource.loop_mode = AudioStreamSample.LOOP_DISABLED
elif "loop" in resource:
resource.loop = false
if ProjectSettings.has_setting("escoria/sound/sound_volume"):
stream.volume_db = ProjectSettings.get_setting("escoria/sound/sound_volume")
resource.loop = false
if escoria.project_settings_manager.has_setting(escoria.project_settings_manager.SFX_VOLUME):
stream.volume_db = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.SFX_VOLUME
)
stream.play()

View File

@@ -94,10 +94,12 @@ func transition(
# *Returns* the full path to the shader or an empty string, if it can't be found
func get_transition(name: String) -> String:
if name.empty():
name = ProjectSettings.get_setting(
"escoria/ui/default_transition"
name = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANISITION
)
for directory in ProjectSettings.get_setting("escoria/ui/transition_paths"):
for directory in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.TRANSITION_PATHS
):
if ResourceLoader.exists(directory.plus_file("%s.material" % name)):
return directory.plus_file("%s.material" % name)
return ""