diff --git a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd index e4ea6150..7ba18108 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd @@ -93,11 +93,12 @@ func load_esc_file(path: String) -> ESCScript: var lines = [] while not file.eof_reached(): lines.append(file.get_line()) - return self.compile(lines) + return self.compile(lines, path) else: escoria.logger.report_errors( - "Can not find ESC file", + path, [ + "Can not find ESC file", "File %s could not be found" % path ] ) @@ -105,18 +106,20 @@ func load_esc_file(path: String) -> ESCScript: # Compiles an array of ESC script strings to an ESCScript -func compile(lines: Array) -> ESCScript: +func compile(lines: Array, path: String = "") -> ESCScript: var script = ESCScript.new() + if lines.size() > 0: - var events = self._compile(lines) + var events = self._compile(lines, path) for event in events: + event.source = path script.events[event.name] = event return script # Compile an array of ESC script lines into an array of ESC objects -func _compile(lines: Array) -> Array: +func _compile(lines: Array, path: String = "") -> Array: var returned = [] while lines.size() > 0: @@ -148,7 +151,7 @@ func _compile(lines: Array) -> Array: "Compiling the next %d lines into the event" % \ event_lines.size() ) - event.statements = self._compile(event_lines) + event.statements = self._compile(event_lines, path) returned.append(event) elif _group_regex.search(line): var group = ESCGroup.new(line) @@ -174,7 +177,7 @@ func _compile(lines: Array) -> Array: "Compiling the next %d lines into the group" % \ group_lines.size() ) - group.statements = self._compile(group_lines) + group.statements = self._compile(group_lines, path) returned.append(group) elif _dialog_regex.search(line): var dialog = ESCDialog.new() @@ -200,7 +203,7 @@ func _compile(lines: Array) -> Array: "Compiling the next %d lines into the dialog" % \ dialog_lines.size() ) - dialog.options = self._compile(dialog_lines) + dialog.options = self._compile(dialog_lines, path) # Remove the end line from the stack lines.pop_front() returned.append(dialog) @@ -232,7 +235,7 @@ func _compile(lines: Array) -> Array: "Compiling the next %d lines into the event" % \ dialog_option_lines.size() ) - dialog_option.statements = self._compile(dialog_option_lines) + dialog_option.statements = self._compile(dialog_option_lines, path) returned.append(dialog_option) elif _command_regex.search(line): var command = ESCCommand.new(line) @@ -240,15 +243,17 @@ func _compile(lines: Array) -> Array: returned.append(command) else: escoria.logger.report_errors( - "Invalid command detected: %s" % command.name, + path, [ + "Invalid command detected: %s" % command.name, "Command implementation not found in any command directory" ] ) else: escoria.logger.report_errors( - "Invalid ESC line detected", + path, [ + "Invalid ESC line detected", "Line couldn't be compiled: %s" % line ] ) diff --git a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd index 38809fc8..9342db37 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_event_manager.gd @@ -72,10 +72,13 @@ func _process(delta: float) -> void: escoria.logger.debug( "esc_event_manager", [ - "Popping event %s from background queue %s" % [ + "Popping event '%s' from background queue %s" % [ _running_events[channel_name].name, - channel_name - ] + channel_name, + ], + "from source %s" % _running_events[channel_name].source \ + if not _running_events[channel_name].source.empty() + else "(unknown)", ] ) if not _running_events[channel_name].is_connected( diff --git a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd index 8acfef83..33d63cce 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_room_manager.gd @@ -279,7 +279,9 @@ func _perform_script_events(room: ESCRoom) -> void: ) ], "%s 0.1" % _wait.get_command_name() - ]) + ], + get_class() + ) escoria.event_manager.queue_event( script_transition_out.events[escoria.event_manager.EVENT_TRANSITION_OUT] ) @@ -348,7 +350,9 @@ func _perform_script_events(room: ESCRoom) -> void: ) ], "%s 0.1" % _wait.get_command_name() - ]) + ], + get_class() + ) escoria.event_manager.queue_event( script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN] ) diff --git a/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd b/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd index 189f7893..67624a03 100644 --- a/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd +++ b/addons/escoria-core/game/core-scripts/esc/types/esc_statement.gd @@ -9,15 +9,19 @@ signal finished(event, return_code) # Emitted when the event was interrupted signal interrupted(return_code) + # The list of ESC commands var statements: Array = [] -# Indicates whether this event was interrupted. -var _is_interrupted: bool = false - # Indicates whether this event was finished. var is_finished: bool = false +# The source of this statement, e.g. an ESC script or a class. +var source: String = "" + +# Indicates whether this event was interrupted. +var _is_interrupted: bool = false + # Check whether the statement should be run based on its conditions func is_valid() -> bool: diff --git a/addons/escoria-core/game/core-scripts/esc_exit.gd b/addons/escoria-core/game/core-scripts/esc_exit.gd index cbfe603c..2a053abb 100644 --- a/addons/escoria-core/game/core-scripts/esc_exit.gd +++ b/addons/escoria-core/game/core-scripts/esc_exit.gd @@ -57,7 +57,8 @@ func _register_event(): ) var exit_scene_event = escoria.esc_compiler.compile( - exit_scene_event_script + exit_scene_event_script, + get_class() ).events[escoria.event_manager.EVENT_EXIT_SCENE] escoria.object_manager.get_object(self.global_id)\ .events[escoria.event_manager.EVENT_EXIT_SCENE] = exit_scene_event diff --git a/addons/escoria-core/game/scenes/esc_prompt/esc_prompt_popup.gd b/addons/escoria-core/game/scenes/esc_prompt/esc_prompt_popup.gd index b7cbba37..75014cea 100644 --- a/addons/escoria-core/game/scenes/esc_prompt/esc_prompt_popup.gd +++ b/addons/escoria-core/game/scenes/esc_prompt/esc_prompt_popup.gd @@ -34,7 +34,9 @@ func _on_command_text_entered(p_command_str : String): var script = escoria.esc_compiler.compile([ "%s%s" % [ESCEvent.PREFIX, _debug.get_command_name()], p_command_str - ]) + ], + get_class() + ) if script: escoria.event_manager.queue_event(script.events[escoria.event_manager.EVENT_DEBUG]) diff --git a/addons/escoria-core/ui_library/tools/room_select/room_select.gd b/addons/escoria-core/ui_library/tools/room_select/room_select.gd index 8f467ef2..ead6fae7 100644 --- a/addons/escoria-core/ui_library/tools/room_select/room_select.gd +++ b/addons/escoria-core/ui_library/tools/room_select/room_select.gd @@ -63,7 +63,9 @@ func _on_button_pressed(): var script = escoria.esc_compiler.compile([ ":room_selector", "change_scene %s" % _options_paths[_selected_id] - ]) + ], + get_class() + ) escoria.event_manager.interrupt_running_event() escoria.event_manager.clear_event_queue() escoria.event_manager.queue_event(script.events['room_selector'])