feat: reports source of ESC errors when possible (#568)
This commit is contained in:
@@ -93,11 +93,12 @@ func load_esc_file(path: String) -> ESCScript:
|
|||||||
var lines = []
|
var lines = []
|
||||||
while not file.eof_reached():
|
while not file.eof_reached():
|
||||||
lines.append(file.get_line())
|
lines.append(file.get_line())
|
||||||
return self.compile(lines)
|
return self.compile(lines, path)
|
||||||
else:
|
else:
|
||||||
escoria.logger.report_errors(
|
escoria.logger.report_errors(
|
||||||
"Can not find ESC file",
|
path,
|
||||||
[
|
[
|
||||||
|
"Can not find ESC file",
|
||||||
"File %s could not be found" % path
|
"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
|
# 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()
|
var script = ESCScript.new()
|
||||||
|
|
||||||
if lines.size() > 0:
|
if lines.size() > 0:
|
||||||
var events = self._compile(lines)
|
var events = self._compile(lines, path)
|
||||||
for event in events:
|
for event in events:
|
||||||
|
event.source = path
|
||||||
script.events[event.name] = event
|
script.events[event.name] = event
|
||||||
|
|
||||||
return script
|
return script
|
||||||
|
|
||||||
|
|
||||||
# Compile an array of ESC script lines into an array of ESC objects
|
# 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 = []
|
var returned = []
|
||||||
|
|
||||||
while lines.size() > 0:
|
while lines.size() > 0:
|
||||||
@@ -148,7 +151,7 @@ func _compile(lines: Array) -> Array:
|
|||||||
"Compiling the next %d lines into the event" % \
|
"Compiling the next %d lines into the event" % \
|
||||||
event_lines.size()
|
event_lines.size()
|
||||||
)
|
)
|
||||||
event.statements = self._compile(event_lines)
|
event.statements = self._compile(event_lines, path)
|
||||||
returned.append(event)
|
returned.append(event)
|
||||||
elif _group_regex.search(line):
|
elif _group_regex.search(line):
|
||||||
var group = ESCGroup.new(line)
|
var group = ESCGroup.new(line)
|
||||||
@@ -174,7 +177,7 @@ func _compile(lines: Array) -> Array:
|
|||||||
"Compiling the next %d lines into the group" % \
|
"Compiling the next %d lines into the group" % \
|
||||||
group_lines.size()
|
group_lines.size()
|
||||||
)
|
)
|
||||||
group.statements = self._compile(group_lines)
|
group.statements = self._compile(group_lines, path)
|
||||||
returned.append(group)
|
returned.append(group)
|
||||||
elif _dialog_regex.search(line):
|
elif _dialog_regex.search(line):
|
||||||
var dialog = ESCDialog.new()
|
var dialog = ESCDialog.new()
|
||||||
@@ -200,7 +203,7 @@ func _compile(lines: Array) -> Array:
|
|||||||
"Compiling the next %d lines into the dialog" % \
|
"Compiling the next %d lines into the dialog" % \
|
||||||
dialog_lines.size()
|
dialog_lines.size()
|
||||||
)
|
)
|
||||||
dialog.options = self._compile(dialog_lines)
|
dialog.options = self._compile(dialog_lines, path)
|
||||||
# Remove the end line from the stack
|
# Remove the end line from the stack
|
||||||
lines.pop_front()
|
lines.pop_front()
|
||||||
returned.append(dialog)
|
returned.append(dialog)
|
||||||
@@ -232,7 +235,7 @@ func _compile(lines: Array) -> Array:
|
|||||||
"Compiling the next %d lines into the event" % \
|
"Compiling the next %d lines into the event" % \
|
||||||
dialog_option_lines.size()
|
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)
|
returned.append(dialog_option)
|
||||||
elif _command_regex.search(line):
|
elif _command_regex.search(line):
|
||||||
var command = ESCCommand.new(line)
|
var command = ESCCommand.new(line)
|
||||||
@@ -240,15 +243,17 @@ func _compile(lines: Array) -> Array:
|
|||||||
returned.append(command)
|
returned.append(command)
|
||||||
else:
|
else:
|
||||||
escoria.logger.report_errors(
|
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"
|
"Command implementation not found in any command directory"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
escoria.logger.report_errors(
|
escoria.logger.report_errors(
|
||||||
"Invalid ESC line detected",
|
path,
|
||||||
[
|
[
|
||||||
|
"Invalid ESC line detected",
|
||||||
"Line couldn't be compiled: %s" % line
|
"Line couldn't be compiled: %s" % line
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -72,10 +72,13 @@ func _process(delta: float) -> void:
|
|||||||
escoria.logger.debug(
|
escoria.logger.debug(
|
||||||
"esc_event_manager",
|
"esc_event_manager",
|
||||||
[
|
[
|
||||||
"Popping event %s from background queue %s" % [
|
"Popping event '%s' from background queue %s" % [
|
||||||
_running_events[channel_name].name,
|
_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(
|
if not _running_events[channel_name].is_connected(
|
||||||
|
|||||||
@@ -279,7 +279,9 @@ func _perform_script_events(room: ESCRoom) -> void:
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
"%s 0.1" % _wait.get_command_name()
|
"%s 0.1" % _wait.get_command_name()
|
||||||
])
|
],
|
||||||
|
get_class()
|
||||||
|
)
|
||||||
escoria.event_manager.queue_event(
|
escoria.event_manager.queue_event(
|
||||||
script_transition_out.events[escoria.event_manager.EVENT_TRANSITION_OUT]
|
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()
|
"%s 0.1" % _wait.get_command_name()
|
||||||
])
|
],
|
||||||
|
get_class()
|
||||||
|
)
|
||||||
escoria.event_manager.queue_event(
|
escoria.event_manager.queue_event(
|
||||||
script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN]
|
script_transition_in.events[escoria.event_manager.EVENT_TRANSITION_IN]
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,15 +9,19 @@ signal finished(event, return_code)
|
|||||||
# Emitted when the event was interrupted
|
# Emitted when the event was interrupted
|
||||||
signal interrupted(return_code)
|
signal interrupted(return_code)
|
||||||
|
|
||||||
|
|
||||||
# The list of ESC commands
|
# The list of ESC commands
|
||||||
var statements: Array = []
|
var statements: Array = []
|
||||||
|
|
||||||
# Indicates whether this event was interrupted.
|
|
||||||
var _is_interrupted: bool = false
|
|
||||||
|
|
||||||
# Indicates whether this event was finished.
|
# Indicates whether this event was finished.
|
||||||
var is_finished: bool = false
|
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
|
# Check whether the statement should be run based on its conditions
|
||||||
func is_valid() -> bool:
|
func is_valid() -> bool:
|
||||||
|
|||||||
@@ -57,7 +57,8 @@ func _register_event():
|
|||||||
)
|
)
|
||||||
|
|
||||||
var exit_scene_event = escoria.esc_compiler.compile(
|
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]
|
).events[escoria.event_manager.EVENT_EXIT_SCENE]
|
||||||
escoria.object_manager.get_object(self.global_id)\
|
escoria.object_manager.get_object(self.global_id)\
|
||||||
.events[escoria.event_manager.EVENT_EXIT_SCENE] = exit_scene_event
|
.events[escoria.event_manager.EVENT_EXIT_SCENE] = exit_scene_event
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ func _on_command_text_entered(p_command_str : String):
|
|||||||
var script = escoria.esc_compiler.compile([
|
var script = escoria.esc_compiler.compile([
|
||||||
"%s%s" % [ESCEvent.PREFIX, _debug.get_command_name()],
|
"%s%s" % [ESCEvent.PREFIX, _debug.get_command_name()],
|
||||||
p_command_str
|
p_command_str
|
||||||
])
|
],
|
||||||
|
get_class()
|
||||||
|
)
|
||||||
|
|
||||||
if script:
|
if script:
|
||||||
escoria.event_manager.queue_event(script.events[escoria.event_manager.EVENT_DEBUG])
|
escoria.event_manager.queue_event(script.events[escoria.event_manager.EVENT_DEBUG])
|
||||||
|
|||||||
@@ -63,7 +63,9 @@ func _on_button_pressed():
|
|||||||
var script = escoria.esc_compiler.compile([
|
var script = escoria.esc_compiler.compile([
|
||||||
":room_selector",
|
":room_selector",
|
||||||
"change_scene %s" % _options_paths[_selected_id]
|
"change_scene %s" % _options_paths[_selected_id]
|
||||||
])
|
],
|
||||||
|
get_class()
|
||||||
|
)
|
||||||
escoria.event_manager.interrupt_running_event()
|
escoria.event_manager.interrupt_running_event()
|
||||||
escoria.event_manager.clear_event_queue()
|
escoria.event_manager.clear_event_queue()
|
||||||
escoria.event_manager.queue_event(script.events['room_selector'])
|
escoria.event_manager.queue_event(script.events['room_selector'])
|
||||||
|
|||||||
Reference in New Issue
Block a user