ESC compiler rewrite
Splits the former ESC_Runner and ESC_Level_Runner into multiple dedicated managers. Authored-by: Dennis Ploeger <develop@dieploegers.de>
This commit is contained in:
@@ -185,5 +185,11 @@ func _ready():
|
||||
target = Vector2(0, 0)
|
||||
|
||||
tween.connect("tween_completed", self, "target_reached")
|
||||
escoria.register_object(self)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(
|
||||
self.name,
|
||||
self
|
||||
),
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -1,76 +1,108 @@
|
||||
# Escoria dialog player
|
||||
tool
|
||||
extends ResourcePreloader
|
||||
class_name ESCDialogsPlayer
|
||||
|
||||
func get_class():
|
||||
return "ESCDialogsPlayer"
|
||||
|
||||
# This scene is in charge of ALL dialogs management :
|
||||
# - characters sayings
|
||||
# - player dialog options panel display/hiding and choices
|
||||
# Emitted when an answer as chosem
|
||||
#
|
||||
# ##### Parameters
|
||||
#
|
||||
# - option: The dialog option that was chosen
|
||||
signal option_chosen(option)
|
||||
|
||||
var path_to_dialog_scenes : String
|
||||
# Emitted when a dialog line was finished
|
||||
signal dialog_line_finished
|
||||
|
||||
|
||||
# Wether the player is currently speaking
|
||||
var is_speaking = false
|
||||
var dialog_ui = null
|
||||
var dialog_chooser_ui = null
|
||||
|
||||
# Reference to the dialog UI
|
||||
var _dialog_ui = null
|
||||
|
||||
# Reference to the dialog chooser UI
|
||||
var _dialog_chooser_ui = null
|
||||
|
||||
|
||||
# Register the dialog player and load the dialog resources
|
||||
func _ready():
|
||||
if !Engine.is_editor_hint():
|
||||
escoria.register_object(self)
|
||||
escoria.dialog_player = self
|
||||
preload_resources(ProjectSettings.get_setting("escoria/ui/dialogs_folder"))
|
||||
|
||||
func preload_resources(path : String):
|
||||
path_to_dialog_scenes = path
|
||||
|
||||
# Preload the dialog UI resources
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - path: Path where the actual dialog UI resources are located
|
||||
func preload_resources(path: String) -> void:
|
||||
var dialog_folder := Directory.new()
|
||||
if !path_to_dialog_scenes.empty() and dialog_folder.open(path_to_dialog_scenes) == OK:
|
||||
if !path.empty() and dialog_folder.open(path) == OK:
|
||||
dialog_folder.list_dir_begin()
|
||||
var file_name = dialog_folder.get_next()
|
||||
while file_name != "":
|
||||
if !dialog_folder.current_is_dir() and file_name.get_extension() == "tscn":
|
||||
if !dialog_folder.current_is_dir() \
|
||||
and file_name.get_extension() == "tscn":
|
||||
var extension = "." + file_name.get_extension()
|
||||
var basename = file_name.replace(extension, "")
|
||||
|
||||
if !has_resource(basename):
|
||||
var file_path = dialog_folder.get_current_dir() + "/" + file_name
|
||||
var file_path = "%s/%s" % [
|
||||
dialog_folder.get_current_dir(),
|
||||
file_name
|
||||
]
|
||||
var dialog_scene = load(file_path)
|
||||
|
||||
if dialog_scene != null:
|
||||
add_resource(basename, dialog_scene)
|
||||
file_name = dialog_folder.get_next()
|
||||
else:
|
||||
escoria.logger.report_errors("dialog_player.gd:preload_resources()",
|
||||
["An error occurred when trying to access the path: {_}.".format(path)])
|
||||
escoria.logger.report_errors(
|
||||
"dialog_player.gd:preload_resources()",
|
||||
[
|
||||
"An error occurred when trying to access the path: %s." % path
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func say(character : String, params : Dictionary):
|
||||
# A short one line dialog
|
||||
#
|
||||
# #### Parameters
|
||||
#
|
||||
# - character: Character that is talking
|
||||
# - params: A dictionary of parameters. Currently only "line" is supported and
|
||||
# holds the line the character should say
|
||||
func say(character: String, params: Dictionary) -> void:
|
||||
is_speaking = true
|
||||
dialog_ui = get_resource(params.ui).instance()
|
||||
get_parent().add_child(dialog_ui)
|
||||
dialog_ui.say(character, params)
|
||||
_dialog_ui = get_resource(params.ui).instance()
|
||||
get_parent().add_child(_dialog_ui)
|
||||
_dialog_ui.say(character, params)
|
||||
yield(_dialog_ui, "dialog_line_finished")
|
||||
emit_signal("dialog_line_finished")
|
||||
|
||||
|
||||
func finish_fast():
|
||||
dialog_ui.finish_fast()
|
||||
# Called when a dialog line is skipped
|
||||
func finish_fast() -> void:
|
||||
_dialog_ui.finish_fast()
|
||||
|
||||
# Options:
|
||||
# type: (default value "default") the type of dialog menu to use. All types are in the "dd_player" scene.
|
||||
# avatar: (default value "default") the avatar to use in the dialog ui.
|
||||
# timeout: (default value 0) timeout to select an option. After the time has passed, the "timeout_option" will be selected automatically. If the value is 0, there's no timeout.
|
||||
# timeout_option: (default value 0) option selected when timeout is reached.
|
||||
func start_dialog_choices(answers : Array, options : Array):
|
||||
if answers.empty():
|
||||
escoria.logger.report_errors("dialog_player.gd:start_dialog_choices()", ["Received answers array was empty."])
|
||||
dialog_chooser_ui = get_resource("text_dialog_choice").instance()
|
||||
get_parent().add_child(dialog_chooser_ui)
|
||||
dialog_chooser_ui.set_answers(answers)
|
||||
|
||||
func play_dialog_option_chosen(level_to_run : Array):
|
||||
# escoria.esc_runner.finished(context)
|
||||
var ev_level = level_to_run
|
||||
var ev = esctypes.ESCEvent.new("dialog_choice_done", ev_level, [])
|
||||
escoria.esc_runner.add_level(ev, false)
|
||||
dialog_chooser_ui.hide()
|
||||
# stop()
|
||||
# Display a list of choices
|
||||
func start_dialog_choices(dialog: ESCDialog):
|
||||
if dialog.options.empty():
|
||||
escoria.logger.report_errors(
|
||||
"dialog_player.gd:start_dialog_choices()",
|
||||
["Received answers array was empty."]
|
||||
)
|
||||
_dialog_chooser_ui = get_resource("text_dialog_choice").instance()
|
||||
get_parent().add_child(_dialog_chooser_ui)
|
||||
|
||||
_dialog_chooser_ui.set_answers(dialog.options)
|
||||
|
||||
|
||||
# Called when an option was chosen
|
||||
func play_dialog_option_chosen(option: ESCDialogOption):
|
||||
emit_signal("option_chosen", option)
|
||||
_dialog_chooser_ui.hide()
|
||||
|
||||
|
||||
@@ -18,16 +18,18 @@ func _on_command_text_entered(p_command_str : String):
|
||||
var actual_command = ":debug\n" + p_command_str + "\n"
|
||||
|
||||
var errors = []
|
||||
var events = escoria.esc_compiler.compile_str(actual_command, errors)
|
||||
var script = escoria.esc_compiler.compile([
|
||||
":debug",
|
||||
p_command_str
|
||||
])
|
||||
|
||||
if errors.empty():
|
||||
#past_actions.text += str(events)
|
||||
var ret = escoria.esc_runner.run_event(events["debug"])
|
||||
if ret != null:
|
||||
past_actions.text += str(ret)
|
||||
else:
|
||||
# Display first error only
|
||||
past_actions.text += str(errors[0].split(":")[1].strip_edges())
|
||||
if script:
|
||||
escoria.event_manager.run(script.events["debug"])
|
||||
var ret = yield(escoria.event_manager, "event_finished")
|
||||
while ret[1] != "debug":
|
||||
ret = yield(escoria.event_manager, "event_finished")
|
||||
if not ret[0] == ESCExecution.RC_OK:
|
||||
past_actions.text += "Returned code: %d" % ret[0]
|
||||
|
||||
|
||||
func _on_event_done(event_name : String):
|
||||
|
||||
@@ -25,10 +25,10 @@ func _ready():
|
||||
# if !Engine.is_editor_hint():
|
||||
# return
|
||||
|
||||
for item_id in escoria.esc_runner.items_in_inventory():
|
||||
for item_id in escoria.inventory_manager.items_in_inventory():
|
||||
call_deferred("add_new_item_by_id", item_id)
|
||||
|
||||
escoria.register_object(self)
|
||||
escoria.inventory = self
|
||||
|
||||
if inventory_ui_container == null or inventory_ui_container.is_empty():
|
||||
escoria.logger.report_errors(self.get_path(), ["Items container is empty."])
|
||||
@@ -37,29 +37,44 @@ func _ready():
|
||||
items_ids_in_inventory[c.item_id] = c
|
||||
# c.connect("pressed", escoria.inputs_manager, "_on_inventory_item_pressed", [c.item_id])
|
||||
|
||||
escoria.esc_runner.connect("global_changed", self, "_on_escoria_global_changed")
|
||||
escoria.globals_manager.connect("global_changed", self, "_on_escoria_global_changed")
|
||||
|
||||
|
||||
# add item to Inventory UI using its id set in its scene
|
||||
func add_new_item_by_id(item_id : String) -> void:
|
||||
if item_id.begins_with("i/"):
|
||||
item_id = item_id.rsplit("i/", false)[0]
|
||||
if !items_ids_in_inventory.has(item_id):
|
||||
if !escoria.esc_runner.check_obj(item_id, "add_new_item_by_id"):
|
||||
escoria.logger.report_errors("inventory_ui.gd:add_new_item_by_id()",
|
||||
["Item global id '"+ item_id + "' does not exist.",
|
||||
"Check item's id in ESCORIA_ALL_ITEMS scene."])
|
||||
if !all_items.get_inventory_item(item_id):
|
||||
escoria.logger.report_errors("inventory_ui.gd:add_new_item_by_id()",
|
||||
["Item global id '"+ item_id + "' doesn't have corresponding inventory item.",
|
||||
"Check item's id in ESCORIA_ALL_ITEMS scene."])
|
||||
if not items_ids_in_inventory.has(item_id):
|
||||
if not escoria.object_manager.has(item_id):
|
||||
escoria.logger.report_errors(
|
||||
"inventory_ui.gd:add_new_item_by_id()",
|
||||
[
|
||||
"Item global id '%s' does not exist." % item_id,
|
||||
"Check item's id in ESCORIA_ALL_ITEMS scene."
|
||||
]
|
||||
)
|
||||
if not all_items.get_inventory_item(item_id):
|
||||
escoria.logger.report_errors(
|
||||
"inventory_ui.gd:add_new_item_by_id()",
|
||||
[
|
||||
"Item global id '%s' doesn't have a " +\
|
||||
"corresponding inventory item." % item_id,
|
||||
"Check item's id in ESCORIA_ALL_ITEMS scene."
|
||||
]
|
||||
)
|
||||
var item_inventory_button = all_items.get_inventory_item(item_id).duplicate()
|
||||
items_ids_in_inventory[item_id] = item_inventory_button
|
||||
get_node(inventory_ui_container).add_item(item_inventory_button)
|
||||
|
||||
# Add the item to inventory
|
||||
if !escoria.esc_runner.objects.has(item_id):
|
||||
escoria.esc_runner.register_object(item_id, item_inventory_button)
|
||||
if not escoria.object_manager.has(item_id):
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(
|
||||
item_id,
|
||||
item_inventory_button
|
||||
),
|
||||
true
|
||||
)
|
||||
item_inventory_button.visible = true
|
||||
|
||||
item_inventory_button.connect("mouse_left_inventory_item",
|
||||
@@ -94,17 +109,14 @@ func remove_item_by_id(item_id : String) -> void:
|
||||
item_inventory_button.queue_free()
|
||||
items_ids_in_inventory.erase(item_id)
|
||||
|
||||
func _on_escoria_global_changed(global : String) -> void:
|
||||
func _on_escoria_global_changed(global : String, old_value, new_value) -> void:
|
||||
if !global.begins_with("i/"):
|
||||
return
|
||||
var item = global.rsplit("i/", false)
|
||||
if item.size() == 1:
|
||||
if escoria.esc_runner.globals[global] == "true":
|
||||
if new_value:
|
||||
add_new_item_by_id(item[0])
|
||||
elif escoria.esc_runner.globals[global] == "false":
|
||||
remove_item_by_id(item[0])
|
||||
else:
|
||||
escoria.logger.report_warnings("inventory_ui.gd:_on_escoria_global_changed()", \
|
||||
["Inventory global " + global + " is neither 'true' nor 'false' (was " + escoria.esc_runner.globals[global] + "). "])
|
||||
remove_item_by_id(item[0])
|
||||
else:
|
||||
escoria.logger.report_errors("inventory_ui.gd:_on_escoria_global_changed()", ["Global must contain 1 item name.", "(received: " + global + ")"])
|
||||
|
||||
@@ -11,8 +11,10 @@ export var global_id = "bg_music"
|
||||
|
||||
func game_cleared():
|
||||
set_state("off", true)
|
||||
self.disconnect("tree_exited", escoria.esc_runner, "object_exit_scene")
|
||||
escoria.register_object(self)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
func set_state(p_state, p_force = false):
|
||||
@@ -38,5 +40,8 @@ func set_state(p_state, p_force = false):
|
||||
stream.play()
|
||||
|
||||
func _ready():
|
||||
escoria.register_object(self)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
@@ -11,7 +11,10 @@ export var global_id = "bg_sound"
|
||||
|
||||
func game_cleared():
|
||||
stream.stream = null
|
||||
escoria.register_object(self)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
|
||||
|
||||
func set_state(p_state, p_force = false):
|
||||
@@ -38,4 +41,7 @@ func set_state(p_state, p_force = false):
|
||||
|
||||
|
||||
func _ready():
|
||||
escoria.register_object(self)
|
||||
escoria.object_manager.register_object(
|
||||
ESCObject.new(global_id, self),
|
||||
true
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user