feat: reports source of ESC errors when possible (#568)

This commit is contained in:
Duncan Brown
2022-04-09 10:13:09 -04:00
committed by GitHub
parent fda97352a0
commit baee79f5a0
7 changed files with 43 additions and 22 deletions

View File

@@ -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
]
)

View File

@@ -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(

View File

@@ -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]
)

View File

@@ -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:

View File

@@ -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

View File

@@ -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])

View File

@@ -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'])