Big refactor: Fix plugin issues when disabling/reenabling plugins (#598)

Co-authored-by: balloonpopper <5151242+balloonpopper@users.noreply.github.com>
Co-authored-by: Duncan Brown <duncan@prometheussoftware.ca>
This commit is contained in:
Julian Murgia
2022-07-10 20:40:08 +02:00
committed by GitHub
parent dfbceadd1c
commit ad79aa69d1
113 changed files with 2977 additions and 2072 deletions

View File

@@ -142,7 +142,7 @@ func _calculate_movement(delta: float):
#
# - angle: the angle X axis and object's facing direction.
func _perform_walk_orientation(angle: float):
last_dir = _get_dir_deg(escoria.utils.get_deg_from_rad(angle),
last_dir = _get_dir_deg(ESCUtils.get_deg_from_rad(angle),
parent.animations)
var animation_player: ESCAnimationPlayer = \
@@ -158,15 +158,10 @@ func _perform_walk_orientation(angle: float):
elif current_animation != animation_to_play and \
not animation_player.has_animation(animation_to_play):
current_animation = animation_to_play
escoria.logger.report_warnings(
"movable.gd:_process()",
[
"Character %s has no animation %s "
% [parent.global_id, animation_to_play],
"Bypassing missing animation and " +
"proceed movement."
],
true
escoria.logger.warn(
self,
"Character %s has no animation %s\nBypassing the missing animation and movement command."
% [parent.global_id, animation_to_play]
)
is_mirrored = parent.animations.directions[last_dir].mirrored
@@ -181,21 +176,21 @@ func teleport(target: Node) -> void:
if target.has_method("get_interact_position"):
parent.global_position = target.get_interact_position()
escoria.logger.info(
"Object %s is teleported at position %s" % [
target.name,
parent.global_position
]
self,
"Object %s is teleported to position %s."
% [target.name, parent.global_position]
)
elif "position" in target:
escoria.logger.info(
"Object %s teleported at position %s" %
[parent.global_id, str(target.global_position)]
self,
"Object %s teleported to position %s."
% [parent.global_id, str(target.global_position)]
)
parent.global_position = target.global_position
else:
escoria.logger.report_errors(
"ESCMovable#teleport()",
["Couldn't understand how to manage teleport Target %s" % target]
escoria.logger.error(
self,
"Target %s could not be teleported. Please configure the interact position parameter or create a child ESCLocation node." % target
)
@@ -206,8 +201,9 @@ func teleport(target: Node) -> void:
# - target: Vector2 target position to teleport to
func teleport_to(target: Vector2) -> void:
escoria.logger.info(
"Object %s teleported to position %s" %
[parent.global_id, str(target)]
self,
"Object %s teleported to position %s."
% [parent.global_id, str(target)]
)
parent.global_position = target
@@ -287,14 +283,16 @@ func walk_stop(pos: Vector2) -> void:
if walk_context.target_object:
escoria.logger.debug(
"%s arrived at %s" % [
self,
"%s arrived at %s." % [
parent.global_id,
walk_context.target_object.global_id
]
)
else:
escoria.logger.debug(
"%s arrived at %s" % [
self,
"%s arrived at %s." % [
parent.global_id,
walk_context.target_position
]
@@ -311,7 +309,8 @@ func update_terrain(on_event_finished_name = null) -> void:
if !parent.terrain or parent.terrain == null \
or !is_instance_valid(parent.terrain):
return
if on_event_finished_name != null and on_event_finished_name != escoria.event_manager.EVENT_SETUP:
if on_event_finished_name != null \
and on_event_finished_name != ESCEventManager.EVENT_SETUP:
return
if parent.get("is_exit"):
return
@@ -376,9 +375,9 @@ func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int:
# It's an error to have the animations misconfigured
if dir == -1:
escoria.logger.report_errors(
"esc_movable.gd:_get_dir_deg()",
["No direction found for " + str(deg)]
escoria.logger.error(
self,
"No animation has been configured for angle %s." + str(deg)
)
return dir
@@ -414,9 +413,9 @@ func _is_angle_in_interval(
# - wait float Wait this amount of seconds until continuing with turning around
func set_angle(deg: int, wait: float = 0.0) -> void:
if deg < 0 or deg > 360:
escoria.logger.report_errors(
"movable.gd:set_angle()",
["Invalid degree to turn to " + str(deg)]
escoria.logger.error(
self,
"Invalid degree to turn to : %s. Valid angles are between 0 and 360." % str(deg)
)
moved = true
@@ -490,15 +489,15 @@ func _get_angle() -> int:
# Integer: -1 (anti-clockwise), 1 (clockwise) or 0 (no movement needed).
func get_shortest_way_to_dir(current_dir: int, target_dir: int) -> int:
if current_dir < 0 or current_dir > parent.animations.dir_angles.size() - 1:
escoria.logger.report_errors(
"esc_movable.gd:get_shortest_way_to_dir()",
["Invalid direction (current_dir) %s" % str(current_dir)]
escoria.logger.error(
self,
"Invalid direction (current_dir) %s" % str(current_dir)
)
if target_dir < 0 or target_dir > parent.animations.dir_angles.size() - 1:
escoria.logger.report_errors(
"esc_movable.gd:get_shortest_way_to_dir()",
["Invalid direction (target_dir) %s " % str(target_dir)]
escoria.logger.error(
self,
"Invalid direction (target_dir) %s " % str(target_dir)
)
if current_dir == target_dir:

View File

@@ -22,6 +22,10 @@ extends ESCBaseCommand
class_name AcceptInputCommand
# The list of supported input types
const SUPPORTED_INPUT_TYPES = ["ALL", "NONE", "SKIP"]
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
return ESCCommandArgumentDescriptor.new(
@@ -36,12 +40,15 @@ func validate(arguments: Array):
if not .validate(arguments):
return false
if not arguments[0] in ["ALL", "NONE", "SKIP"]:
escoria.logger.report_errors(
"accept_input: invalid parameter",
[
"%s is not a valid parameter value (ALL, NONE, SKIP)" %\
arguments[0]
if not arguments[0] in SUPPORTED_INPUT_TYPES:
escoria.logger.error(
self,
"[%s]: invalid parameter. %s is not a valid parameter value." +
"Should be one of %s"
% [
get_command_name(),
arguments[0],
str(SUPPORTED_INPUT_TYPES)
]
)
return false

View File

@@ -30,11 +30,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"anim: invalid object",
[
"Object with global id %s not found." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true
@@ -56,9 +55,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -31,11 +31,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"anim_block.gd:validate",
[
"Object with global id %s not found." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true
@@ -62,9 +61,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -48,20 +48,25 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"camera_push: invalid object",
[
"Object global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
if not arguments[2] in SUPPORTED_TRANSITIONS:
escoria.logger.report_errors(
"camera_shift: invalid transition type",
[
"Transition type {t_type} is not one of the accepted types : {allowed_types}".format(
{"t_type":arguments[2],"allowed_types":SUPPORTED_TRANSITIONS})
]
escoria.logger.error(
self,
(
"[{command_name}]: invalid transition type. Transition type {t_type} " +
"is not one of the accepted types : {allowed_types}"
).format(
{
"command_name":get_command_name(),
"t_type":arguments[2],
"allowed_types":SUPPORTED_TRANSITIONS
}
)
)
return false
@@ -74,16 +79,14 @@ func run(command_params: Array) -> int:
.push(
escoria.object_manager.get_object(command_params[0]).node,
command_params[1],
Tween.new().get("TRANS_%s" % command_params[2])
ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[2])
)
return ESCExecution.RC_OK
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -33,14 +33,14 @@ func validate(arguments: Array):
return false
if escoria.main.current_scene.camera_limits.size() < arguments[0]:
escoria.logger.report_errors(
"camera_set_limits: invalid limits id",
[
"Limit id %d is bigger than limits array size %d" % [
escoria.logger.error(
self,
"[%s]: invalid limits id. Camera limit id (%d) is larger than the number of limits defined in this scene (%d)."
% [
get_command_name(),
arguments[0],
escoria.main.current_scene.camera_limits.size()
]
]
)
return false
@@ -55,9 +55,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -36,9 +36,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -32,11 +32,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"camera_set_target: invalid object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: Invalid object: Object with global id %s not found."
% [get_command_name(), arguments[1]]
)
return false
@@ -55,9 +54,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -40,9 +40,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -30,11 +30,10 @@ func validate(arguments: Array):
return false
if arguments[0] < 0:
escoria.logger.report_errors(
"camera_set_zoom_height: invalid height",
[
"Can't zoom to a negative height %d" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid height. Can't zoom to a negative height (%d)."
% [get_command_name(), arguments[0]]
)
return false
@@ -53,9 +52,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -49,7 +49,7 @@ func run(command_params: Array) -> int:
command_params[1]
),
command_params[2],
Tween.new().get("TRANS_%s" % command_params[3])
ClassDB.class_get_integer_constant("Tween", "TRANS_%s" % command_params[3])
)
return ESCExecution.RC_OK
@@ -59,12 +59,18 @@ func validate(arguments: Array):
return false
if not arguments[3] in SUPPORTED_TRANSITIONS:
escoria.logger.report_errors(
"camera_shift: invalid transition type",
[
"Transition type {t_type} is not one of the accepted types : {allowed_types}".format(
{"t_type":arguments[3],"allowed_types":SUPPORTED_TRANSITIONS})
]
escoria.logger.error(
self,
(
"[{command_name}]: invalid transition type" +
"Transition type {t_type} is not one of the accepted types : {allowed_types}"
).format(
{
"command_name": get_command_name(),
"t_type":arguments[3],
"allowed_types":SUPPORTED_TRANSITIONS
}
)
)
return false
@@ -73,9 +79,7 @@ func validate(arguments: Array):
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -31,20 +31,22 @@ func validate(arguments: Array) -> bool:
return false
if not ResourceLoader.exists(arguments[0]):
escoria.logger.report_errors(
"change_scene: Invalid scene",
["Scene %s was not found" % arguments[0]]
escoria.logger.error(
self,
"[%s]: Invalid scene. Scene %s was not found."
% [get_command_name(), arguments[0]]
)
return false
if not ResourceLoader.exists(
escoria.project_settings_manager.get_setting(escoria.project_settings_manager.GAME_SCENE)
ESCProjectSettingsManager.get_setting(ESCProjectSettingsManager.GAME_SCENE)
):
escoria.logger.report_errors(
"change_scene: Game scene not found",
[
"The path set in 'ui/game_scene' was not found: %s" % \
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_SCENE
escoria.logger.error(
self,
"[%s]: Game scene not found. The path set in 'ui/game_scene' was not found: %s."
% [
get_command_name(),
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_SCENE
)
]
)
@@ -56,10 +58,14 @@ func validate(arguments: Array) -> bool:
# Run the command
func run(command_params: Array) -> int:
escoria.logger.info(
"Changing scene to %s (enable_automatic_transition = %s)" % [
self,
"[%s] Changing scene to %s (enable_automatic_transition = %s)."
% [
get_command_name(),
command_params[0], # scene file
command_params[1] # enable_automatic_transition
])
]
)
escoria.room_manager.change_scene(command_params[0], command_params[1])
@@ -68,9 +74,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -35,24 +35,23 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"custom: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
elif not escoria.object_manager.get_object(arguments[0]).node.has_node(
arguments[1]
):
escoria.logger.report_errors(
"custom: invalid node",
[
"Object with global id %s has no node %s" % [
escoria.logger.error(
self,
"[%s]: invalid node. Object with global id %s has no child node called %s."
% [
get_command_name(),
arguments[0],
arguments[1],
]
]
)
return false
elif not escoria.object_manager.get_object(arguments[0]).node\
@@ -62,15 +61,15 @@ func validate(arguments: Array):
.has_method(
arguments[2]
):
escoria.logger.report_errors(
"custom: invalid function",
[
"Object with global id %s and node %s has no function %s" % [
escoria.logger.error(
self,
"[%s]: invalid function. Object with global id %s and node %s has no function called %s."
% [
get_command_name(),
arguments[0],
arguments[1],
arguments[2],
]
]
)
return false
return true
@@ -84,7 +83,7 @@ func run(command_params: Array) -> int:
# Global variables can be substituted into the command arguments by wrapping the global
# name in braces.
for loop in command_params[3].size():
command_params[3][loop] = escoria.esc_compiler.replace_globals(command_params[3][loop])
command_params[3][loop] = escoria.globals_manager.replace_globals(command_params[3][loop])
object.node.get_node(command_params[1]).call(
command_params[2],
@@ -95,9 +94,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
get_command_name(),
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -27,11 +27,10 @@ func validate(arguments: Array):
return false
if not escoria.globals_manager.get_global(arguments[0]) is int:
escoria.logger.report_errors(
"dec_global: invalid global",
[
"Global %s didn't have an integer value." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid global. Global %s isn't an integer value."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -36,11 +36,10 @@ func run(command_params: Array) -> int:
escoria.room_terrain.current_active_navigation_instance.enabled = true
return ESCExecution.RC_OK
else:
escoria.logger.report_errors(
"EnableTerrainCommand.run: Can not find terrain node",
[
"Terrain node %s could not be found" % name
]
escoria.logger.error(
self,
"[%s]: Can not find terrain node. Terrain node %s could not be found."
% [get_command_name(), name]
)
return ESCExecution.RC_ERROR

View File

@@ -34,11 +34,9 @@ func validate(arguments: Array):
return false
if not arguments[0] in ["main", "pause"]:
escoria.logger.report_errors(
"hide_menu: invalid menu ",
[
"menu %s is invalid" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: menu %s is invalid." % [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -27,19 +27,17 @@ func validate(arguments: Array):
return false
if not escoria.globals_manager.has(arguments[0]):
escoria.logger.report_errors(
"inc_global: invalid global",
[
"Global %s does not exist." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid global. Global %s does not exist."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.globals_manager.get_global(arguments[0]) is int:
escoria.logger.report_errors(
"inc_global: invalid global",
[
"Global %s didn't have an integer value." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid global. Global %s isn't an integer value."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -28,11 +28,10 @@ func validate(arguments: Array):
return false
if arguments[0].begins_with("i/"):
escoria.logger.report_errors(
"inventory_add: invalid item name",
[
"Item name %s cannot start with 'i/'." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid item name. Item name %s cannot start with 'i/'."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -33,15 +33,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"play_snd: invalid sound player",
["Sound player %s not registered" % arguments[1]]
escoria.logger.error(
self,
"[%s]: invalid sound player. Sound player %s not registered."
% [get_command_name(), arguments[1]]
)
return false
if not ResourceLoader.exists(arguments[0]):
escoria.logger.report_errors(
"play_snd: invalid parameter",
["File %s not found" % arguments[0]]
escoria.logger.error(
self,
"[%s]: invalid parameter. File %s not found."
% [get_command_name(), arguments[0]]
)
return false
_snd_player = arguments[1]

View File

@@ -24,7 +24,7 @@ func configure() -> ESCCommandArgumentDescriptor:
# Run the command
func run(command_params: Array) -> int:
# Replace the names of any globals in "{ }" with their value
print(escoria.esc_compiler.replace_globals(command_params[0]))
print(escoria.globals_manager.replace_globals(command_params[0]))
return ESCExecution.RC_OK

View File

@@ -31,39 +31,31 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"queue_event.gd:validate",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"Object with global id %s not found." % arguments[0]
)
return false
var node = escoria.object_manager.get_object(
arguments[0]
).node
if not "esc_script" in node or node.esc_script == "":
escoria.logger.report_errors(
"queue_event.gd:validate",
[
"Object with global id %s has no ESC script" % arguments[0]
]
escoria.logger.error(
self,
"Object with global id %s has no ESC script." % arguments[0]
)
return false
var esc_script = escoria.esc_compiler.load_esc_file(node.esc_script)
if not arguments[1] in esc_script.events:
escoria.logger.report_errors(
"queue_event.gd:validate",
[
"Event with name %s not found" % arguments[1]
]
escoria.logger.error(
self,
"Event with name %s not found." % arguments[1]
)
return false
if arguments[3] and not escoria.event_manager.is_channel_free(arguments[2]):
escoria.logger.report_errors(
"queue_event.gd:validate",
[
escoria.logger.error(
self,
"The queue %s doesn't accept a new event." % arguments[2]
]
)
return false
return true

View File

@@ -28,9 +28,10 @@ func validate(arguments: Array) -> bool:
return false
if not ResourceLoader.exists(arguments[0]):
escoria.logger.report_errors(
"queue_resource: Invalid resource",
["Resource %s was not found" % arguments[0]]
escoria.logger.error(
self,
"[%s]: Invalid resource. Resource %s was not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -64,21 +64,18 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"anim: invalid object",
[
"Object with global id %s not found." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: Invalid object: Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
if ProjectSettings.get_setting("escoria/ui/default_dialog_type") == "" \
if ESCProjectSettingsManager.get_setting(ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE) == "" \
and arguments[2] == "":
escoria.logger.report_errors(
"say()",
[
"Project setting 'escoria/ui/default_dialog_type' is not set.",
"Please set a default dialog type."
]
escoria.logger.error(
self,
"[%s]: Project setting '%s' is not set. Please set a default dialog type."
% [get_command_name(), ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE]
)
return true
@@ -91,17 +88,15 @@ func run(command_params: Array) -> int:
escoria.current_state = escoria.GAME_STATE.DIALOG
if !escoria.dialog_player:
escoria.logger.report_errors(
"No dialog player registered",
[
"No dialog player was registered and the say command was" +
"encountered."
]
escoria.logger.error(
self,
"[%s]: No dialog player was registered and the say command was encountered."
% get_command_name()
)
return ESCExecution.RC_ERROR
# Replace the names of any globals in "{ }" with their value
command_params[1] = escoria.esc_compiler.replace_globals(command_params[1])
command_params[1] = escoria.globals_manager.replace_globals(command_params[1])
escoria.dialog_player.say(
command_params[0],
@@ -115,9 +110,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
"say",
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -32,23 +32,22 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"sched_event: invalid object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[1]]
)
return false
elif not escoria.object_manager.get_object(arguments[1]).events\
.has(arguments[2]):
escoria.logger.report_errors(
"sched_event: invalid object event",
[
"Object with global id %s has no event %s" % [
escoria.logger.error(
self,
"[%s]: invalid object event. Object with global id %s has no event %s."
% [
get_command_name(),
arguments[1],
arguments[2],
]
]
)
return false
return true

View File

@@ -28,11 +28,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_active: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -33,11 +33,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_angle: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true
@@ -60,4 +59,3 @@ func run(command_params: Array) -> int:
func interrupt():
# Do nothing
pass

View File

@@ -27,19 +27,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_animations: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
if not ResourceLoader.exists(arguments[1]):
escoria.logger.report_errors(
"set_animations: invalid animations",
[
"The animation resource %s was not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: invalid animation resource. The animation resource %s was not found."
% [get_command_name(), arguments[1]]
)
return false
return true

View File

@@ -27,11 +27,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_interactive: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -26,11 +26,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_speed: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -34,11 +34,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"set_state: invalid object",
[
"Object %s not found." % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid object. Object %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -31,11 +31,9 @@ func validate(arguments: Array):
return false
if not arguments[0] in ["main", "pause"]:
escoria.logger.report_errors(
"show_menu: invalid menu ",
[
"menu %s is invalid" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: menu %s is invalid." % [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -35,19 +35,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"slide: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. Object with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"slide: invalid second object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: invalid second object. Object with global id %s not found."
% [get_command_name(), arguments[1]]
)
return false
return true
@@ -81,6 +79,8 @@ func _slide_object(
var tween = Tween.new()
(escoria.main as Node).add_child(tween)
tween.connect("tween_completed", self, "_on_tween_completed")
var duration = source.node.position.distance_to(
destination.node.position
) / speed
@@ -115,3 +115,7 @@ func run(command_params: Array) -> int:
func interrupt():
for tween in _tweens:
tween.stop_all()
func _on_tween_completed(tween: Tween):
tween.queue_free()

View File

@@ -31,27 +31,24 @@ func validate(arguments: Array):
if arguments[0].empty() \
or arguments[0] in escoria.object_manager.RESERVED_OBJECTS:
escoria.logger.report_errors(
"spawn: invalid global_id",
[
"global_id %s is invalid" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: global_id (%s) is invalid. The global_id was either empty or is reserved."
% [get_command_name(), arguments[0]]
)
return false
if not ResourceLoader.exists(arguments[1]):
escoria.logger.report_errors(
"spawn: invalid scene path",
[
"Scene with path %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: Invalid scene path: %s not found."
% [get_command_name(), arguments[1]]
)
return false
if arguments[3] and not escoria.object_manager.has(arguments[3]):
escoria.logger.report_errors(
"spawn: invalid object",
[
"Object with global id %s not found" % arguments[3]
]
escoria.logger.error(
self,
"[%s]: invalid object: Object with global id %s not found."
% [get_command_name(), arguments[3]]
)
return false
return true
@@ -83,11 +80,10 @@ func run(command_params: Array) -> int:
command_params[2]
else:
escoria.logger.report_errors(
"spawn: Invalid scene",
[
"Failed loading scene %s" % command_params[1]
]
escoria.logger.error(
self,
"[%s]: Invalid scene. Failed to load scene %s."
% [get_command_name(), command_params[1]]
)
return ESCExecution.RC_OK

View File

@@ -35,9 +35,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"stop_snd: invalid sound player",
["Sound player %s not registered" % arguments[0]]
escoria.logger.error(
self,
"[%s]: invalid sound player. Sound player %s not registered."
% [get_command_name(), arguments[0]]
)
return false
_snd_player = arguments[0]

View File

@@ -28,19 +28,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"teleport: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. Object to teleport with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"teleport: invalid second object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: invalid second object. Destination location to teleport to with global id %s not found."
% [get_command_name(), arguments[1]]
)
return false
return true

View File

@@ -28,11 +28,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"teleport_pos: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. Object to teleport with global id %s not found."
% [get_command_name(), arguments[0]]
)
return false
return true

View File

@@ -30,19 +30,18 @@ func validate(arguments: Array):
if not escoria.main.scene_transition.has_transition(arguments[0]) \
and not arguments[0].empty():
escoria.logger.report_errors(
"transition: argument invalid",
[
"transition with name '%s' doesn't exist" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: argument invalid. Transition with name '%s' doesn't exist."
% [get_command_name(), arguments[0]]
)
return false
if not arguments[1] in ["in", "out"]:
escoria.logger.report_errors(
"transition: argument invalid",
[
"'in' or 'out' expected, but got '%s'" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: argument invalid" +
"Transition type 'in' or 'out' expected, but '%s' was provided."
% [get_command_name(), arguments[1]]
)
return false
return true
@@ -58,18 +57,26 @@ func run(command_params: Array) -> int:
)
if transition_id == ESCTransitionPlayer.TRANSITION_ID_INSTANT:
escoria.logger.debug("Performing instant transition.")
escoria.logger.debug(
self,
"Performing instant transition."
)
escoria.main.scene_transition.reset_shader_cutoff()
return ESCExecution.RC_OK
escoria.logger.debug("Starting transition #%s [%s, %s]"
% [transition_id, command_params[0], command_params[1]])
escoria.logger.debug(
self,
"Starting transition #%s [%s, %s]."
% [transition_id, command_params[0], command_params[1]]
)
while yield(
escoria.main.scene_transition,
"transition_done"
) != transition_id:
pass
escoria.logger.debug("Ending transition #%s [%s, %s]"
escoria.logger.debug(
self,
"Ending transition #%s [%s, %s]."
% [transition_id, command_params[0], command_params[1]])
return ESCExecution.RC_OK

View File

@@ -35,19 +35,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"turn_to: invalid object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: The object to turn with global id %s was not found."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"turn_to: invalid target object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: The object to turn towards with global id %s was not found."
% [get_command_name(), arguments[0]]
)
return false
return true
@@ -65,9 +63,7 @@ func run(command_params: Array) -> int:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.report_warnings(
"turn_to",
[
"Interrupt() function not implemented"
]
escoria.logger.warn(
self,
"[%s] interrupt() function not implemented." % get_command_name()
)

View File

@@ -30,12 +30,10 @@ func validate(arguments: Array):
# We can't wait for 0 or fewer seconds, now, can we?
if arguments[0] <= 0.0:
escoria.logger.report_errors(
"wait: argument invalid",
[
"%ss is an invalid amount of time to wait." % arguments[0],
"Time to wait must be positive."
]
escoria.logger.error(
self,
"[%s]: argument invalid. %s is an invalid amount of time to wait (must be positive)."
% [get_command_name(), arguments[0]]
)
return false

View File

@@ -38,19 +38,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"walk: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. The object with global id %s to make walk was not found."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"walk: invalid second object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
": invalid second object. The object to walk to with global id %s was not found."
% [get_command_name(), arguments[1]]
)
return false

View File

@@ -38,19 +38,17 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"walk_block: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. The object to make walk with global id %s was not found."
% [get_command_name(), arguments[0]]
)
return false
if not escoria.object_manager.has(arguments[1]):
escoria.logger.report_errors(
"walk_block: invalid second object",
[
"Object with global id %s not found" % arguments[1]
]
escoria.logger.error(
self,
"[%s]: invalid second object. The object to walk to with global id %s was not found."
% [get_command_name(), arguments[1]]
)
return false

View File

@@ -37,11 +37,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"walk_to_pos: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. The object to make walk with global id %s was not found."
% [get_command_name(), arguments[0]]
)
return false

View File

@@ -37,11 +37,10 @@ func validate(arguments: Array):
return false
if not escoria.object_manager.has(arguments[0]):
escoria.logger.report_errors(
"walk_to_pos_block: invalid first object",
[
"Object with global id %s not found" % arguments[0]
]
escoria.logger.error(
self,
"[%s]: invalid first object. The object to make walk with global id %s was not found."
% [get_command_name(), arguments[0]]
)
return false

View File

@@ -1,5 +1,5 @@
# Manages currently carried out actions
extends Object
extends Resource
class_name ESCActionManager
@@ -90,12 +90,10 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
# Check moving object.
if not escoria.object_manager.has(params[0]):
escoria.logger.report_errors(
"esc_action_manager.gd:do()",
[
"Walk action requested on nonexisting " + \
"object: %s " % params[0]
]
escoria.logger.error(
self,
"Walk action requested for nonexisting object: %s."
% params[0]
)
return
@@ -104,12 +102,10 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
if params[1] is String:
if not escoria.object_manager.has(params[1]):
escoria.logger.report_errors(
"esc_action_manager.gd:do()",
[
"Walk action requested to nonexisting " + \
"object: %s " % params[1]
]
escoria.logger.error(
self,
"Walk action requested to nonexisting destination object: %s."
% params[1]
)
return
@@ -122,8 +118,8 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
ACTION.ITEM_LEFT_CLICK:
if params[0] is String:
escoria.logger.info(
"esc_action_manager.do(): item_left_click on item ",
[params[0]]
self,
"item_left_click on item %s." % params[0]
)
if can_interrupt:
@@ -135,8 +131,8 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
ACTION.ITEM_RIGHT_CLICK:
if params[0] is String:
escoria.logger.info(
"esc_action_manager.do(): item_right_click on item ",
[params[0]]
self,
"item_right_click on item %s." % params[0]
)
if can_interrupt:
@@ -149,10 +145,13 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
var trigger_id = params[0]
var object_id = params[1]
var trigger_in_verb = params[2]
escoria.logger.info("esc_action_manager.do(): trigger_in %s by %s" % [
escoria.logger.info(
self,
"trigger_in on trigger %s activated by %s." % [
trigger_id,
object_id
])
]
)
escoria.event_manager.queue_event(
escoria.object_manager.get_object(trigger_id).events[
trigger_in_verb
@@ -163,10 +162,13 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
var trigger_id = params[0]
var object_id = params[1]
var trigger_out_verb = params[2]
escoria.logger.info("esc_action_manager.do(): trigger_out %s by %s" % [
escoria.logger.info(
self,
"trigger_out on trigger %s activated by %s." % [
trigger_id,
object_id
])
]
)
escoria.event_manager.queue_event(
escoria.object_manager.get_object(trigger_id).events[
trigger_out_verb
@@ -174,8 +176,10 @@ func do(action: int, params: Array = [], can_interrupt: bool = false) -> void:
)
_:
escoria.logger.report_warnings("esc_action_manager.gd:do()",
["Action received:", action, "with params ", params])
escoria.logger.warn(
self,
"Action received: %s with params %s.", [action, params]
)
elif escoria.current_state == escoria.GAME_STATE.WAIT:
pass
@@ -237,7 +241,10 @@ func _activate(
target: ESCObject,
combine_with: ESCObject = null
) -> int:
escoria.logger.info("Activated action %s on %s" % [action, target])
escoria.logger.info(
self,
"Activated action %s on %s." % [action, target]
)
# If we're using an action which item requires to combine
if target.node is ESCItem\
@@ -314,16 +321,16 @@ func _activate(
("Reason: %s's item interaction " +\
"is one-way.") % combine_with.global_id
)
escoria.logger.report_warnings(
"ESCActionManager.activate: Invalid action",
errors
escoria.logger.warn(
self,
"Invalid action" + str(errors)
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR
else:
escoria.logger.report_warnings(
"ESCActionManager.activate: Invalid action on item",
[
escoria.logger.warn(
self,
"Invalid action on item: " +
(
"Trying to combine object %s with %s, "+
"but %s is not in inventory."
@@ -332,7 +339,6 @@ func _activate(
combine_with.global_id,
combine_with.global_id
]
]
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR
@@ -344,16 +350,15 @@ func _activate(
)
return ESCExecution.RC_OK
else:
escoria.logger.report_warnings(
"ESCActionManager.activate: Invalid action on item",
[
"Trying to run %s on object %s, " %
escoria.logger.warn(
self,
"Invalid action on item" +
"Trying to run action %s on object %s, " %
[
action,
target.node.global_id
]
+ "but item must be in inventory."
]
)
if target.events.has(action):
@@ -372,14 +377,13 @@ func _activate(
emit_signal("action_finished")
return event_returned[0]
else:
escoria.logger.report_warnings(
"ESCActionManager.activate: Invalid action",
[
escoria.logger.warn(
self,
"Invalid action: " +
"Event for action %s on object %s not found." % [
action,
target.global_id
]
]
)
emit_signal("action_finished")
return ESCExecution.RC_ERROR
@@ -428,12 +432,10 @@ func perform_walk(
moving_obj.node.walk_to(target_position, walk_context)
else:
escoria.logger.report_errors(
"esc_controller.gd:perform_walk()",
[
escoria.logger.error(
self,
"Function expected either a Vector2 or ESCObject type " + \
"for destination parameter. Actual was: %s " % destination
]
"for destination parameter. Destination provided was: %s." % destination
)
return
@@ -472,7 +474,10 @@ func perform_inputevent_on_object(
In this case, perform the default_action on the item.
"""
escoria.logger.info("%s left-clicked with event " % obj.global_id, [event])
escoria.logger.info(
self,
"%s left-clicked with event %s." % [obj.global_id, event]
)
var event_flags = 0
var has_current_action: bool = false
@@ -620,8 +625,10 @@ func _walk_towards_object(
var dont_interact: bool = false
if obj == null || obj.node == null:
escoria.logger.report_errors("esc_action_manager.gd:_walk_towards_object",
["obj or obj.node not populated."])
escoria.logger.error(
self,
"walk_towards_object error. obj or obj.node not populated."
)
var interact_position = obj.node.get_interact_position()
# If clicked object is interactive, get destination position from it.
if escoria.object_manager.get_object(obj.global_id).interactive:
@@ -645,7 +652,10 @@ func _walk_towards_object(
escoria.main.current_scene.player.walk_to(destination_position,
walk_context)
escoria.logger.debug("Player walking to destination. Yielding.")
escoria.logger.debug(
self,
"Player walking to destination. Yielding."
)
# Wait for the player to arrive before continuing with action.
var context: ESCWalkContext = yield(
@@ -654,11 +664,16 @@ func _walk_towards_object(
)
if context.target_object != obj:
escoria.logger.debug("Original walk context target does not match " \
escoria.logger.debug(
self,
"Original walk context target does not match " \
+ "yielded walk context. Likely interrutped walk.")
return
escoria.logger.info("Context arrived: %s" % context)
escoria.logger.info(
self,
"Context arrived: %s." % context
)
# Confirm that reached item was the one user clicked in the first place.
# Don't interact if that is not the case.

View File

@@ -1,5 +1,5 @@
# A registry of ESC command objects
extends Object
extends Reference
class_name ESCCommandRegistry
@@ -14,8 +14,8 @@ var registry: Dictionary = {}
# - command_name: Name of command to load
# **Returns** The command object
func load_command(command_name: String) -> ESCBaseCommand:
for command_directory in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.COMMAND_DIRECTORIES
for command_directory in ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.COMMAND_DIRECTORIES
):
if ResourceLoader.exists("%s/%s.gd" % [command_directory, command_name]):
registry[command_name] = load(
@@ -26,12 +26,10 @@ func load_command(command_name: String) -> ESCBaseCommand:
).new()
return registry[command_name]
escoria.logger.report_errors(
"ESCCommandRegistry.load_command: Command not found",
[
"No command class could be found for command %s" %
command_name
]
escoria.logger.error(
self,
"No command class could be found for command %s."
% command_name
)
return null

View File

@@ -1,5 +1,5 @@
# Compiler of the ESC language
extends Object
extends Resource
class_name ESCCompiler
@@ -52,7 +52,7 @@ var _current_indent = 0
func _init():
# Assure command list preference
# (we use ProjectSettings instead of escoria.project_settings_manager
# (we use ProjectSettings instead of ESCProjectSettingsManager
# here because this is called from escoria._init())
if not ProjectSettings.has_setting(COMMAND_DIRECTORIES):
ProjectSettings.set_setting(COMMAND_DIRECTORIES, [
@@ -90,7 +90,7 @@ func _init():
# Load an ESC file from a file resource
func load_esc_file(path: String) -> ESCScript:
escoria.logger.debug("Parsing file %s" % path)
escoria.logger.debug(self, "Parsing file %s." % path)
if File.new().file_exists(path):
var file = File.new()
file.open(path, File.READ)
@@ -99,12 +99,9 @@ func load_esc_file(path: String) -> ESCScript:
lines.append(file.get_line())
return self.compile(lines, path)
else:
escoria.logger.report_errors(
path,
[
"Can not find ESC file",
"File %s could not be found" % path
]
escoria.logger.error(
self,
"Can not find ESC file: file %s could not be found." % path
)
return null
@@ -128,20 +125,29 @@ func _compile(lines: Array, path: String = "") -> Array:
while lines.size() > 0:
var line = lines.pop_front().strip_edges(false, true)
escoria.logger.trace("Parsing line %s" % line)
escoria.logger.trace(
self,
"Parsing line %s." % line
)
if _comment_regex.search(line) or _empty_regex.search(line):
# Ignore comments and empty lines
escoria.logger.trace("Line is empty or a comment. Skipping.")
escoria.logger.trace(
self,
"Line is empty or a comment. Skipping."
)
continue
var indent = \
escoria.utils.get_re_group(
ESCUtils.get_re_group(
_indent_regex.search(line),
INDENT_REGEX_GROUP
).length()
if _event_regex.search(line):
var event = ESCEvent.new(line)
escoria.logger.trace("Line is the event %s" % event.name)
escoria.logger.trace(
self,
"Line is the event %s." % event.name
)
var event_lines = []
while lines.size() > 0:
var next_line = lines.pop_front()
@@ -152,14 +158,18 @@ func _compile(lines: Array, path: String = "") -> Array:
break
if event_lines.size() > 0:
escoria.logger.trace(
"Compiling the next %d lines into the event" % \
self,
"Compiling the next %d lines into the event." % \
event_lines.size()
)
event.statements = self._compile(event_lines, path)
returned.append(event)
elif _group_regex.search(line):
var group = ESCGroup.new(line)
escoria.logger.trace("Line is a group")
escoria.logger.trace(
self,
"Line is a group."
)
var group_lines = []
while lines.size() > 0:
var next_line = lines.pop_front()
@@ -167,7 +177,7 @@ func _compile(lines: Array, path: String = "") -> Array:
_empty_regex.search(next_line):
continue
var next_line_indent = \
escoria.utils.get_re_group(
ESCUtils.get_re_group(
_indent_regex.search(next_line),
INDENT_REGEX_GROUP
).length()
@@ -178,7 +188,8 @@ func _compile(lines: Array, path: String = "") -> Array:
break
if group_lines.size() > 0:
escoria.logger.trace(
"Compiling the next %d lines into the group" % \
self,
"Compiling the next %d lines into the group." % \
group_lines.size()
)
group.statements = self._compile(group_lines, path)
@@ -186,7 +197,10 @@ func _compile(lines: Array, path: String = "") -> Array:
elif _dialog_regex.search(line):
var dialog = ESCDialog.new()
dialog.load_string(line)
escoria.logger.trace("Line is a dialog")
escoria.logger.trace(
self,
"Line is a dialog."
)
var dialog_lines = []
while lines.size() > 0:
var next_line = lines.pop_front()
@@ -195,7 +209,7 @@ func _compile(lines: Array, path: String = "") -> Array:
continue
var end_line = _dialog_end_regex.search(next_line)
if end_line and \
escoria.utils.get_re_group(
ESCUtils.get_re_group(
end_line,
INDENT_REGEX_GROUP
).length() == indent:
@@ -204,7 +218,8 @@ func _compile(lines: Array, path: String = "") -> Array:
dialog_lines.append(next_line)
if dialog_lines.size() > 0:
escoria.logger.trace(
"Compiling the next %d lines into the dialog" % \
self,
"Compiling the next %d lines into the dialog." % \
dialog_lines.size()
)
dialog.options = self._compile(dialog_lines, path)
@@ -215,7 +230,8 @@ func _compile(lines: Array, path: String = "") -> Array:
var dialog_option = ESCDialogOption.new()
dialog_option.load_string(line)
escoria.logger.trace(
"Line is the dialog option %s" % \
self,
"Line is the dialog option %s." % \
dialog_option.option
)
var dialog_option_lines = []
@@ -225,7 +241,7 @@ func _compile(lines: Array, path: String = "") -> Array:
_empty_regex.search(next_line):
continue
var next_line_indent = \
escoria.utils.get_re_group(
ESCUtils.get_re_group(
_indent_regex.search(next_line),
INDENT_REGEX_GROUP
).length()
@@ -236,8 +252,9 @@ func _compile(lines: Array, path: String = "") -> Array:
break
if dialog_option_lines.size() > 0:
escoria.logger.trace(
"Compiling the next %d lines into the event" % \
dialog_option_lines.size()
self,
"Compiling the next %d lines into the event."
% dialog_option_lines.size()
)
dialog_option.statements = self._compile(dialog_option_lines, path)
returned.append(dialog_option)
@@ -246,34 +263,19 @@ func _compile(lines: Array, path: String = "") -> Array:
if command.command_exists():
returned.append(command)
else:
escoria.logger.report_errors(
path,
[
"Invalid command detected: %s" % command.name,
"Command implementation not found in any command directory"
escoria.logger.error(
self,
"Command \"%s\" cannot be found under folder %s.\nPlease confirm setting \"%s\" is set to the folder where ESC commands are stored."
% [
command.name,
ProjectSettings.get_setting(COMMAND_DIRECTORIES),
ESCProjectSettingsManager.COMMAND_DIRECTORIES
]
)
else:
escoria.logger.report_errors(
path,
[
"Invalid ESC line detected",
"Line couldn't be compiled: %s" % line
]
escoria.logger.error(
self,
"Invalid ESC line detected.\nLine couldn't be compiled: %s."
% line
)
return returned
# Look to see if any globals (names in braces) should be interpreted
#
# #### Parameters
#
# * string: Text to log
func replace_globals(string: String) -> String:
for result in _globals_regex.search_all(string):
var globresult = escoria.globals_manager.get_global(
str(result.get_string())
)
string = string.replace(
"{" + result.get_string() + "}", str(globresult)
)
return string

View File

@@ -88,16 +88,14 @@ func _process(delta: float) -> void:
_running_events[channel_name] = \
events_queue[channel_name].pop_front()
escoria.logger.debug(
"esc_event_manager",
[
"Popping event '%s' from background queue %s" % [
self,
"Popping event '%s' from background queue %s " % [
_running_events[channel_name].name,
channel_name,
],
"from source %s" % _running_events[channel_name].source \
] +
"to source %s." % _running_events[channel_name].source \
if not _running_events[channel_name].source.empty()
else "(unknown)",
]
else "(unknown)"
)
if not _running_events[channel_name].is_connected(
"finished", self, "_on_event_finished"
@@ -174,28 +172,22 @@ func queue_event_from_esc(script_object: ESCScript, event: String,
return ESCExecution.RC_WONT_QUEUE
if channel == CHANNEL_FRONT:
escoria.event_manager.queue_event(script_object.events[event])
queue_event(script_object.events[event])
else:
escoria.event_manager.queue_background_event(
queue_background_event(
channel,
script_object.events[event]
)
if block:
if channel == CHANNEL_FRONT:
var rc = yield(escoria.event_manager, "event_finished")
var rc = yield(self, "event_finished")
while rc[1] != event:
rc = yield(escoria.event_manager, "event_finished")
rc = yield(self, "event_finished")
return rc
else:
var rc = yield(
escoria.event_manager,
"background_event_finished"
)
var rc = yield(self, "background_event_finished")
while rc[1] != event and rc[2] != channel:
rc = yield(
escoria.event_manager,
"background_event_finished"
)
rc = yield(self, "background_event_finished")
return rc
return ESCExecution.RC_OK
@@ -208,6 +200,7 @@ func queue_event_from_esc(script_object: ESCScript, event: String,
func queue_event(event: ESCEvent, force: bool = false) -> void:
if _changing_scene and not force:
escoria.logger.info(
self,
"Changing scenes. Won't queue event '%s'." % event.name
)
return
@@ -222,18 +215,22 @@ func queue_event(event: ESCEvent, force: bool = false) -> void:
var message = "Event '%s' is already the most-recently queued event in channel '%s'." + \
" Won't be queued again."
escoria.logger.debug(message % [event.name, CHANNEL_FRONT])
escoria.logger.debug(self, message % [event.name, CHANNEL_FRONT])
return
elif _is_event_running(event, CHANNEL_FRONT):
# Don't queue the same event if it's already running.
escoria.logger.debug(
self,
"Event %s already running in channel '%s'. Won't be queued."
% [event.name, CHANNEL_FRONT]
)
return
escoria.logger.debug("Queueing %s in channel %s." % [event.name, CHANNEL_FRONT])
escoria.logger.debug(
self,
"Queueing event %s in channel %s." % [event.name, CHANNEL_FRONT]
)
self.events_queue[CHANNEL_FRONT].append(event)
@@ -266,11 +263,12 @@ func queue_background_event(channel_name: String, event: ESCEvent) -> void:
var message = "Event '%s' is already the most-recently queued event in channel '%s'." + \
" Won't be queued again."
escoria.logger.debug(message % [event.name, channel_name])
escoria.logger.debug(self, message % [event.name, channel_name])
return
elif _is_event_running(event, CHANNEL_FRONT):
# Don't queue the same event if it's already running.
escoria.logger.debug(
self,
"Event %s already running in channel '%s'. Won't be queued."
% [event.name, channel_name]
)
@@ -287,7 +285,9 @@ func queue_background_event(channel_name: String, event: ESCEvent) -> void:
func interrupt(exceptions: PoolStringArray = []) -> void:
for channel_name in _running_events.keys():
if _running_events[channel_name] != null and not _running_events[channel_name].name in exceptions:
escoria.logger.debug("Interrupting running event %s in channel %s..."
escoria.logger.debug(
self,
"Interrupting running event %s in channel %s..."
% [_running_events[channel_name].name, channel_name])
_running_events[channel_name].interrupt()
_channels_state[channel_name] = true
@@ -298,7 +298,9 @@ func interrupt(exceptions: PoolStringArray = []) -> void:
if event.name in exceptions:
continue
escoria.logger.debug("Interrupting queued event %s in channel %s..."
escoria.logger.debug(
self,
"Interrupting queued event %s in channel %s..."
% [event.name, channel_name])
event.interrupt()
@@ -334,7 +336,10 @@ func get_running_event(name: String) -> ESCEvent:
# #### Parameterse
# - value: boolean value to set _changing_scene to
func set_changing_scene(p_is_changing_scene: bool) -> void:
escoria.logger.trace("Setting _changing_scene to %s." % p_is_changing_scene)
escoria.logger.trace(
self,
"Setting _changing_scene to %s." % p_is_changing_scene
)
_changing_scene = p_is_changing_scene
@@ -353,17 +358,16 @@ func set_changing_scene(p_is_changing_scene: bool) -> void:
func _on_event_finished(finished_statement: ESCStatement, return_code: int, channel_name: String) -> void:
var event = _running_events[channel_name]
if not event:
escoria.logger.report_warnings(
"esc_event_manager.gd:_on_event_finished()",
[
"Event %s finished without being in _running_events[%s]"
escoria.logger.warn(
self,
"Event %s finished without being in _running_events[%s]."
% [finished_statement.name, channel_name]
]
)
return
escoria.logger.debug(
"Event %s ended with return code %d" % [event.name, return_code]
self,
"Event %s ended with return code %d." % [event.name, return_code]
)
var event_flags = event.flags

View File

@@ -16,6 +16,13 @@ export(Dictionary) var _globals = {}
# Registry of globals that are to be reserved for internal use only.
var _reserved_globals: Dictionary = {}
# Use look-ahead/behind to capture the term in braces
var globals_regex: RegEx = RegEx.new()
# Constructor
func _init():
globals_regex.compile("(?<=\\{)(.*)(?=\\})")
# Check if a global was registered
#
@@ -35,11 +42,11 @@ func has(key: String) -> bool:
# - value: The initial value (optional)
func register_reserved_global(key: String, value = null) -> void:
if key in _reserved_globals:
escoria.logger.report_errors(
"ESCGlobalsManager.register_reserved_global: Can not override reserved global",
[
"Global key %s is already registered as reserved" % key
]
escoria.logger.error(
self,
"Can not override reserved global: Global key %s is already " +
"registered as reserved."
% key
)
var old_value = _globals[key] if _globals.has(key) else ""
_reserved_globals[key] = value
@@ -86,11 +93,9 @@ func filter(pattern: String) -> Dictionary:
# - value: The new value
func set_global(key: String, value, ignore_reserved: bool = false) -> void:
if key in _reserved_globals and not ignore_reserved:
escoria.logger.report_errors(
"ESCGlobalsManager.set_global: Can not override reserved global",
[
"Global key %s is reserved and can not be overridden" % key
]
escoria.logger.error(
self,
"Global key %s is reserved and can not be overridden." % key
)
emit_signal(
@@ -102,7 +107,6 @@ func set_global(key: String, value, ignore_reserved: bool = false) -> void:
_globals[key] = value
# Set all globals that match the pattern to the value
# Check out [the Godot docs](https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-match)
# for the pattern format
@@ -117,6 +121,24 @@ func set_global_wildcard(pattern: String, value) -> void:
self.set_global(global_key, value)
# Look to see if any globals (names in braces) should be interpreted
#
# #### Parameters
#
# * string: Text in which to replace globals
#
# *Returns* the provided string with globals variables replaced with their values
func replace_globals(string: String) -> String:
for result in globals_regex.search_all(string):
var globresult = escoria.globals_manager.get_global(
str(result.get_string())
)
string = string.replace(
"{" + result.get_string() + "}", str(globresult)
)
return string
# Save the state of globals in the savegame.
#
# #### Parameters

View File

@@ -1,5 +1,5 @@
# A manager for inventory objects
extends Object
extends Resource
class_name ESCInventoryManager
@@ -31,11 +31,10 @@ func items_in_inventory() -> Array:
# - item: Inventory item id
func remove_item(item: String):
if not inventory_has(item):
escoria.logger.report_errors(
"ESCInventoryManager.remove_item: Error removing inventory item",
[
"Trying to remove non-existent item %s" % item
]
escoria.logger.error(
self,
"Error removing inventory item: " +
"Trying to remove non-existent item %s." % item
)
else:
escoria.globals_manager.set_global("i/%s" % item, false)

View File

@@ -1,5 +1,5 @@
# A manager for ESC objects
extends Node
extends Resource
class_name ESCObjectManager
@@ -69,15 +69,6 @@ func _init() -> void:
current_room_key = ESCRoomObjectsKey.new()
# Make active objects in current room visible
func _process(_delta):
for room in room_objects:
if room.is_reserved or _is_current_room(room):
for object in room.objects:
if (object as ESCObject).node:
(object as ESCObject).node.visible = (object as ESCObject).active
# Updates which object manager room is to be treated as the currently active one.
#
# #### Parameters
@@ -85,12 +76,10 @@ func _process(_delta):
# - room: Room to register the object with in the object manager
func set_current_room(room: ESCRoom) -> void:
if room == null:
escoria.logger.report_errors(
"ESCObjectManager:set_current_room()",
[
"Unable to set current room: No valid room specified.",
escoria.logger.error(
self,
"Unable to set current room: No room was specified.\n" +
"Please pass in a valid ESCRoom as an argument to the method."
]
)
current_room_key.room_global_id = room.global_id
@@ -111,13 +100,11 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
if object.global_id.empty():
object.global_id = str(object.node.get_path()).split("/root/", false)[0]
object.node.global_id = object.global_id
escoria.logger.report_warnings(
"ESCObjectManager:register_object()",
[
"Registering ESCObject %s with empty global_id." % object.name,
escoria.logger.warn(
self,
"Registering ESCObject %s with empty global_id." % object.name +
"Using node's full path as global_id: %s"
% object.node.global_id
]
)
# If this is a reserved object, let's make sure it's in the right place.
@@ -139,28 +126,25 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
if not room_key.is_valid():
# This condition should very likely never happen.
escoria.logger.report_errors(
"ESCObjectManager:register_object()",
[
"No room was specified to register object with, and no current room is properly set.",
escoria.logger.error(
self,
"No room was specified to register object with, and no current room is properly set.\n" +
"Please either pass in a valid ESCRoom to this method, or " + \
"call set_current_room() with a valid ESCRoom first."
]
)
else:
room_key.room_global_id = room.global_id
room_key.room_instance_id = room.get_instance_id()
if not force and _object_exists_in_room(object, room_key):
escoria.logger.report_errors(
"ESCObjectManager:register_object()",
[
"Object with global id %s in room (%s, %s) already registered" %
[
if not force and _object_exists_in_room(object, room_key) \
and _object_state_in_room_is_default(object, room_key):
escoria.logger.error(
self,
"Object with global id '%s' in room %s already registered from node path %s."
% [
object.global_id,
room_key.room_global_id,
room_key.room_instance_id
]
get_object(object.global_id, room).node.get_path()
]
)
return
@@ -213,16 +197,14 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
# If object state is not STATE_DEFAULT, save it in manager's object states
if object.state != ESCObject.STATE_DEFAULT:
if get_object(object.global_id) == null:
escoria.logger.report_errors(
"ESCObjectManager:register_object()",
[
"Object with global id %s in room (%s, %s) not found in Object Manager" %
[
escoria.logger.error(
self,
"Object with global id %s in room (%s, %s) not found in Object Manager."
% [
object.global_id,
room_key.room_global_id,
room_key.room_instance_id
]
]
)
else:
get_object(object.global_id).state = object.state
@@ -235,7 +217,6 @@ func register_object(object: ESCObject, room: ESCRoom = null, force: bool = fals
room_container.room_instance_id = room_key.room_instance_id
room_container.is_reserved = false
room_container.objects = objects
room_objects.push_back(room_container)
@@ -256,8 +237,9 @@ func has(global_id: String, room: ESCRoom = null) -> bool:
var room_key: ESCRoomObjectsKey
if room == null:
escoria.logger.trace("ESCObjectManager.has(): No room specified." \
+ " Defaulting to current room."
escoria.logger.trace(
self,
"No room specified. Defaulting to current room."
)
room_key = current_room_key
@@ -284,20 +266,19 @@ func get_object(global_id: String, room: ESCRoom = null) -> ESCObject:
if reserved_objects_container.objects.has(global_id):
return reserved_objects_container.objects[global_id]
else:
escoria.logger.report_warnings(
"ESCObjectManager:get_object()",
[
escoria.logger.warn(
self,
"Reserved object with global id %s not found in object manager!"
% global_id
]
)
return null
var room_key: ESCRoomObjectsKey
if room == null:
escoria.logger.trace("ESCObjectManager.has(): No room specified." \
+ " Defaulting to current room."
escoria.logger.trace(
self,
"No room specified. Defaulting to current room."
)
room_key = current_room_key
@@ -307,13 +288,11 @@ func get_object(global_id: String, room: ESCRoom = null) -> ESCObject:
room_key.room_instance_id = room.get_instance_id()
if not _room_exists(room_key):
escoria.logger.report_warnings(
"ESCObjectManager:get_object()",
[
"Specified room is empty/not found.",
"Object with global id %s in room instance (%s, %s) not found"
escoria.logger.warn(
self,
"Specified room is empty/not found.\n" +
"Object with global id %s in room instance (%s, %s) not found."
% [global_id, room_key.room_global_id, room_key.room_instance_id]
]
)
return null
@@ -322,12 +301,10 @@ func get_object(global_id: String, room: ESCRoom = null) -> ESCObject:
if objects.has(global_id):
return objects[global_id]
else:
escoria.logger.report_warnings(
"ESCObjectManager:get_object()",
[
"Object with global id %s in room instance (%s, %s) not found"
escoria.logger.warn(
self,
"Object with global id %s in room instance (%s, %s) not found."
% [global_id, room_key.room_global_id, room_key.room_instance_id]
]
)
return null
@@ -344,23 +321,22 @@ func unregister_object(object: ESCObject, room_key: ESCRoomObjectsKey) -> void:
# called as part of an objectd's forced registration and the object not
# yet being managed.
escoria.logger.debug(
"ESCObjectManager:unregister_object(): Unable to unregister object.",
[
"Object with global ID %s room (%s, %s) not found. If this was" %
[
self,
"Unable to unregister object.\n" +
"Object with global ID %s room (%s, %s) not found. If this was "
% [
"?" if object == null else object.global_id,
room_key.room_global_id,
room_key.room_instance_id
],
] +
"part of a 'forced' registration, ignore this warning."
]
)
return
var room_objects = _get_room_objects_objects(room_key)
if escoria.inventory_manager.inventory_has(object.global_id):
if not escoria.is_quitting and escoria.inventory_manager.inventory_has(object.global_id):
# Re-instance the node if it is an item present in inventory; that is,
# re-register it with the new current room.
if object.node != null:
@@ -393,11 +369,9 @@ func unregister_object_by_global_id(global_id: String, room_key: ESCRoomObjectsK
# - p_savegame: The savegame resource
func save_game(p_savegame: ESCSaveGame) -> void:
if not current_room_key.is_valid() or not _room_exists(current_room_key):
escoria.logger.report_errors(
"ESCObjectManager:save_game()",
[
escoria.logger.error(
self,
"No current room specified or found."
]
)
var objects: Dictionary = _get_room_objects_objects(current_room_key)
@@ -430,12 +404,10 @@ func get_start_location() -> ESCLocation:
and object.node.is_start_location:
return object
escoria.logger.report_warnings(
"ESCObjectManager:get_start_location()",
[
"Room has no ESCLocation node with 'is_start_location' enabled.",
"Player will be set at position (0,0) by default."
]
escoria.logger.warn(
self,
"Room has no ESCLocation node with 'is_start_location' enabled. " +
"Player will be set at position (0,0)."
)
return null
@@ -486,11 +458,9 @@ func _room_exists(room_key: ESCRoomObjectsKey) -> bool:
# **Returns** True iff object exists in the object manager entry specified by room_key.
func _object_exists_in_room(object: ESCObject, room_key: ESCRoomObjectsKey) -> bool:
if object == null:
escoria.logger.report_warnings(
"ESCObjectManager:_object_exists_in_room()",
[
"Cannot check for null objects."
]
escoria.logger.warn(
self,
"Cannot check room for \"null\" objects."
)
return false
@@ -503,6 +473,30 @@ func _object_exists_in_room(object: ESCObject, room_key: ESCRoomObjectsKey) -> b
return false
# Checks whether the specified object's state is "default" in the specified object manager entry.
#
# #### Parameters
#
# - object: The object to check for existence.
# - room_key: The key representing the desired room in the object manager array.
# **Returns** True if object's state is "default" in the object manager entry specified by room_key.
func _object_state_in_room_is_default(object: ESCObject, room_key: ESCRoomObjectsKey) -> bool:
if object == null:
escoria.logger.warn(
self,
"Cannot check room for \"null\" objects."
)
return false
for room_container in room_objects:
if _compare_container_to_key(room_container, room_key) \
and room_container.objects.get(object.global_id).state == ESCObject.STATE_DEFAULT:
return true
return false
# Returns the objects currently being managed in the object manager entry specified
# by the specified room key.
#

View File

@@ -1,4 +1,4 @@
extends Object
extends Resource
class_name ESCRoomManager
@@ -86,14 +86,12 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
# Check if game scene was loaded
if not escoria.game_scene:
escoria.logger.report_errors(
"ESCRoomManager.change_scene: Failed loading game scene",
[
"Failed loading scene %s" % \
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_SCENE
escoria.logger.error(
self,
"Failed loading game scene %s." % \
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_SCENE
)
]
)
if escoria.main.current_scene \
@@ -106,9 +104,12 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
var room_scene = res_room.instance()
if room_scene:
if enable_automatic_transitions \
and escoria.event_manager.get_running_event(escoria.event_manager.CHANNEL_FRONT) != null \
and escoria.event_manager.get_running_event(escoria.event_manager.CHANNEL_FRONT).name \
== escoria.event_manager.EVENT_ROOM_SELECTOR:
and escoria.event_manager.get_running_event(
escoria.event_manager.CHANNEL_FRONT
) != null \
and escoria.event_manager.get_running_event(
escoria.event_manager.CHANNEL_FRONT
).name == escoria.event_manager.EVENT_ROOM_SELECTOR:
room_scene.enabled_automatic_transitions = true
else:
room_scene.enabled_automatic_transitions = enable_automatic_transitions
@@ -138,11 +139,9 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
escoria.inputs_manager.hotspot_focused = ""
else:
escoria.logger.report_errors(
"ESCRoomManager.change_scene: Failed loading room scene",
[
"Failed loading scene %s" % room_path
]
escoria.logger.error(
self,
"Failed loading room scene %s." % room_path
)
@@ -154,11 +153,9 @@ func change_scene(room_path: String, enable_automatic_transitions: bool) -> void
# - room: The ESCRoom to be initialized for use.
func init_room(room: ESCRoom) -> void:
if not is_instance_valid(room) || room == null:
escoria.logger.report_errors(
"ESCRoomManager.init_room: No valid room specified",
[
escoria.logger.error(
self,
"No valid room was specified for initialization."
]
)
if room.camera_limits.empty():
@@ -189,11 +186,10 @@ func init_room(room: ESCRoom) -> void:
# player by the same number of pixels when they're at the terrain edge and
# move them when it shouldn't.
if room.position != Vector2(0,0):
escoria.logger.report_errors(
"ESCRoomManager.init_room: Room node not at (0,0)",
[
"The room node's coordinates must be (0,0) instead of %s." % room.position
]
escoria.logger.error(
self,
"The room node's coordinates must be (0,0) instead of %s."
% room.position
)
_perform_script_events(room)
@@ -217,8 +213,8 @@ func _perform_script_events(room: ESCRoom) -> void:
"%s %s out" %
[
_transition.get_command_name(),
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANSITION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION
)
],
"%s 0.1" % _wait.get_command_name()
@@ -286,7 +282,9 @@ func _perform_script_events(room: ESCRoom) -> void:
escoria.main.finish_current_scene_init(room)
# Add new camera to scene being prepared.
var new_player_camera: ESCCamera = escoria.resource_cache.get_resource(escoria.CAMERA_SCENE_PATH).instance()
var new_player_camera: ESCCamera = escoria.resource_cache.get_resource(
escoria.CAMERA_SCENE_PATH
).instance()
new_player_camera.register()
room.player_camera = new_player_camera
@@ -360,8 +358,8 @@ func _perform_script_events(room: ESCRoom) -> void:
command_strings.append("%s %s in" %
[
_transition.get_command_name(),
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANSITION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION
)
]
)
@@ -432,12 +430,10 @@ func _run_script_event(event_name: String, room: ESCRoom):
if room.compiled_script.events.has(event_name):
escoria.logger.debug(
"esc_room:_run_script_event",
[
"Queuing room script event %s" % event_name,
"Composed of %s statements" %
room.compiled_script.events[event_name].statements.size()
]
self,
"Queuing room script event %s " % event_name +
"composed of %s statements."
% room.compiled_script.events[event_name].statements.size()
)
escoria.event_manager.queue_event(room.compiled_script.events[event_name], true)
return true

View File

@@ -1,6 +1,6 @@
# A base class for every ESC command.
# Extending classes have to override the configure and run function
extends Node
extends Resource
class_name ESCBaseCommand
@@ -22,7 +22,10 @@ func _init() -> void:
# Return the descriptor of the arguments of this command
func configure() -> ESCCommandArgumentDescriptor:
escoria.logger.error("Command %s did not override configure." % get_command_name())
escoria.logger.error(
self,
"Command %s did not override configure. Please implement a configure() function." % get_command_name()
)
return ESCCommandArgumentDescriptor.new()
@@ -33,7 +36,10 @@ func validate(arguments: Array) -> bool:
# Run the command
func run(command_params: Array) -> int:
escoria.logger.error("Command %s did not override run." % get_command_name())
escoria.logger.error(
self,
"Command %s did not override run. Please implement a run() function." % get_command_name()
)
return 0
@@ -44,4 +50,7 @@ func get_command_name() -> String:
# Function called when the command is interrupted.
func interrupt():
escoria.logger.trace("Command %s did not override interrupt." % get_command_name())
escoria.logger.trace(
self,
"Command %s did not override interrupt. Please implement an interrupt() function." % get_command_name()
)

View File

@@ -28,15 +28,15 @@ func _init(command_string):
if command_regex.search(command_string):
for result in command_regex.search_all(command_string):
if "name" in result.names:
self.name = escoria.utils.get_re_group(result, "name")
self.name = ESCUtils.get_re_group(result, "name")
if "parameters" in result.names:
# Split parameters by whitespace but allow quoted
# parameters
var quote_open = false
var parameter_values = PoolStringArray([])
var parsed_parameters = \
escoria.utils.sanitize_whitespace(
escoria.utils.get_re_group(
ESCUtils.sanitize_whitespace(
ESCUtils.get_re_group(
result,
"parameters"
).strip_edges()
@@ -66,7 +66,7 @@ func _init(command_string):
else:
parameters.append(parameter)
if "conditions" in result.names:
for condition in escoria.utils.get_re_group(
for condition in ESCUtils.get_re_group(
result,
"conditions"
).split(","):
@@ -74,22 +74,20 @@ func _init(command_string):
ESCCondition.new(condition.strip_edges())
)
else:
escoria.logger.report_errors(
"Invalid command detected: %s" % command_string,
[
"Command regexp didn't match"
]
escoria.logger.error(
self,
"Invalid command detected: %s\nCommand regexp didn't match."
% command_string
)
# Check, if conditions match
func is_valid() -> bool:
if not command_exists():
escoria.logger.report_errors(
"Invalid command detected: %s" % self.name,
[
"Command implementation not found in any command directory"
]
escoria.logger.error(
self,
"Invalid command detected: %s" % self.name +
"Command implementation not found in any command directory."
)
return false
@@ -100,8 +98,8 @@ func is_valid() -> bool:
#
# *Returns* True if the command exists, else false.
func command_exists() -> bool:
for base_path in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.COMMAND_DIRECTORIES
for base_path in ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.COMMAND_DIRECTORIES
):
var command_path = "%s/%s.gd" % [
base_path.trim_suffix("/"),
@@ -124,14 +122,18 @@ func run() -> int:
)
if command_object.validate(prepared_arguments):
escoria.logger.debug("Running command %s with parameters %s" % [
self.name,
prepared_arguments
])
escoria.logger.debug(
self,
"Running command %s with parameters %s."
% [self.name, prepared_arguments]
)
var rc = command_object.run(prepared_arguments)
if rc is GDScriptFunctionState:
rc = yield(rc, "completed")
escoria.logger.debug("[%s] Return code: %d" % [self.name, rc])
escoria.logger.debug(
self,
"[%s] Return code: %d." % [self.name, rc]
)
return rc
else:
return ESCExecution.RC_ERROR

View File

@@ -1,5 +1,5 @@
# The descriptor of the arguments of an ESC command
extends Object
extends Reference
class_name ESCCommandArgumentDescriptor
# As the get_type command was deprecated with Godot 2.x w we need a way to determine
@@ -71,7 +71,7 @@ func prepare_arguments(arguments: Array) -> Array:
# appear at the very end of a command's argument list.
varargs.append(arguments[index])
else:
complete_arguments[index] = escoria.utils.get_typed_value(
complete_arguments[index] = ESCUtils.get_typed_value(
arguments[index],
types[index]
)
@@ -98,22 +98,20 @@ func validate(command: String, arguments: Array) -> bool:
if required_args_count < min_args:
var verb = "was" if required_args_count == 1 else "were"
escoria.logger.report_errors(
"ESCCommandArgumentDescriptor:validate()",
[
"Invalid arguments for command %s" % command,
"Arguments didn't match minimum size {num}: Only {args} {verb} found" \
escoria.logger.error(
self,
"Invalid arguments for command %s. " % command +
"Arguments didn't match minimum size {num}: Only {args} {verb} found." \
.format({"num":self.min_args,"args":required_args_count,"verb":verb})
]
)
if arguments.size() > self.max_args and not has_varargs:
escoria.logger.report_errors(
"ESCCommandArgumentDescriptor:validate()",
[
"Invalid arguments for command %s" % command,
"Maximum number of arguments ({num}) exceeded: {args}".format({"num":self.max_args,"args":arguments})
]
escoria.logger.error(
self,
"Invalid arguments for command %s" % command +
"Maximum number of arguments ({num}) exceeded: {args}.".format(
{"num":self.max_args,"args":arguments}
)
)
for index in range(arguments.size()):
@@ -140,17 +138,17 @@ func validate(command: String, arguments: Array) -> bool:
for type in self.types[types_index]:
allowed_types += GODOT_TYPE_LIST[type] + " or "
allowed_types = allowed_types.substr(0, allowed_types.length() - 3) + "]"
escoria.logger.report_errors(
"Argument type did not match descriptor for command \"%s\"" %
command,
[
"Argument %d (\"%s\") is of type %s. Expected %s" % [
escoria.logger.error(
self,
"Argument type did not match descriptor for command \"%s\"\n"
% command +
"Argument %d (\"%s\") is of type %s. Expected %s."
% [
index,
arguments[index],
GODOT_TYPE_LIST[typeof(arguments[index])],
allowed_types
]
]
)
return true

View File

@@ -1,5 +1,5 @@
# A condition to run a command
extends Object
extends Reference
class_name ESCCondition
@@ -56,24 +56,24 @@ func _init(comparison_string: String):
if "is_negated" in result.names:
self.negated = true
if "comparison" in result.names:
match escoria.utils.get_re_group(result, "comparison"):
match ESCUtils.get_re_group(result, "comparison"):
"eq": self.comparison = COMPARISON_EQ
"gt": self.comparison = COMPARISON_GT
"lt": self.comparison = COMPARISON_LT
_: escoria.logger.report_errors(
_:
escoria.logger.error(
self,
"Invalid comparison type detected: %s" %
comparison_string,
[
comparison_string +
"Comparison type %s unknown" %
escoria.utils.get_re_group(
ESCUtils.get_re_group(
result,
"comparison"
)
]
)
if "comparison_value" in result.names:
self.comparison_value = escoria.utils.get_typed_value(
escoria.utils.get_re_group(
self.comparison_value = ESCUtils.get_typed_value(
ESCUtils.get_re_group(
result,
"comparison_value"
)
@@ -83,13 +83,12 @@ func _init(comparison_string: String):
if "is_activity" in result.names:
self.comparison = COMPARISON_ACTIVITY
if "flag" in result.names:
self.flag = escoria.utils.get_re_group(result, "flag")
self.flag = ESCUtils.get_re_group(result, "flag")
else:
escoria.logger.report_errors(
"Invalid comparison detected: %s" % comparison_string,
[
"Comparison regexp didn't match"
]
escoria.logger.error(
self,
"Invalid comparison detected: %s\nComparison regexp didn't match."
% comparison_string
)
@@ -98,6 +97,7 @@ func run() -> bool:
var global_name = self.flag
escoria.logger.debug(
self,
COMPARISON_DESCRIPTION[self.comparison] % [
"inventory item" if self.inventory else "global value",
self.flag,
@@ -138,6 +138,7 @@ func run() -> bool:
return_value = not return_value
escoria.logger.debug(
self,
"It is" if return_value else "It isn't"
)

View File

@@ -38,37 +38,36 @@ func load_string(dialog_string: String):
if dialog_regex.search(dialog_string):
for result in dialog_regex.search_all(dialog_string):
if "avatar" in result.names:
self.avatar = escoria.utils.get_re_group(result, "avatar")
self.avatar = ESCUtils.get_re_group(result, "avatar")
if "timeout" in result.names:
self.timeout = int(
escoria.utils.get_re_group(result, "timeout")
ESCUtils.get_re_group(result, "timeout")
)
if "timeout_option" in result.names:
self.timeout_option = int(
escoria.utils.get_re_group(result, "timeout_option")
ESCUtils.get_re_group(result, "timeout_option")
)
else:
escoria.logger.report_errors(
"Invalid dialog detected: %s" % dialog_string,
[
"Dialog regexp didn't match"
]
escoria.logger.error(
self,
"Invalid dialog detected: %s\nDialog regexp didn't match."
% dialog_string
)
# Check if dialog is valid
func is_valid() -> bool:
if self.avatar != "-" and not ResourceLoader.exists(self.avatar):
escoria.logger.report_errors(
"Avatar scene not found: %s" % self.avatar,
[]
escoria.logger.error(
self,
"Avatar scene not found: %s." % self.avatar
)
return false
if self.timeout_option > self.options.size() \
or self.timeout_option < 0:
escoria.logger.report_errors(
"Invalid timeout_option parameter given: %d" % self.timeout_option,
[]
escoria.logger.error(
self,
"Invalid timeout_option parameter given: %d." % self.timeout_option
)
return false
@@ -77,7 +76,10 @@ func is_valid() -> bool:
# Run this dialog
func run():
escoria.logger.debug("Starting dialog")
escoria.logger.debug(
self,
"Starting dialog."
)
escoria.current_state = escoria.GAME_STATE.DIALOG
if !escoria.dialog_player:
escoria.dialog_player = escoria.main.current_scene.get_node(

View File

@@ -30,13 +30,13 @@ func load_string(option_string: String):
var _trans_key = ""
if "trans_key" in result.names:
_trans_key = "%s:" % \
escoria.utils.get_re_group(result, "trans_key")
ESCUtils.get_re_group(result, "trans_key")
self.option = "%s%s" % [
_trans_key,
escoria.utils.get_re_group(result, "option")
ESCUtils.get_re_group(result, "option")
]
if "conditions" in result.names:
for condition_text in escoria.utils.get_re_group(
for condition_text in ESCUtils.get_re_group(
result,
"conditions"
).split(","):
@@ -44,11 +44,10 @@ func load_string(option_string: String):
ESCCondition.new(condition_text.strip_edges())
)
else:
escoria.logger.report_errors(
"Invalid dialog option detected: %s" % option_string,
[
escoria.logger.error(
self,
"Invalid dialog option detected: %s." % option_string,
"Dialog option regexp didn't match"
]
)

View File

@@ -60,10 +60,10 @@ func _init(event_string: String):
if event_regex.search(event_string):
for result in event_regex.search_all(event_string):
if "name" in result.names:
self.name = escoria.utils.get_re_group(result, "name") \
self.name = ESCUtils.get_re_group(result, "name") \
.strip_edges()
if "flags" in result.names:
var _flags = escoria.utils.get_re_group(
var _flags = ESCUtils.get_re_group(
result,
"flags"
).strip_edges().split(" ")
@@ -76,17 +76,19 @@ func _init(event_string: String):
if "NO_SAVE" in _flags:
self.flags |= FLAG_NO_SAVE
else:
escoria.logger.report_errors(
"Invalid event detected: %s" % event_string,
[
"Event regexp didn't match"
]
escoria.logger.error(
self,
"Invalid event detected: %s\nEvent regexp didn't match."
% event_string
)
# Execute this statement and return its return code
func run() -> int:
reset_interrupt()
escoria.logger.debug("Event %s started" % name)
escoria.logger.debug(
self,
"Event %s started." % name
)
return .run()

View File

@@ -1,5 +1,5 @@
# Basic features and informations about ESC executions
extends Object
extends Resource
class_name ESCExecution

View File

@@ -20,7 +20,7 @@ func _init(group_string: String):
if group_regex.search(group_string):
for result in group_regex.search_all(group_string):
if "conditions" in result.names:
for condition in escoria.utils.get_re_group(
for condition in ESCUtils.get_re_group(
result,
"conditions"
).split(","):
@@ -28,9 +28,8 @@ func _init(group_string: String):
ESCCondition.new(condition.strip_edges())
)
else:
escoria.logger.report_errors(
"Invalid group detected: %s" % group_string,
[
"Group regexp didn't match"
]
escoria.logger.error(
self,
"Invalid group detected: %s\nGroup regexp didn't match."
% group_string
)

View File

@@ -1,5 +1,5 @@
extends Reference
# An object handled in Escoria
extends Node
class_name ESCObject
@@ -50,23 +50,23 @@ func set_state(p_state: String, immediate: bool = false):
if animation_node.has_animation(p_state):
if immediate:
escoria.logger.debug(
"State \"%s\" set. Matching immediate animation executing." % [
p_state
]
self,
"State \"%s\" set. Matching immediate animation executing."
% p_state
)
animation_node.seek_end(p_state)
else:
escoria.logger.debug(
"State \"%s\" set. Matching non-immediate animation executing." % [
p_state
]
self,
"State \"%s\" set. Matching non-immediate animation executing."
% p_state
)
animation_node.play(p_state)
else:
escoria.logger.debug(
"State \"%s\" set. No matching animation found." % [
p_state
]
self,
"State \"%s\" set. No matching animation found."
% p_state
)

View File

@@ -1,5 +1,5 @@
# An event that is scheduled to run later
extends Object
extends Reference
class_name ESCScheduledEvent

View File

@@ -1,5 +1,5 @@
# A compiled ESC script
extends Object
extends Resource
class_name ESCScript

View File

@@ -1,5 +1,5 @@
# A statement in an ESC file
extends Object
extends Reference
class_name ESCStatement
@@ -7,7 +7,7 @@ class_name ESCStatement
signal finished(event, return_code)
# Emitted when the event was interrupted
signal interrupted(return_code)
signal interrupted(event, return_code)
# The list of ESC commands
@@ -35,7 +35,7 @@ func run() -> int:
if _is_interrupted:
final_rc = ESCExecution.RC_INTERRUPTED
statement.interrupt()
emit_signal("interrupted", final_rc)
emit_signal("interrupted", self, final_rc)
return final_rc
if statement.is_valid():
@@ -43,9 +43,8 @@ func run() -> int:
if rc is GDScriptFunctionState:
rc = yield(rc, "completed")
escoria.logger.debug(
"esc_statement",
["Statement (%s) was completed."
% statement]
self,
"Statement (%s) was completed." % statement
)
if rc == ESCExecution.RC_REPEAT:
return self.run()
@@ -59,11 +58,10 @@ func run() -> int:
# Interrupt the statement in the middle of its execution.
func interrupt():
escoria.logger.info("Interrupting event %s (%s)" % \
[
self.name if "name" in self else "group",
str(self)
]
escoria.logger.info(
self,
"Interrupting event %s (%s)."
% [self.name if "name" in self else "group", str(self)]
)
_is_interrupted = true
for statement in statements:

View File

@@ -96,7 +96,7 @@ func _ready():
# Handle debugging visualizations
func _draw():
if !Engine.is_editor_hint():
if not Engine.is_editor_hint():
return
if editor_debug_mode == EDITOR_GAME_DEBUG_DISPLAY.NONE:
return
@@ -131,12 +131,9 @@ func do_walk(destination, params: Array = [], can_interrupt: bool = false) -> vo
# Check moving object.
if not escoria.object_manager.has(params[0]):
escoria.logger.report_errors(
"esc_game.gd:do_walk()",
[
"Walk action requested on nonexisting " + \
"object: %s " % params[0]
]
escoria.logger.error(
self,
"Walk action requested on nonexisting object: %s." % params[0]
)
return
@@ -145,12 +142,9 @@ func do_walk(destination, params: Array = [], can_interrupt: bool = false) -> vo
if destination is String:
if not escoria.object_manager.has(destination):
escoria.logger.report_errors(
"esc_game.gd:do_walk()",
[
"Walk action requested to nonexisting " + \
"object: %s " % destination
]
escoria.logger.error(
self,
"Walk action requested to nonexisting object: %s." % destination
)
return
@@ -436,8 +430,8 @@ func show_crash_popup(files: Array = []) -> void:
var files_to_send: String = ""
for file in files:
files_to_send += "- %s\n" % file
crash_popup.dialog_text = tr(escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.CRASH_MESSAGE)
crash_popup.dialog_text = tr(ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.CRASH_MESSAGE)
) % files_to_send
crash_popup.popup_centered()
escoria.set_game_paused(true)
@@ -451,9 +445,9 @@ func escoria_hide_ui():
if ui_parent_control_node != null and not ui_parent_control_node.is_empty():
(get_node(ui_parent_control_node) as Control).visible = false
else:
escoria.logger.report_warnings(
"esc_game.gd#escoria_hide_ui",
["UI parent Control node not defined!"]
escoria.logger.warn(
self,
"UI parent Control node not defined!"
)
@@ -463,9 +457,9 @@ func escoria_show_ui():
if ui_parent_control_node != null and not ui_parent_control_node.is_empty():
(get_node(ui_parent_control_node) as Control).visible = true
else:
escoria.logger.report_warnings(
"esc_game.gd#escoria_show_ui",
["UI parent Control node not defined!"]
escoria.logger.warn(
self,
"UI parent Control node not defined!"
)

View File

@@ -323,7 +323,10 @@ func _unhandled_input(input_event: InputEvent) -> void:
if event is InputEventMouseButton and event.is_pressed():
if not escoria.current_state == escoria.GAME_STATE.DEFAULT:
escoria.logger.info("Game state doesn't accept interactions")
escoria.logger.info(
self,
"Current game state doesn't accept interactions."
)
return
var p = get_global_mouse_position()
if _is_in_shape(p):
@@ -367,8 +370,9 @@ func get_animation_player() -> Node:
child is AnimationPlayer:
player_node_path = child.get_path()
if not has_node(player_node_path):
escoria.logger.warning(
"Can not find node at path %s" % player_node_path
escoria.logger.warn(
self,
"Can not find animation_player node at path %s for %s." % [player_node_path, global_id]
)
else:
_animation_player = ESCAnimationPlayer.new(
@@ -394,7 +398,9 @@ func get_interact_position() -> Vector2:
interact_position = collision.global_position
if multiple_positions_found:
escoria.logger.warning("Multiple ESClocations found to walk to for object " +
escoria.logger.warn(
self,
"Multiple ESClocations found to walk to for object " +
"%s. Last one will be used." % global_id)
return interact_position
@@ -500,7 +506,8 @@ func get_sprite() -> Node:
_sprite_node = child
if _sprite_node == null:
escoria.logger.error(
"No sprite node found in the scene %s" % get_path()
self,
"No sprite node found in the scene %s." % get_path()
)
return _sprite_node
@@ -579,7 +586,11 @@ func update_idle():
# global position of the player
func get_camera_node():
if has_node(camera_node):
escoria.logger.debug("Camera node found - directing camera to the camera_node on " + global_id)
escoria.logger.debug(
self,
"Camera node found - directing camera to the camera_node on %s."
% global_id
)
return get_node(camera_node)
return self

View File

@@ -1,5 +1,5 @@
# A cache for resources
extends Object
extends Reference
class_name ESCResourceCache
var thread: Thread
@@ -138,7 +138,7 @@ func get_resource(path):
return res
else:
_unlock("return")
# We can't use escoria.project_settings_manager here since this method
# We can't use ESCProjectSettingsManager here since this method
# can be called from escoria._init()
if not ProjectSettings.get_setting("escoria/platform/skip_cache"):
var res = ResourceLoader.load(path)

View File

@@ -60,7 +60,10 @@ func _enter_tree():
# name of this node if it's not set manually
func _ready():
# Might as well just check here.
if get_parent() == get_tree().root and ProjectSettings.get_setting("application/run/main_scene") != self.filename:
if get_parent() == get_tree().root \
and ESCProjectSettingsManager.get_setting(
"application/run/main_scene"
) != self.filename:
is_run_directly = true
escoria.room_manager.init_room(self)
@@ -85,7 +88,9 @@ func _draw():
# Draw lines for camera limits
for i in camera_limits.size():
draw_rect(camera_limits[i], camera_limits_colors[i], false, 10.0)
var default_font = Control.new().get_font("font")
var temp_control = Control.new()
var default_font = temp_control.get_font("font")
temp_control.queue_free()
draw_string(default_font, Vector2(camera_limits[i].position.x + 30,
camera_limits[i].position.y + 30), str(i), camera_limits_colors[i])

View File

@@ -64,20 +64,16 @@ func _ready():
if n is NavigationPolygonInstance:
if n.enabled:
if !Engine.is_editor_hint() and navigation_enabled_found:
escoria.logger.report_errors(
"ESCTerrain:_ready()",
[
escoria.logger.error(
self,
"Multiple NavigationPolygonInstances enabled " + \
"at the same time."
]
)
elif Engine.is_editor_hint():
escoria.logger.report_warnings(
"ESCTerrain:_ready()",
[
escoria.logger.warn(
self,
"Multiple NavigationPolygonInstances enabled " + \
"at the same time."
]
)
navigation_enabled_found = true
current_active_navigation_instance = n

View File

@@ -85,6 +85,7 @@ func set_debug_mode(p_debug_mode: bool):
else:
if debug_texturerect_node:
remove_child(debug_texturerect_node)
debug_texturerect_node.queue_free()
# Set the first target of the label.

View File

@@ -1,6 +1,6 @@
# The walk context describes the target of a walk command and if that command
# should be executed fast
extends Object
extends Reference
class_name ESCWalkContext

View File

@@ -1,325 +0,0 @@
# Logging framework for Escoria
extends Object
class_name ESCLogger
# Log file format
const LOG_FILE_FORMAT: String = "log_%s_%s.log"
# The path of the ESC file that was reported last (used for removing
# duplicate warnings
var warning_path: String
# Log file handler
var log_file: File
# Crash save filename
var crash_savegame_filename
# Did we crash already?
onready var crashed = false
# Valid log levels
enum { LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_TRACE }
# A map of log level names to log level ints
var _level_map: Dictionary = {
"ERROR": LOG_ERROR,
"WARNING": LOG_WARNING,
"INFO": LOG_INFO,
"DEBUG": LOG_DEBUG,
"TRACE": LOG_TRACE,
}
# Logger constructor
func _init():
# Open logfile in write mode
log_file = File.new()
# this is left alone as this constructor is called from escoria.gd's own
# constructor
var log_file_path = ProjectSettings.get_setting(
"escoria/debug/log_file_path"
)
var date = OS.get_datetime()
log_file_path = log_file_path.plus_file(LOG_FILE_FORMAT % [
str(date["year"]) + str(date["month"]) + str(date["day"]),
str(date["hour"]) + str(date["minute"]) + str(date["second"])
])
log_file.open(
log_file_path,
File.WRITE
)
# Log a trace message
#
# Global variables can be substituted into the text by wrapping the global
# name in braces.
# e.g. trace "There are {coin_count} coins remaining".
#
# #### Parameters
#
# * string: Text to log
# * args: Additional information
func trace(string: String, args = []):
if _get_log_level() >= LOG_TRACE and !crashed:
var argsstr = str(args) if !args.empty() else ""
string = escoria.esc_compiler.replace_globals(string)
_log("(T)\t" + string + " \t" + argsstr)
# Log a debug message
#
# Global variables can be substituted into the text by wrapping the global
# name in braces.
# e.g. debug "There are {coin_count} coins remaining".
#
# #### Parameters
#
# * string: Text to log
# * args: Additional information
func debug(string: String, args = []):
if _get_log_level() >= LOG_DEBUG and !crashed:
string = escoria.esc_compiler.replace_globals(string)
var argsstr = str(args) if !args.empty() else ""
_log("(D)\t" + string + " \t" + argsstr)
# Log an info message
#
# Global variables can be substituted into the text by wrapping the global
# name in braces.
# e.g. info "There are {coin_count} coins remaining".
#
# #### Parameters
#
# * string: Text to log
# * args: Additional information
func info(string: String, args = []):
if _get_log_level() >= LOG_INFO and !crashed:
var argsstr = []
if !args.empty():
for arg in args:
if arg is Array:
for p in arg:
argsstr.append(p.global_id)
else:
argsstr.append(str(arg))
string = escoria.esc_compiler.replace_globals(string)
_log("(I)\t" + string + " \t" + str(argsstr))
# Log a warning message
#
# Global variables can be substituted into the text by wrapping the global
# name in braces.
# e.g. warning "There are {coin_count} coins remaining".
#
# #### Parameters
#
# * string: Text to log
# * args: Additional information
func warning(string: String, args = []):
if _get_log_level() >= LOG_WARNING and !crashed:
var argsstr = str(args) if !args.empty() else ""
string = escoria.esc_compiler.replace_globals(string)
_log("(W)\t" + string + " \t" + argsstr, true)
if escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.TERMINATE_ON_WARNINGS
):
_perform_stack_trace_log()
crashed = true
var files = "- %s" % log_file.get_path_absolute()
var message = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.CRASH_MESSAGE
) % files
_log(message, true)
escoria.set_game_paused(true)
escoria.main.current_scene.game.show_crash_popup(
[log_file.get_path_absolute()]
)
assert(false)
# Log an error message
#
# Global variables can be substituted into the text by wrapping the global
# name in braces.
# e.g. error "There are {coin_count} coins remaining".
#
# #### Parameters
#
# * string: Text to log
# * args: Additional information
func error(string: String, args = [], do_savegame: bool = true):
if _get_log_level() >= LOG_ERROR and !crashed:
var argsstr = str(args) if !args.empty() else ""
string = escoria.esc_compiler.replace_globals(string)
_log("(E)\t" + string + " \t" + argsstr, true)
if escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.TERMINATE_ON_ERRORS
):
_perform_stack_trace_log()
crashed = true
if do_savegame:
_perform_save_game_log()
var files_to_send: Array = [
log_file.get_path_absolute().get_base_dir().plus_file(
escoria.save_manager.crash_savegame_filename.get_file()
),
log_file.get_path_absolute()
]
var files = "- %s\n- %s" % files_to_send
var message = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.CRASH_MESSAGE
) % files
_log(message, true)
escoria.set_game_paused(true)
if is_instance_valid(escoria.main.current_scene):
escoria.main.current_scene.game.show_crash_popup(files_to_send)
assert(false)
# Log a warning message about an ESC file
#
# #### Parameters
#
# * p_path: Path to the file
# * warnings: Array of warnings to put out
# * report_once: Additional messages about the same file will be ignored
func report_warnings(p_path: String, warnings: Array, report_once = false) -> void:
var warning_is_reported = false
if p_path == warning_path:
warning_is_reported = true
if !warning_is_reported:
var text = "Warnings in file "+p_path+"\n"
for w in warnings:
if w is Array:
text += str(w)+"\n"
else:
text += w+"\n"
warning(text)
if report_once:
warning_is_reported = true
# Log an error message about an ESC file
#
# #### Parameters
#
# * p_path: Path to the file
# * errors: Array of errors to put out
func report_errors(p_path: String, errors: Array) -> void:
var text = "Errors in file "+p_path+"\n"
for e in errors:
if e is Array:
text += str(e)+"\n"
else:
text += e+"\n"
error(text)
# Write message:
# - in logfile
# - in stdout, or stderr if err is true.
#
# #### Parameters
#
# * message: Message to log
# * err: if true, write in stderr
func _log(message:String, err: bool = false):
message = "ESC {0} {1}".format([_formatted_date(), message])
if err:
printerr(message)
else:
print(message)
_write_logfile(message)
# Returns the current date/time, as a string
# formatted for logging. E.g. 2022-04-19T16:10:39
func _formatted_date() -> String:
var info = OS.get_datetime()
info["year"] = "%04d" % info["year"]
info["month"] = "%02d" % info["month"]
info["day"] = "%02d" % info["day"]
info["hour"] = "%02d" % info["hour"]
info["minute"] = "%02d" % info["minute"]
info["second"] = "%02d" % info["second"]
return "{year}-{month}-{day}T{hour}:{minute}:{second}".format(info)
# Returns the currently set log level
# **Returns** Log level as set in the configuration
func _get_log_level() -> int:
return _level_map[escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.LOG_LEVEL
)]
# Creates a savegame file and save it in output log location
func _perform_save_game_log():
_log("Performing emergency savegame.")
var error = escoria.save_manager.save_game_crash()
if error == OK:
_log(
"Emergency savegame created successfully in folder: %s" %
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.LOG_FILE_PATH
)
)
else:
_log("Emergency savegame creation failed!", false)
# Logs and writes the stack trace into stdout and log file.
func _perform_stack_trace_log():
_log("Stack trace:")
print_stack()
_write_stack_logfile()
# Write a message in the output logfile
#
# #### Parameters
#
# * message: Message to write
func _write_logfile(message: String) -> void:
if log_file.is_open():
log_file.store_string(message + "\n")
# Write the stacktrace in the output logfile
func _write_stack_logfile():
var frame_number = 0
for stack in get_stack().slice(2, get_stack().size()):
_write_logfile(
"Frame %s - %s:%s in function '%s'" % [
str(frame_number),
stack["source"],
stack["line"],
stack["function"],
]
)
frame_number += 1
# Close the log file cleanly
func close_logs():
_log("Closing logs peacefully.")
log_file.close()

View File

@@ -1,6 +1,6 @@
# Base class for all migration version scripts. Extending scripts should be
# named like the version they migrate the savegame to. (e.g. 1.0.0.gd, 1.0.1.gd)
extends Object
extends Reference
class_name ESCMigration

View File

@@ -1,5 +1,5 @@
# Class that handles migrations between different game or escoria versions
extends Object
extends Reference
class_name ESCMigrationManager
@@ -29,10 +29,11 @@ func migrate(
to: String,
versions_directory: String
) -> ESCSaveGame:
escoria.logger.info("Migrating from version %s to %s" % [
from,
to
])
escoria.logger.info(
self,
"Migrating savegame from version %s to version %s."
% [from, to]
)
var from_info = version_regex.search(from)
var to_info = version_regex.search(to)
@@ -49,14 +50,11 @@ func migrate(
wrong_version = true
if wrong_version:
escoria.logger.report_errors(
"esc_migration_manager:migrate",
[
"Can not migrate savegame from version %s to version %s" % [
from,
to
]
]
escoria.logger.error(
self,
"Can not migrate savegame from version %s to version %s." +
" \"To\" version must be later than \"from\" version."
% [from, to]
)
var versions = _find_versions(versions_directory, from, to)
@@ -67,13 +65,14 @@ func migrate(
for version in versions:
var migration_script = load(version).new()
if not migration_script is ESCMigration:
escoria.logger.report_errors(
"esc_migration_manager:migrate",
[
"File %s is not a valid migration script" % version
]
escoria.logger.error(
self,
"File %s is not a valid migration script." % version
)
escoria.logger.debug(
self,
"Migrating savegame to version %s." % version
)
escoria.logger.debug("Migrating using %s" % version)
(migration_script as ESCMigration).set_savegame(savegame)
(migration_script as ESCMigration).migrate()
savegame = (migration_script as ESCMigration).get_savegame()
@@ -90,7 +89,10 @@ func migrate(
# - to: End version to check
# **Returns** A list of version scripts
func _find_versions(directory: String, from: String, to: String) -> Array:
escoria.logger.trace("Searching directory %s" % directory)
escoria.logger.trace(
self,
"Searching directory %s." % directory
)
var versions = []
var dir = Directory.new()
dir.open(directory)
@@ -106,7 +108,10 @@ func _find_versions(directory: String, from: String, to: String) -> Array:
to
)
elif regex_result and _version_between(version, from, to):
escoria.logger.trace("Found fitting migration script %s" % version)
escoria.logger.trace(
self,
"Found compatible savegame migration script for version %s." % version
)
versions.append(
directory.plus_file(file_name)
)

View File

@@ -0,0 +1,102 @@
class_name EscoriaPlugin
# Register a user interface. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - plugin: the plugin that registers
# - game_scene: Path to the game scene extending ESCGame
#
# *Returns* a boolean indicating whether the ui could be successfully registered
static func register_ui(plugin: EditorPlugin, game_scene: String) -> bool:
if not plugin.get_editor_interface().is_plugin_enabled(
Escoria.ESCORIA_CORE_PLUGIN_NAME
):
push_error("Escoria Core must be enabled.")
return false
var game_scene_setting_value = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_SCENE
)
if not game_scene_setting_value in [
"",
game_scene
]:
push_error("Can't register user interface because user interface %s is registered."
% game_scene_setting_value
)
return false
ESCProjectSettingsManager.set_setting(
ESCProjectSettingsManager.GAME_SCENE,
game_scene
)
return true
# Deregister a user interface
#
# #### Parameters
# - game_scene: Path to the game scene extending ESCGame
static func deregister_ui(game_scene: String):
# If the currently configured game scene is not the one we're disabling, exit now.
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_SCENE
) != game_scene:
return
ESCProjectSettingsManager.set_setting(
ESCProjectSettingsManager.GAME_SCENE,
""
)
# Register a dialog manager addon. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - plugin: the plugin that registers
# - manager_class: Path to the manager class script
#
# *Returns* a boolean value indicating whether the dialog manager was registered
static func register_dialog_manager(plugin: EditorPlugin, manager_class: String) -> bool:
if not plugin.get_editor_interface().is_plugin_enabled(
Escoria.ESCORIA_CORE_PLUGIN_NAME
):
push_error("Escoria Core must be enabled.")
return false
var dialog_managers: Array = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS
)
if manager_class in dialog_managers:
return true
dialog_managers.push_back(manager_class)
ESCProjectSettingsManager.set_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS,
dialog_managers
)
return true
# Deregister a dialog manager addon
#
# #### Parameters
# - manager_class: Path to the manager class script
static func deregister_dialog_manager(manager_class: String):
var dialog_managers: Array = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS
)
# If the dialog manager we're removing in not in the registered list, return quietly.
if not manager_class in dialog_managers:
return
dialog_managers.erase(manager_class)
ESCProjectSettingsManager.set_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS,
dialog_managers
)

View File

@@ -1,5 +1,5 @@
# Describes a resource for use in the resource cache
extends Object
extends Resource
class_name ESCResourceDescriptor

View File

@@ -76,9 +76,9 @@ func get_saves_list() -> Dictionary:
var save_game_res: Resource = load(save_path)
if save_game_res == null:
escoria.logger.report_warnings(
"esc_save_manager.gd",
["Savegame file %s is corrupted. Skipping." % save_path]
escoria.logger.warn(
self,
"Savegame file %s is corrupted. Skipping." % save_path
)
else:
var save_game_data = {
@@ -91,12 +91,10 @@ func get_saves_list() -> Dictionary:
if matches != null and matches.get_string("slotnumber") != null:
saves[int(matches.get_string("slotnumber"))] = save_game_data
else:
escoria.logger.report_warnings(
"esc_save_manager.gd",
[
escoria.logger.warn(
self,
"Savegame file %s contains valid data but doesn't match filename format %s. Skipping."
% [save_path, regex.get_pattern()]
]
)
nextfile = dirsave.get_next()
return saves
@@ -121,8 +119,9 @@ func save_game_exists(id: int) -> bool:
func save_game(id: int, p_savename: String):
if not save_enabled:
escoria.logger.debug(
"esc_save_manager.gd",
["Save requested while saving is not possible. Save canceled."])
self,
"Save requested while saving is not possible. Save cancelled."
)
return
var save_game := _do_save_game(p_savename)
@@ -134,9 +133,9 @@ func save_game(id: int, p_savename: String):
var save_path = save_folder.plus_file(SAVE_NAME_TEMPLATE % id)
var error: int = ResourceSaver.save(save_path, save_game)
if error != OK:
escoria.logger.report_errors(
"esc_save_manager.gd",
["There was an issue writing the save %s to %s" % [id, save_path]]
escoria.logger.error(
self,
"There was an issue writing savegame number %s to %s." % [id, save_path]
)
@@ -153,8 +152,8 @@ func save_game_crash():
var save_game := _do_save_game("Crash %s" % datetime_string)
var save_file_path: String = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.LOG_FILE_PATH
var save_file_path: String = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.LOG_FILE_PATH
)
crash_savegame_filename = save_file_path.plus_file(
CRASH_SAVE_NAME_TEMPLATE % [
@@ -167,10 +166,11 @@ func save_game_crash():
var error: int = ResourceSaver.save(crash_savegame_filename, save_game)
if error != OK:
escoria.logger.report_errors(
"esc_save_manager.gd",
["There was an issue writing the crash save to %s"
% crash_savegame_filename])
escoria.logger.error(
self,
"There was an issue writing the crash save to %s."
% crash_savegame_filename
)
return error
@@ -185,8 +185,8 @@ func _do_save_game(p_savename: String) -> ESCSaveGame:
plugin_config.load("res://addons/escoria-core/plugin.cfg")
save_game.escoria_version = plugin_config.get_value("plugin", "version")
save_game.game_version = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_VERSION
save_game.game_version = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_VERSION
)
save_game.name = p_savename
@@ -216,14 +216,16 @@ func load_game(id: int):
var save_file_path: String = save_folder.plus_file(SAVE_NAME_TEMPLATE % id)
var file: File = File.new()
if not file.file_exists(save_file_path):
escoria.logger.report_errors(
"esc_save_manager.gd:load_game()",
["Save file %s doesn't exist" % save_file_path])
escoria.logger.error(
self,
"Save file %s doesn't exist." % save_file_path
)
return
escoria.logger.info(
"esc_save_manager.gd:load_game()",
["Loading savegame %s" % str(id)])
self,
"Loading savegame %s." % str(id)
)
var save_game: ESCSaveGame = ResourceLoader.load(save_file_path)
@@ -243,21 +245,21 @@ func load_game(id: int):
)
# Migrate savegame through game versions
if escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_VERSION
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_VERSION
) != save_game.game_version \
and escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_MIGRATION_PATH
and ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_MIGRATION_PATH
) != "":
var migration_manager: ESCMigrationManager = ESCMigrationManager.new()
save_game = migration_manager.migrate(
save_game,
save_game.game_version,
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_VERSION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_VERSION
),
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_MIGRATION_PATH
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_MIGRATION_PATH
)
)
@@ -271,8 +273,8 @@ func load_game(id: int):
"%s %s out" %
[
_transition.get_command_name(),
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANSITION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION
)]
)
)
@@ -391,8 +393,8 @@ func load_game(id: int):
"%s %s in" %
[
_transition.get_command_name(),
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANSITION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION
)]
)
)
@@ -402,9 +404,7 @@ func load_game(id: int):
escoria.set_game_paused(false)
escoria.event_manager.queue_event(load_event)
escoria.logger.debug(
"esc_save_manager.gd:load_game()",
["Load event queued."])
escoria.logger.debug(self, "Load event queued.")
# Save the game settings in the settings file.
@@ -432,9 +432,9 @@ func save_settings():
var save_path = settings_folder.plus_file(SETTINGS_TEMPLATE)
var error: int = ResourceSaver.save(save_path, settings_res)
if error != OK:
escoria.logger.report_errors(
escoria.logger.error(
"esc_save_manager.gd:save_settings()",
["There was an issue writing settings %s" % save_path])
["There was an issue writing settings file %s." % save_path])
# Load the game settings from the settings file
@@ -444,10 +444,11 @@ func load_settings() -> Resource:
settings_folder.plus_file(SETTINGS_TEMPLATE)
var file: File = File.new()
if not file.file_exists(save_settings_path):
escoria.logger.report_warnings(
"esc_save_manager.gd:load_settings()",
["Settings file %s doesn't exist" % save_settings_path,
"Setting default settings."])
escoria.logger.warn(
self,
"Settings file %s doesn't exist. Using default settings."
% save_settings_path
)
save_settings()
return load(save_settings_path)

View File

@@ -1,5 +1,5 @@
# A set of common utilities
extends Object
extends Reference
class_name ESCUtils
@@ -9,7 +9,7 @@ class_name ESCUtils
#
# - rad_angle: Angle in radians
# **Returns** Degrees
func get_deg_from_rad(rad_angle: float):
static func get_deg_from_rad(rad_angle: float):
var deg = rad2deg(rad_angle)
if deg >= 360.0:
deg = clamp(deg, 0.0, 360.0)
@@ -25,7 +25,7 @@ func get_deg_from_rad(rad_angle: float):
# - re_match: The RegExMatch object
# - group: The name of the group
# **Returns** The value of the named regex group in the match
func get_re_group(re_match: RegExMatch, group: String) -> String:
static func get_re_group(re_match: RegExMatch, group: String) -> String:
if group in re_match.names:
return re_match.strings[re_match.names[group]]
else:
@@ -39,7 +39,7 @@ func get_re_group(re_match: RegExMatch, group: String) -> String:
# - value: The original value
# - type_hint: The type it should be
# **Returns** The typed value according to the type inference
func get_typed_value(value: String, type_hint = []):
static func get_typed_value(value: String, type_hint = []):
var regex_bool = RegEx.new()
regex_bool.compile("^true|false$")
var regex_float = RegEx.new()
@@ -68,7 +68,7 @@ func get_typed_value(value: String, type_hint = []):
#
# - value: String to work on
# **Returns** the string with sanitized whitespaces
func sanitize_whitespace(value: String) -> String:
static func sanitize_whitespace(value: String) -> String:
var tab_regex = RegEx.new()
tab_regex.compile("\\t")
var double_regex = RegEx.new()

View File

@@ -0,0 +1,195 @@
# This is Escoria's singleton script.
# It holds accessors to some utils, such as Escoria's logger.
extends Node
# Signal sent when Escoria is paused
signal paused
# Signal sent when Escoria is resumed from pause
signal resumed
# Current game state
# * DEFAULT: Common game function
# * DIALOG: Game is playing a dialog
# * WAIT: Game is waiting
enum GAME_STATE {
DEFAULT,
DIALOG,
WAIT
}
# Audio bus indices.
const BUS_MASTER = "Master"
const BUS_SFX = "SFX"
const BUS_MUSIC = "Music"
const BUS_SPEECH = "Speech"
# Path to camera scene
const CAMERA_SCENE_PATH = "res://addons/escoria-core/game/scenes/camera_player/camera.tscn"
# Logger class
const Logger = preload("res://addons/escoria-core/game/esc_logger.gd")
# Logger instance
var logger = Logger.ESCLoggerFile.new()
# ESC Compiler
var esc_compiler = ESCCompiler.new()
# ESC Object Manager
var object_manager = ESCObjectManager.new()
# ESC Room Manager
var room_manager = ESCRoomManager.new()
# Terrain of the current room
var room_terrain
# The inventory manager instance
var inventory_manager: ESCInventoryManager
# The action manager instance
var action_manager: ESCActionManager
# ESC Event manager instance
var event_manager: ESCEventManager
# ESC globals registry instance
var globals_manager: ESCGlobalsManager
# ESC command registry instance
var command_registry: ESCCommandRegistry
# Resource cache handler
var resource_cache: ESCResourceCache
# Dialog player instantiator. This instance is called directly for dialogs.
var dialog_player: ESCDialogPlayer
# Inventory scene
var inventory
# These are settings that the player can affect and save/load later
var settings: ESCSaveSettings
# The main scene
var main
# The escoria inputs manager
var inputs_manager: ESCInputsManager
# Savegames and settings manager
var save_manager: ESCSaveManager
# The game scene loaded
var game_scene: ESCGame
# The main player camera
var player_camera: ESCCamera
# The compiled start script loaded from ProjectSettings
# escoria/main/game_start_script
var start_script: ESCScript
# Whether we ran a room directly from editor, not a full game
var is_direct_room_run: bool = false
# Whether we're quitting the game
var is_quitting: bool = false
# The game resolution
onready var game_size = get_viewport().size
# The current state of the game
onready var current_state = GAME_STATE.DEFAULT
# Ready function
func _ready():
# We check if we run the full game or a room scene directly
if not get_tree().current_scene is ESCMain:
# Running a room scene. We need to instantiate the main scene ourselves
# so that the Escoria scene is created and managers are instanced as well.
is_direct_room_run = true
var main_scene = preload("res://addons/escoria-core/game/main_scene.tscn").instance()
add_child(main_scene)
# Get the Escoria node. That node gives access to the Escoria scene that's
# instanced by the main_scene (if full game is run) or by this autoload if
# room is run directly.
func get_escoria():
# We check if we run the full game or a room scene directly
if get_tree().current_scene is ESCMain:
return get_node("/root/main_scene").escoria_node
else:
return get_node("main_scene").escoria_node
# Pauses or unpause the game
#
# #### Parameters
# - p_paused: if true, pauses the game. If false, unpauses the game.
func set_game_paused(p_paused: bool):
if p_paused:
emit_signal("paused")
else:
emit_signal("resumed")
var scene_tree = get_tree()
if is_instance_valid(scene_tree):
scene_tree.paused = p_paused
# Apply the loaded settings
#
# #### Parameters
#
# * p_settings: Loaded settings
func apply_settings(p_settings: ESCSaveSettings) -> void:
if not Engine.is_editor_hint():
escoria.logger.info(self, "******* settings loaded")
if p_settings != null:
settings = p_settings
else:
settings = ESCSaveSettings.new()
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_MASTER),
linear2db(settings.master_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_SFX),
linear2db(settings.sfx_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_MUSIC),
linear2db(settings.music_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_SPEECH),
linear2db(settings.speech_volume)
)
TranslationServer.set_locale(settings.text_lang)
game_scene.apply_custom_settings(settings.custom_settings)
# Called from main menu's "new game" button
func new_game():
get_escoria().new_game()
# Called from main menu's "quit" button
func quit():
is_quitting = true
get_escoria().quit()

View File

@@ -1,6 +1,6 @@
# Escoria inputs manager
# Catches, handles and distributes input events for the game
extends Node
extends Resource
class_name ESCInputsManager
@@ -166,7 +166,10 @@ func clear_stack():
# - position: Position of the click
func _on_left_click_on_bg(position: Vector2) -> void:
if input_mode == INPUT_ALL and hotspot_focused.empty():
escoria.logger.info("Left click on background at ", [str(position)])
escoria.logger.info(
self,
"Left click on background at %s." % str(position)
)
escoria.main.current_scene.game.left_click_on_bg(position)
@@ -178,7 +181,8 @@ func _on_left_click_on_bg(position: Vector2) -> void:
func _on_double_left_click_on_bg(position: Vector2) -> void:
if input_mode == INPUT_ALL and hotspot_focused.empty():
escoria.logger.info(
"Double left click on background at %s" % str(position)
self,
"Double left click on background at %s." % str(position)
)
escoria.main.current_scene.game.left_double_click_on_bg(position)
@@ -190,7 +194,10 @@ func _on_double_left_click_on_bg(position: Vector2) -> void:
# - position: Position of the click
func _on_right_click_on_bg(position: Vector2) -> void:
if input_mode == INPUT_ALL and hotspot_focused.empty():
escoria.logger.info("Right click on background at ", [str(position)])
escoria.logger.info(
self,
"Right click on background at %s." % str(position)
)
escoria.main.current_scene.game.right_click_on_bg(position)
@@ -205,7 +212,8 @@ func _on_mouse_left_click_inventory_item(
event: InputEvent
) -> void:
escoria.logger.info(
"Inventory item left clicked %s " % inventory_item_global_id
self,
"Inventory item %s left clicked." % inventory_item_global_id
)
escoria.main.current_scene.game.left_click_on_inventory_item(
inventory_item_global_id,
@@ -225,7 +233,8 @@ func _on_mouse_right_click_inventory_item(
) -> void:
if input_mode == INPUT_ALL:
escoria.logger.info(
"Inventory item right clicked %s" % inventory_item_global_id
self,
"Inventory item %s right clicked." % inventory_item_global_id
)
escoria.main.current_scene.game.right_click_on_inventory_item(
inventory_item_global_id,
@@ -245,7 +254,8 @@ func _on_mouse_double_left_click_inventory_item(
) -> void:
if input_mode == INPUT_ALL:
escoria.logger.info(
"Inventory item double left clicked %s" % inventory_item_global_id
self,
"Inventory item %s double left clicked." % inventory_item_global_id
)
escoria.main.current_scene.game.left_double_click_on_inventory_item(
inventory_item_global_id,
@@ -261,7 +271,8 @@ func _on_mouse_double_left_click_inventory_item(
# that is hovered
func _on_mouse_entered_inventory_item(inventory_item_global_id: String) -> void:
escoria.logger.info(
"Inventory item focused %s" % inventory_item_global_id
self,
"Inventory item %s focused." % inventory_item_global_id
)
escoria.main.current_scene.game.inventory_item_focused(
inventory_item_global_id
@@ -270,7 +281,10 @@ func _on_mouse_entered_inventory_item(inventory_item_global_id: String) -> void:
# The mouse exited an inventory item
func _on_mouse_exited_inventory_item() -> void:
escoria.logger.info("Inventory item unfocused")
escoria.logger.info(
self,
"Inventory item unfocused."
)
escoria.main.current_scene.game.inventory_item_unfocused()
@@ -280,7 +294,10 @@ func _on_mouse_exited_inventory_item() -> void:
#
# - item: The Escoria item hovered
func _on_mouse_entered_item(item: ESCItem) -> void:
escoria.logger.info("Item focused: ", [item.global_id])
escoria.logger.info(
self,
"Item focused: %s" % item.global_id
)
_clean_hover_stack()
if not hover_stack.empty():
@@ -301,7 +318,10 @@ func _on_mouse_entered_item(item: ESCItem) -> void:
#
# - item: The Escoria item hovered
func _on_mouse_exited_item(item: ESCItem) -> void:
escoria.logger.info("Item unfocused: ", [item.global_id])
escoria.logger.info(
self,
"Item unfocused: %s" % item.global_id
)
_hover_stack_erase_item(item)
if hover_stack.empty():
hotspot_focused = ""
@@ -320,7 +340,10 @@ func _on_mouse_exited_item(item: ESCItem) -> void:
func _on_mouse_left_clicked_item(item: ESCItem, event: InputEvent) -> void:
if input_mode == INPUT_ALL:
if hover_stack.empty() or hover_stack.back() == item:
escoria.logger.info("Item left clicked", [item.global_id, event])
escoria.logger.info(
self,
"Item %s left clicked with event %s." % [item.global_id, event]
)
hotspot_focused = item.global_id
escoria.main.current_scene.game.left_click_on_item(
item.global_id,
@@ -339,7 +362,10 @@ func _on_mouse_left_double_clicked_item(
event: InputEvent
) -> void:
if input_mode == INPUT_ALL:
escoria.logger.info("Item left double clicked", [item.global_id, event])
escoria.logger.info(
self,
"Item %s left double clicked with event %s." % [item.global_id, event]
)
hotspot_focused = item.global_id
escoria.main.current_scene.game.left_double_click_on_item(
item.global_id,
@@ -355,7 +381,10 @@ func _on_mouse_left_double_clicked_item(
# - event: The input event from the click
func _on_mouse_right_clicked_item(item: ESCItem, event: InputEvent) -> void:
if input_mode == INPUT_ALL:
escoria.logger.info("Item right clicked", [item.global_id, event])
escoria.logger.info(
self,
"Item %s right clicked with event %s." % [item.global_id, event]
)
hotspot_focused = item.global_id
escoria.main.current_scene.game.right_click_on_item(
item.global_id,

View File

@@ -0,0 +1,195 @@
class ESCLoggerBase:
# Perform emergency savegame
signal perform_emergency_savegame
# Valid log levels
enum { LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_TRACE }
# Log file format
const LOG_FILE_FORMAT: String = "log_%s_%s.log"
# A map of log level names to log level ints
var _level_map: Dictionary = {
"ERROR": LOG_ERROR,
"WARNING": LOG_WARNING,
"INFO": LOG_INFO,
"DEBUG": LOG_DEBUG,
"TRACE": LOG_TRACE,
}
# Configured log level
var _log_level: int
# Constructor
func _init():
_log_level = _level_map[ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.LOG_LEVEL
).to_upper()]
func formatted_message(context: String, msg: String, letter: String) -> String:
return "ESC ({0}) {1} {2}: {3}".format([_formatted_date(), letter, context, msg])
func trace(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
print(formatted_message(context, msg, "T"))
# Debug log
func debug(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
print(formatted_message(context, msg, "D"))
func info(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
print(formatted_message(context, msg, "I"))
# Warning log
func warn(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
print(formatted_message(context, msg, "W"))
push_warning(formatted_message(context, msg, "W"))
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.TERMINATE_ON_WARNINGS
):
assert(false)
escoria.get_tree().quit()
# Error log
func error(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
printerr(formatted_message(context, msg, "E"))
push_error(formatted_message(context, msg, "E"))
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.TERMINATE_ON_ERRORS
):
assert(false)
escoria.get_tree().quit()
func get_log_level() -> int:
return _log_level
func _formatted_date():
var info = OS.get_datetime()
info["year"] = "%04d" % info["year"]
info["month"] = "%02d" % info["month"]
info["day"] = "%02d" % info["day"]
info["hour"] = "%02d" % info["hour"]
info["minute"] = "%02d" % info["minute"]
info["second"] = "%02d" % info["second"]
return "{year}-{month}-{day}T{hour}:{minute}:{second}".format(info)
# A logger that logs to the terminal and to a log file.
class ESCLoggerFile extends ESCLoggerBase:
# Log file handler
var log_file: File
# Constructor
func _init():
# Open logfile in write mode
log_file = File.new()
# This is left alone as this constructor is called from escoria.gd's own
# constructor
var log_file_path = ProjectSettings.get_setting(
ESCProjectSettingsManager.LOG_FILE_PATH
)
var date = OS.get_datetime()
log_file_path = log_file_path.plus_file(LOG_FILE_FORMAT % [
str(date["year"]) + str(date["month"]) + str(date["day"]),
str(date["hour"]) + str(date["minute"]) + str(date["second"])
])
log_file.open(
log_file_path,
File.WRITE
)
func trace(owner: Object, msg: String):
if _log_level >= LOG_TRACE:
_log_to_file(owner, msg, "T")
.trace(owner, msg)
# Debug log
func debug(owner: Object, msg: String):
if _log_level >= LOG_DEBUG:
_log_to_file(owner, msg, "D")
.debug(owner, msg)
func info(owner: Object, msg: String):
if _log_level >= LOG_INFO:
_log_to_file(owner, msg, "I")
.info(owner, msg)
# Warning log
func warn(owner: Object, msg: String):
if _log_level >= LOG_WARNING:
_log_to_file(owner, msg, "W")
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.TERMINATE_ON_WARNINGS
):
_log_stack_trace_to_file(owner)
print_stack()
close_logs()
.warn(owner, msg)
# Error log
func error(owner: Object, msg: String):
if _log_level >= LOG_ERROR:
_log_to_file(owner, msg, "E")
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.TERMINATE_ON_ERRORS
):
_log_stack_trace_to_file(owner)
print_stack()
close_logs()
.error(owner, msg)
# Close the log file cleanly
func close_logs():
print("Closing logs peacefully.")
_log_line_to_file("Closing logs peacefully.")
log_file.close()
func _log_to_file(owner: Object, msg: String, letter: String):
if log_file.is_open():
var context = ""
if owner != null:
context = owner.get_script().resource_path.get_file()
log_file.store_string(formatted_message(context, msg, letter) + "\n")
func _log_line_to_file(msg: String):
if log_file.is_open():
log_file.store_string(msg + "\n")
func _log_stack_trace_to_file(owner: Object):
var frame_number = 0
for stack in get_stack().slice(2, get_stack().size()):
_log_line_to_file(
"Frame %s - %s:%s in function '%s'" % [
str(frame_number),
stack["source"],
stack["line"],
stack["function"],
]
)
frame_number += 1
# A simple logger that logs to terminal using debug() function
class ESCLoggerVerbose extends ESCLoggerBase:
func _init():
pass
func debug(owner: Object, msg: String):
var context = owner.get_script().resource_path.get_file()
print(context, ": ", msg)

View File

@@ -1,5 +1,5 @@
# Registers and allows access to Escoria-specific project settings.
extends Node
extends Resource
class_name ESCProjectSettingsManager
@@ -75,8 +75,7 @@ const MAX_TIME_TO_DISAPPEAR = "%s/%s/max_time_to_disappear" % [_ESCORIA_SETTINGS
# - name: Name of the project setting
# - default: Default value
# - info: Property info for the setting
func register_setting(name: String, default, info: Dictionary) -> void:
if not ProjectSettings.has_setting(name):
static func register_setting(name: String, default, info: Dictionary) -> void:
ProjectSettings.set_setting(
name,
default
@@ -92,11 +91,10 @@ func register_setting(name: String, default, info: Dictionary) -> void:
# - key: Project setting name.
#
# *Returns* the value of the project setting located with key.
func get_setting(key: String):
static func get_setting(key: String):
if not ProjectSettings.has_setting(key):
escoria.logger.report_errors("project_settings_manager.gd",
["Parameter %s is not set!" % key]
)
push_error("Parameter %s is not set!" % key)
assert(false)
return ProjectSettings.get_setting(key)
@@ -107,7 +105,7 @@ func get_setting(key: String):
#
# - key: Project setting name.
# - value: Project setting value.
func set_setting(key: String, value) -> void:
static func set_setting(key: String, value) -> void:
ProjectSettings.set_setting(key, value)
@@ -118,5 +116,5 @@ func set_setting(key: String, value) -> void:
# - key: Project setting name.
#
# *Returns* true iff the project setting exists.
func has_setting(key: String) -> bool:
static func has_setting(key: String) -> bool:
return ProjectSettings.has_setting(key)

View File

@@ -3,166 +3,98 @@ tool
extends Node
class_name Escoria
# Signal sent when Escoria is paused
signal paused
# Signal sent when Escoria is resumed from pause
signal resumed
# Signal sent when pause menu has to be displayed
signal request_pause_menu
# Current game state
# * DEFAULT: Common game function
# * DIALOG: Game is playing a dialog
# * WAIT: Game is waiting
enum GAME_STATE {
DEFAULT,
DIALOG,
WAIT
}
# Name of the Escoria core plugin
const ESCORIA_CORE_PLUGIN_NAME: String = "escoria-core"
# Audio bus indices.
const BUS_MASTER = "Master"
const BUS_SFX = "SFX"
const BUS_MUSIC = "Music"
const BUS_SPEECH = "Speech"
const CAMERA_SCENE_PATH = "res://addons/escoria-core/game/scenes/camera_player/camera.tscn"
# Logger used
var logger: ESCLogger
# Several utilities
var utils: ESCUtils
# The inventory manager instance
var inventory_manager: ESCInventoryManager
# The action manager instance
var action_manager: ESCActionManager
# ESC compiler instance
var esc_compiler: ESCCompiler
# ESC Event manager instance
var event_manager: ESCEventManager
# ESC globals registry instance
var globals_manager: ESCGlobalsManager
# ESC room manager instance
var room_manager: ESCRoomManager
# ESC object manager instance
var object_manager: ESCObjectManager
# ESC project settings manager instance
var project_settings_manager: ESCProjectSettingsManager
# ESC command registry instance
var command_registry: ESCCommandRegistry
# Resource cache handler
var resource_cache: ESCResourceCache
# Terrain of the current room
var room_terrain
# Dialog player instantiator. This instance is called directly for dialogs.
var dialog_player: ESCDialogPlayer
# Inventory scene
var inventory
# These are settings that the player can affect and save/load later
var settings: ESCSaveSettings
# The game resolution
onready var game_size = get_viewport().size
# The main scene
onready var main = $main
# The current state of the game
onready var current_state = GAME_STATE.DEFAULT
# The escoria inputs manager
var inputs_manager: ESCInputsManager
# Savegames and settings manager
var save_manager: ESCSaveManager
# The game scene loaded
var game_scene: ESCGame
# The main player camera
var player_camera: ESCCamera
# The compiled start script loaded from ProjectSettings
# escoria/main/game_start_script
var start_script: ESCScript
# Initialize various objects
func _init():
self.logger = ESCLogger.new()
self.utils = ESCUtils.new()
self.inventory_manager = ESCInventoryManager.new()
self.action_manager = ESCActionManager.new()
self.event_manager = ESCEventManager.new()
self.globals_manager = ESCGlobalsManager.new()
self.add_child(self.event_manager)
self.object_manager = ESCObjectManager.new()
self.command_registry = ESCCommandRegistry.new()
self.esc_compiler = ESCCompiler.new()
self.resource_cache = ESCResourceCache.new()
self.resource_cache.start()
self.save_manager = ESCSaveManager.new()
self.inputs_manager = ESCInputsManager.new()
self.room_manager = ESCRoomManager.new()
self.project_settings_manager = ESCProjectSettingsManager.new()
escoria.inventory_manager = ESCInventoryManager.new()
escoria.action_manager = ESCActionManager.new()
escoria.event_manager = ESCEventManager.new()
escoria.globals_manager = ESCGlobalsManager.new()
add_child(escoria.event_manager)
escoria.object_manager = ESCObjectManager.new()
escoria.command_registry = ESCCommandRegistry.new()
escoria.resource_cache = ESCResourceCache.new()
escoria.resource_cache.start()
escoria.save_manager = ESCSaveManager.new()
escoria.inputs_manager = ESCInputsManager.new()
escoria.settings = ESCSaveSettings.new()
settings = ESCSaveSettings.new()
if self.project_settings_manager.get_setting(self.project_settings_manager.GAME_SCENE) == "":
logger.report_errors("escoria.gd",
["Project setting '%s' is not set!" % self.project_settings_manager.GAME_SCENE]
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_SCENE
).empty():
escoria.logger.error(
self,
"Project setting '%s' is not set!" % ESCProjectSettingsManager.GAME_SCENE
)
else:
game_scene = resource_cache.get_resource(
self.project_settings_manager.get_setting(self.project_settings_manager.GAME_SCENE)
escoria.game_scene = escoria.resource_cache.get_resource(
ESCProjectSettingsManager.get_setting(ESCProjectSettingsManager.GAME_SCENE)
).instance()
print("ESC {0}".format([get_script().get_path()]))
# Load settings
func _ready():
_handle_direct_scene_run()
settings = save_manager.load_settings()
apply_settings(settings)
room_manager.register_reserved_globals()
inputs_manager.register_core()
if self.project_settings_manager.get_setting(self.project_settings_manager.GAME_START_SCRIPT).empty():
logger.report_errors("escoria.gd",
[
"Project setting '%s' is not set!" % self.project_settings_manager.GAME_START_SCRIPT
])
start_script = self.esc_compiler.load_esc_file(
self.project_settings_manager.get_setting(self.project_settings_manager.GAME_START_SCRIPT)
escoria.settings = escoria.save_manager.load_settings()
escoria.apply_settings(escoria.settings)
escoria.room_manager.register_reserved_globals()
escoria.inputs_manager.register_core()
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_START_SCRIPT
).empty():
escoria.logger.error(
self,
"Project setting '%s' is not set!"
% ESCProjectSettingsManager.GAME_START_SCRIPT
)
escoria.start_script = escoria.esc_compiler.load_esc_file(
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.GAME_START_SCRIPT
)
)
escoria.main = main
_perform_plugins_checks()
# Verifies that the game is configured with required plugin(s).
# If a required plugin is missing (or disabled) we stop immediately.
func _perform_plugins_checks():
if ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS
).empty():
escoria.logger.error(
self,
"No dialog manager configured. Please add a dialog manager plugin."
)
func _notification(what):
# Manage notifications received from OS
#
# #### Parameters
# - what: the notification constant received (usually defined in MainLoop)
func _notification(what: int):
match what:
MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
escoria.logger.close_logs()
escoria.is_quitting = true
get_tree().quit()
MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST:
escoria.logger.close_logs()
escoria.is_quitting = true
get_tree().quit()
@@ -173,69 +105,22 @@ func init():
# Don't show the UI until we're ready in order to avoid a sometimes-noticeable
# blink. The UI will be "shown" later via a visibility update to the first room.
escoria.game_scene.escoria_hide_ui()
run_event_from_script(start_script, self.event_manager.EVENT_INIT)
# Called by Main menu "start new game"
func new_game():
run_event_from_script(start_script, self.event_manager.EVENT_NEW_GAME)
# Apply the loaded settings
#
# #### Parameters
#
# * p_settings: Loaded settings
func apply_settings(p_settings: ESCSaveSettings) -> void:
if not Engine.is_editor_hint():
logger.info("******* settings loaded")
if p_settings != null:
settings = p_settings
else:
settings = ESCSaveSettings.new()
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_MASTER),
linear2db(settings.master_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_SFX),
linear2db(settings.sfx_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_MUSIC),
linear2db(settings.music_volume)
)
AudioServer.set_bus_volume_db(
AudioServer.get_bus_index(BUS_SPEECH),
linear2db(settings.speech_volume)
)
TranslationServer.set_locale(settings.text_lang)
game_scene.apply_custom_settings(settings.custom_settings)
run_event_from_script(escoria.start_script, escoria.event_manager.EVENT_INIT)
pass
# Input function to manage specific input keys
func _input(event):
if InputMap.has_action(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT) \
and event.is_action_pressed(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT):
escoria.main.get_node("layers/debug_layer/esc_prompt_popup").popup()
# Pauses or unpause the game
#
# #### Parameters
# - p_paused: if true, pauses the game. If false, unpauses the game.
func set_game_paused(p_paused: bool):
if p_paused:
emit_signal("paused")
else:
emit_signal("resumed")
# - event: the input event to manage.
func _input(event: InputEvent):
if InputMap.has_action(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT) \
and event.is_action_pressed(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT):
main.get_node("layers/debug_layer/esc_prompt_popup").popup()
var scene_tree = get_tree()
if is_instance_valid(scene_tree):
scene_tree.paused = p_paused
if event.is_action_pressed("ui_cancel"):
emit_signal("request_pause_menu")
pass
# Runs the event "event_name" from the "script" ESC script.
@@ -246,121 +131,27 @@ func set_game_paused(p_paused: bool):
# - event_name: Name of the event to run
func run_event_from_script(script: ESCScript, event_name: String):
if script == null:
logger.report_errors(
"escoria.gd:run_event_from_script()",
["Requested action %s on unloaded script %s" % [event_name, script],
"Please load the ESC script using esc_compiler.load_esc_file()."]
escoria.logger.error(
self,
"Requested action %s on unloaded script %s." % [event_name, script] +
"Please load the ESC script using esc_compiler.load_esc_file()."
)
event_manager.queue_event(script.events[event_name])
var rc = yield(event_manager, "event_finished")
escoria.event_manager.queue_event(script.events[event_name])
var rc = yield(escoria.event_manager, "event_finished")
while rc[1] != event_name:
rc = yield(event_manager, "event_finished")
rc = yield(escoria.event_manager, "event_finished")
if rc[0] != ESCExecution.RC_OK:
self.logger.report_errors(
"Start event of the start script returned unsuccessful: %d" % rc[0],
[]
escoria.logger.error(
self,
"Start event of the start script returned unsuccessful: %d." % rc[0]
)
return
# Register a user interface. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - game_scene: Path to the game scene extending ESCGame
func register_ui(game_scene: String):
var game_scene_setting_value = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_SCENE
)
if not game_scene_setting_value in [
"",
game_scene
]:
logger.report_errors(
"escoria.gd:register_ui()",
[
"Can't register user interface because %s is registered" % \
game_scene_setting_value
]
)
escoria.project_settings_manager.set_setting(
escoria.project_settings_manager.GAME_SCENE,
game_scene
)
# Deregister a user interface
#
# #### Parameters
# - game_scene: Path to the game scene extending ESCGame
func deregister_ui(game_scene: String):
var game_scene_setting_value = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.GAME_SCENE
)
if game_scene_setting_value != game_scene:
logger.report_errors(
"escoria.gd:deregister_ui()",
[
(
"Can't deregister user interface %s because it " +
"is not registered."
) % game_scene_setting_value
]
)
escoria.project_settings_manager.set_setting(
escoria.project_settings_manager.GAME_SCENE,
""
)
# Register a dialog manager addon. This should be called in a deferred way
# from the addon's _enter_tree.
#
# #### Parameters
# - manager_class: Path to the manager class script
func register_dialog_manager(manager_class: String):
var dialog_managers: Array = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
)
if manager_class in dialog_managers:
return
dialog_managers.push_back(manager_class)
escoria.project_settings_manager.set_setting(
escoria.project_settings_manager.DIALOG_MANAGERS,
dialog_managers
)
# Deregister a dialog manager addon
#
# #### Parameters
# - manager_class: Path to the manager class script
func deregister_dialog_manager(manager_class: String):
var dialog_managers: Array = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
)
if not manager_class in dialog_managers:
logger.report_warnings(
"escoria.gd:deregister_dialog_manager()",
[
"Dialog manager %s is not registered" % manager_class
]
)
return
dialog_managers.erase(manager_class)
escoria.project_settings_manager.set_setting(
escoria.project_settings_manager.DIALOG_MANAGERS,
dialog_managers
)
# Called from escoria autoload to start a new game.
func new_game():
run_event_from_script(escoria.start_script, escoria.event_manager.EVENT_NEW_GAME)
# Function called to quit the game.
@@ -370,19 +161,8 @@ func quit():
# Handle anything necessary if the game started a scene directly.
func _handle_direct_scene_run() -> void:
var current_scene_root: Node = get_tree().get_current_scene()
if current_scene_root == null:
# there's no 'current scene'
# e.g. you're opening escoria.tscn from the editor
return
if current_scene_root.filename == ProjectSettings.get_setting('application/run/main_scene'):
# This is a normal, full-game run, so there's nothing to do.
return
if current_scene_root is ESCRoom:
escoria.object_manager.set_current_room(current_scene_root)
if escoria.is_direct_room_run:
escoria.object_manager.set_current_room(get_tree().get_current_scene())
# Used by game.gd to determine whether the game scene is ready to take inputs
@@ -393,5 +173,5 @@ func _handle_direct_scene_run() -> void:
# *Returns*
# true if game scene is ready for inputs
func is_ready_for_inputs() -> bool:
return escoria.main.current_scene and escoria.main.current_scene.game \
and escoria.main.current_scene.game.room_ready_for_inputs
return main.current_scene and main.current_scene.game \
and main.current_scene.game.room_ready_for_inputs

View File

@@ -3,7 +3,7 @@
[ext_resource path="res://addons/escoria-core/game/main.tscn" type="PackedScene" id=2]
[ext_resource path="res://addons/escoria-core/game/escoria.gd" type="Script" id=3]
[node name="escoria" type="Node"]
[node name="escoria_scene" type="Node"]
pause_mode = 2
script = ExtResource( 3 )

View File

@@ -31,6 +31,10 @@ func _ready() -> void:
$layers/wait_timer.connect("timeout", self, "_on_wait_finished")
func _exit_tree():
$layers/curtain.remove_child(scene_transition)
scene_transition.queue_free()
# Set current scene
#
# #### Parameters
@@ -38,7 +42,10 @@ func _ready() -> void:
# - p_scene: Scene to set
func set_scene(p_scene: Node) -> void:
if !p_scene:
escoria.logger.report_errors("main", ["Trying to set empty scene"])
escoria.logger.error(
self,
"Can't change to an empty scene. Please specify the scene name."
)
previous_scene = current_scene
@@ -130,14 +137,12 @@ func set_camera_limits(camera_limit_id: int = 0, scene: Node = current_scene) ->
var limits = {}
var last_available_camera_limit = scene.camera_limits.size() - 1
if camera_limit_id > last_available_camera_limit:
escoria.logger.report_errors(
"main.gd:set_camera_limits()",
[
escoria.logger.error(
self,
"Camera limit %d requested. Last available camera limit is %d." % [
camera_limit_id,
last_available_camera_limit
]
]
)
var scene_camera_limits = scene.camera_limits[camera_limit_id]
if scene_camera_limits.size.x == 0 and scene_camera_limits.size.y == 0:
@@ -151,15 +156,16 @@ func set_camera_limits(camera_limit_id: int = 0, scene: Node = current_scene) ->
# to stick centered on the background
if area.size.x == 0 or area.size.y == 0 \
or area.size < get_viewport().size:
escoria.logger.report_warnings(
"main.gd:set_camera_limits()",
[
"No limit area! Using viewport."
]
escoria.logger.warn(
self,
"Defined camera is smaller than the viewport. Using viewport size."
)
area.size = get_viewport().size
escoria.logger.info("Setting camera limits from scene ", [area])
escoria.logger.info(
self,
"Setting camera limits from scene " + area
)
limits = ESCCameraLimits.new(
area.position.x,
area.position.x + area.size.x,
@@ -176,8 +182,8 @@ func set_camera_limits(camera_limit_id: int = 0, scene: Node = current_scene) ->
scene_camera_limits.size.y
)
escoria.logger.info(
"Setting camera limits from parameter ",
[scene_camera_limits]
self,
"Setting camera limits using configured parameters " + str(scene_camera_limits)
)
escoria.object_manager.get_object(

View File

@@ -14,8 +14,6 @@ script = ExtResource( 1 )
[node name="curtain" type="CanvasLayer" parent="layers"]
layer = 20
[node name="menu" type="CanvasLayer" parent="layers"]
[node name="wait_timer" type="Timer" parent="layers"]
[node name="debug_layer" type="CanvasLayer" parent="layers"]

View File

@@ -1,9 +1,17 @@
# Main_scene is the entry point for Godot Engine.
# This scene sets up the main menu scene to load.
extends Node
class_name ESCMain
var escoria_node: Escoria
# Start the main menu
func _ready():
escoria.init()
escoria.logger.info(self, "Escoria starts...")
escoria_node = preload("res://addons/escoria-core/game/escoria.tscn").instance()
add_child(escoria_node)
if not escoria.is_direct_room_run:
escoria_node.init()

View File

@@ -23,6 +23,12 @@ func _ready():
_tween.connect("tween_all_completed", self, "_target_reached")
func _exit_tree():
remove_child(_tween)
if is_instance_valid(_tween):
_tween.queue_free()
# Update the position if the followed target is moving
func _process(_delta):
if is_instance_valid(_follow_target) and not _tween.is_active() and _follow_target.has_moved():
@@ -103,21 +109,20 @@ func set_target(p_target, p_time : float = 0.0):
_resolve_target_and_zoom(p_target)
escoria.logger.info(
"Current camera position = %s " % str(self.global_position)
self,
"Current camera position = %s." % str(self.global_position)
)
if p_time == 0.0:
self.global_position = _target
else:
if _tween.is_active():
escoria.logger.report_warnings(
"esc_camera.gd:set_target()",
[
"Tween is still active: %f/%f" % [
escoria.logger.warn(
self,
"Tween is still active: %f seconds of %f completed." % [
_tween.tell(),
_tween.get_runtime()
]
]
)
_tween.emit_signal("tween_completed")
@@ -140,9 +145,9 @@ func set_target(p_target, p_time : float = 0.0):
# - p_time: Number of seconds for the camera to reach the zoom level
func set_camera_zoom(p_zoom_level: float, p_time: float):
if p_zoom_level <= 0.0:
escoria.logger.report_errors(
"esc_camera.gd:set_camera_zoom()",
["Tried to set negative or zero zoom level"]
escoria.logger.error(
self,
"Tried to set negative or zero zoom level."
)
_zoom_target = Vector2(1, 1) * p_zoom_level
@@ -151,14 +156,12 @@ func set_camera_zoom(p_zoom_level: float, p_time: float):
self.zoom = _zoom_target
else:
if _tween.is_active():
escoria.logger.report_warnings(
"esc_camera.gd:set_camera_zoom()",
[
escoria.logger.warn(
self,
"Tween is still active: %f/%f" % [
_tween.tell(),
_tween.get_runtime()
]
]
)
_tween.emit_signal("tween_completed")
@@ -199,14 +202,12 @@ func push(p_target, p_time: float = 0.0, p_type: int = 0):
self.zoom = _zoom_target
else:
if _tween.is_active():
escoria.logger.report_warnings(
"esc_camera.gd:push()",
[
"Tween is still active: %f/%f" % [
escoria.logger.warn(
self,
"Tween is still active: %f seconds of %f completed." % [
_tween.tell(),
_tween.get_runtime()
]
]
)
_tween.emit_signal("tween_completed", null, null)
@@ -251,14 +252,12 @@ func shift(p_target: Vector2, p_time: float, p_type: int):
_target = new_pos
if _tween.is_active():
escoria.logger.report_warnings(
"esc_camera.gd:set_camera_zoom()",
[
"Tween is still active: %f/%f" % [
escoria.logger.warn(
self,
"Tween is still active: %f seconds of %f completed." % [
_tween.tell(),
_tween.get_runtime()
]
]
)
_tween.emit_signal("tween_completed")
@@ -276,6 +275,3 @@ func shift(p_target: Vector2, p_time: float, p_type: int):
func _target_reached():
_tween.stop_all()

View File

@@ -1,5 +1,5 @@
# Describes a bounding box that limits the camera movement in the scene
extends Object
extends Reference
class_name ESCCameraLimits

View File

@@ -26,9 +26,15 @@ func set_dialog(new_dialog: ESCDialog) -> void:
# Show the dialog chooser UI
func show_chooser() -> void:
escoria.logger.error("Dialog chooser did not implement the show method.")
escoria.logger.error(
self,
"Dialog chooser does not implement the show method."
)
# Hide the dialog chooser UI
func hide_chooser() -> void:
escoria.logger.error("Dialog chooser did not implement the hide method.")
escoria.logger.error(
self,
"Dialog chooser does not implement the hide method."
)

View File

@@ -62,8 +62,8 @@ func _input(event):
# *Returns* The path to the matching voice file
func _get_voice_file(key: String, start: String = "") -> String:
if start == "":
start = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.SPEECH_FOLDER
start = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.SPEECH_FOLDER
)
var _dir = Directory.new()
if _dir.open(start) == OK:
@@ -80,8 +80,8 @@ func _get_voice_file(key: String, start: String = "") -> String:
else:
if file_name == "%s.%s.import" % [
key,
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.SPEECH_EXTENSION
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.SPEECH_EXTENSION
)
]:
return start.plus_file(file_name.trim_suffix(".import"))
@@ -98,12 +98,12 @@ func _get_voice_file(key: String, start: String = "") -> String:
# - text: Text to say
func say(character: String, type: String, text: String) -> void:
if type == "":
type = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_DIALOG_TYPE
type = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE
)
is_speaking = true
for _manager_class in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
for _manager_class in ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS
):
if ResourceLoader.exists(_manager_class):
var _manager: ESCDialogManager = load(_manager_class).new()
@@ -113,22 +113,18 @@ func say(character: String, type: String, text: String) -> void:
_dialog_manager = null
if _dialog_manager == null:
escoria.logger.report_errors(
"esc_dialog_player.gd:say",
[
"No dialog manager supports the type %s" % type
]
escoria.logger.error(
self,
"No dialog manager called %s configured." % type
)
_dialog_manager.connect("say_finished", self, "_on_say_finished", [], CONNECT_ONESHOT)
var matches = _keytext_regex.search(text)
if not matches:
escoria.logger.report_errors(
"esc_dialog_player.gd:say",
[
"Unexpected text encountered %s" % text
]
escoria.logger.error(
self,
"Unexpected text encountered : %s." % text
)
var key = matches.get_string("key")
if matches.get_string("key") != "":
@@ -136,11 +132,9 @@ func say(character: String, type: String, text: String) -> void:
matches.get_string("key")
)
if _speech_resource == "":
escoria.logger.report_warnings(
"esc_dialog_player.gd:say",
[
escoria.logger.warn(
self,
"Unable to find voice file with key '%s'." % matches.get_string("key")
]
)
else:
(
@@ -153,11 +147,9 @@ func say(character: String, type: String, text: String) -> void:
# Only update the text if the translated text was found; otherwise, raise
# a warning and use the original, untranslated text.
if translated_text == matches.get_string("key"):
escoria.logger.report_warnings(
"esc_dialog_player.gd:say",
[
escoria.logger.warn(
self,
"Unable to find translation key '%s'. Using untranslated text." % matches.get_string("key")
]
)
text = matches.get_string("text")
else:
@@ -165,8 +157,8 @@ func say(character: String, type: String, text: String) -> void:
else:
text = matches.get_string("text")
_dialog_manager.say(self, character, text, type)
_dialog_manager.say(self, character, text, type)
# Handles the end of a say function after it has emitted say_finished.
func _on_say_finished():
@@ -189,15 +181,15 @@ func speedup() -> void:
# - dialog: The dialog to start
func start_dialog_choices(dialog: ESCDialog, type: String = "simple"):
if dialog.options.empty():
escoria.logger.report_errors(
"esc_dialog_player.gd:start_dialog_choices()",
["Received answers array was empty."]
escoria.logger.error(
self,
"Received dialog options array was empty."
)
var _dialog_chooser_ui: ESCDialogManager = null
for _manager_class in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DIALOG_MANAGERS
for _manager_class in ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS
):
if ResourceLoader.exists(_manager_class):
var _manager: ESCDialogManager = load(_manager_class).new()
@@ -205,11 +197,9 @@ func start_dialog_choices(dialog: ESCDialog, type: String = "simple"):
_dialog_chooser_ui = _manager
if _dialog_chooser_ui == null:
escoria.logger.report_errors(
"esc_dialog_player.gd: Unknown chooser type",
[
"No dialog manager supports the chooser type %s" % type
]
escoria.logger.error(
self,
"No dialog manager supports the chooser type %s." % type
)
_dialog_chooser_ui.choose(self, dialog)

View File

@@ -17,9 +17,9 @@ var items_ids_in_inventory: Dictionary = {}
# listen when a global has changed
func _ready():
if inventory_ui_container == null or inventory_ui_container.is_empty():
escoria.logger.report_errors(
self.get_path(),
["Items container is empty."]
escoria.logger.error(
self,
"Inventory items container is empty."
)
return
@@ -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" % [
escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.ITEMS_AUTOREGISTER_PATH
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.ITEMS_AUTOREGISTER_PATH
).trim_suffix("/"),
item_id
]
@@ -58,10 +58,20 @@ func add_new_item_by_id(item_id: String) -> void:
true
)
else:
escoria.logger.report_errors(
"inventory_ui.gd:add_new_item_by_id()",
[
"Item global id '%s' does not exist." % item_id
escoria.logger.error(
self,
(
"Item global id '%s' is not registered because the item's scene file was not found.\n"
+ "Attempted scene file path: %s.\n"
+ "Please ensure that the '%s' project setting points at **your inventory items folder** (current is: \"%s\")."
)
% [
item_id,
inventory_file,
ESCProjectSettingsManager.ITEMS_AUTOREGISTER_PATH,
ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.ITEMS_AUTOREGISTER_PATH
)
]
)
@@ -90,7 +100,10 @@ func add_new_item_by_id(item_id: String) -> void:
# remove item fromInventory UI using its id set in its scene
func remove_item_by_id(item_id: String) -> void:
if items_ids_in_inventory.has(item_id):
var item_inventory_button = items_ids_in_inventory[item_id]
var item_inventory = items_ids_in_inventory[item_id]
var item_inventory_button = get_node(
inventory_ui_container
).get_inventory_button(item_inventory)
if item_inventory_button.is_connected(
"mouse_left_inventory_item",
@@ -143,7 +156,7 @@ func remove_item_by_id(item_id: String) -> void:
"_on_mouse_exited_inventory_item"
)
get_node(inventory_ui_container).remove_item(item_inventory_button)
get_node(inventory_ui_container).remove_item(item_inventory)
items_ids_in_inventory.erase(item_id)
@@ -158,10 +171,7 @@ func _on_escoria_global_changed(global: String, old_value, new_value) -> void:
else:
remove_item_by_id(item[0])
else:
escoria.logger.report_errors(
"inventory_ui.gd:_on_escoria_global_changed()",
[
"Global must contain only one item name.",
"(received: %s)" % global
]
escoria.logger.error(
self,
"Global must contain only one item name (received: %s)." % global
)

View File

@@ -44,9 +44,9 @@ 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 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
if ESCProjectSettingsManager.has_setting(ESCProjectSettingsManager.MUSIC_VOLUME):
stream.volume_db = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.MUSIC_VOLUME
)
stream.play()

View File

@@ -43,9 +43,9 @@ func set_state(p_state: String, p_force: bool = false):
resource.loop_mode = AudioStreamSample.LOOP_DISABLED
elif "loop" in resource:
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
if ESCProjectSettingsManager.has_setting(ESCProjectSettingsManager.SFX_VOLUME):
stream.volume_db = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.SFX_VOLUME
)
stream.play()

View File

@@ -67,14 +67,14 @@ func transition(
_tween.connect("tween_all_completed", self, "_on_tween_completed")
if transition_name.empty():
transition_name = escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.DEFAULT_TRANSITION
transition_name = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION
)
if not has_transition(transition_name):
escoria.logger.report_errors(
"transition: Transition %s not found" % transition_name,
[]
escoria.logger.error(
self,
"transition: Transition %s not found" % transition_name
)
# If this is an "instant" transition, we need to set the alpha of the base
@@ -122,8 +122,8 @@ 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:
for directory in escoria.project_settings_manager.get_setting(
escoria.project_settings_manager.TRANSITION_PATHS
for directory in ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.TRANSITION_PATHS
):
if ResourceLoader.exists(directory.plus_file("%s.material" % name)):
return directory.plus_file("%s.material" % name)
@@ -154,5 +154,5 @@ func _on_tween_completed():
if not _was_canceled:
_tween.stop_all()
_tween.remove_all()
escoria.logger.debug("Transition %s done." % str(transition_id))
escoria.logger.debug(self, "Transition %s done." % str(transition_id))
emit_signal("transition_done", transition_id)

View File

@@ -2,41 +2,28 @@
tool
extends EditorPlugin
# The path to node 'escoria'.
const ESCORIA: String = "/root/escoria"
# Reference to "escoria" singleton instance.
var escoria_instance: Node = null
# Returns the 'escoria' singleton/autoload.
#
# *Returns*
# The escoria singleton.
func _get_escoria():
if not is_instance_valid(escoria_instance):
escoria_instance = get_node(ESCORIA)
if not is_instance_valid(escoria_instance):
printerr(
"Escoria could not load the 'escoria' singleton/autoload.\n",
"Please try to disable and re-enable 'Escoria' plugin."
)
return escoria_instance
# The warning popup displayed on escoria-core enabling.
var popup_info: AcceptDialog
# Virtual function called when plugin is enabled.
func _enable_plugin():
func enable_plugin():
add_autoload_singleton(
"escoria",
"res://addons/escoria-core/game/escoria.tscn"
"res://addons/escoria-core/game/esc_autoload.gd"
)
# Prepare settings
set_escoria_main_settings()
set_escoria_debug_settings()
set_escoria_ui_settings()
set_escoria_sound_settings()
set_escoria_platform_settings()
# Add input actions in InputMap
InputMap.add_action(_get_escoria().inputs_manager.SWITCH_ACTION_VERB)
InputMap.add_action(_get_escoria().inputs_manager.ESC_SHOW_DEBUG_PROMPT)
# if not InputMap.has_action(ESCInputsManager.SWITCH_ACTION_VERB):
# InputMap.add_action(ESCInputsManager.SWITCH_ACTION_VERB)
# if not InputMap.has_action(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT):
# InputMap.add_action(ESCInputsManager.ESC_SHOW_DEBUG_PROMPT)
# Define standard settings
ProjectSettings.set_setting(
@@ -49,92 +36,103 @@ func _enable_plugin():
"res://addons/escoria-core/default_bus_layout.tres"
)
popup_info = AcceptDialog.new()
popup_info.dialog_text = """You enabled escoria-core plugin.
Please ignore error messages in Output console and reload your project using
Godot editor's "Project / Reload Current Project" menu.
"""
popup_info.connect("confirmed", self, "_on_warning_popup_confirmed", [], CONNECT_ONESHOT)
add_child(popup_info)
popup_info.popup_centered()
func _on_warning_popup_confirmed():
popup_info.queue_free()
# Virtual function called when plugin is disabled.
func _disable_plugin():
InputMap.erase_action(_get_escoria().inputs_manager.SWITCH_ACTION_VERB)
InputMap.erase_action(_get_escoria().inputs_manager.ESC_SHOW_DEBUG_PROMPT)
func disable_plugin():
remove_autoload_singleton("escoria")
# if InputMap.has_action(ESCInputsManager.SWITCH_ACTION_VERB):
# InputMap.erase_action(ESCInputsManager.SWITCH_ACTION_VERB)
# if InputMap.has_action(ESCInputsManager.SWITCH_ACTION_VERB):
# InputMap.erase_action(ESCInputsManager.SWITCH_ACTION_VERB)
# Setup Escoria
func _enter_tree():
_enable_plugin()
pass
func _ready():
# Prepare settings
set_escoria_main_settings()
set_escoria_debug_settings()
set_escoria_ui_settings()
set_escoria_sound_settings()
set_escoria_platform_settings()
ProjectSettings.save()
ProjectSettings.save_custom("escoria.godot")
# Prepare the settings in the Escoria UI category
func set_escoria_ui_settings():
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.DEFAULT_DIALOG_TYPE,
register_setting(
ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE,
"",
{
"type": TYPE_STRING
}
)
print("DEFAULT DIALOG TYPE RESET !!!")
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.GAME_SCENE,
register_setting(
ESCProjectSettingsManager.GAME_SCENE,
"",
{
"name": _get_escoria().project_settings_manager.GAME_SCENE,
"name": ESCProjectSettingsManager.GAME_SCENE,
"type": TYPE_STRING,
"hint": PROPERTY_HINT_FILE,
"hint_string": "*.tscn, *.scn"
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.ITEMS_AUTOREGISTER_PATH,
"res://game/items/escitems/",
register_setting(
ESCProjectSettingsManager.ITEMS_AUTOREGISTER_PATH,
"res://game/items/inventory/",
{
"name": _get_escoria().project_settings_manager.ITEMS_AUTOREGISTER_PATH,
"name": ESCProjectSettingsManager.ITEMS_AUTOREGISTER_PATH,
"type": TYPE_STRING,
"hint": PROPERTY_HINT_DIR
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.DEFAULT_TRANSITION,
register_setting(
ESCProjectSettingsManager.DEFAULT_TRANSITION,
"curtain",
{
"name": _get_escoria().project_settings_manager.DEFAULT_TRANSITION,
"name": ESCProjectSettingsManager.DEFAULT_TRANSITION,
"type": TYPE_STRING
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.TRANSITION_PATHS,
register_setting(
ESCProjectSettingsManager.TRANSITION_PATHS,
[
"res://addons/escoria-core/game/scenes/transitions/shaders/"
],
{
"name": _get_escoria().project_settings_manager.TRANSITION_PATHS,
"name": ESCProjectSettingsManager.TRANSITION_PATHS,
"type": TYPE_STRING_ARRAY,
"hint": PROPERTY_HINT_DIR
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.INVENTORY_ITEM_SIZE,
register_setting(
ESCProjectSettingsManager.INVENTORY_ITEM_SIZE,
Vector2(72, 72),
{
"name": _get_escoria().project_settings_manager.INVENTORY_ITEM_SIZE,
"name": ESCProjectSettingsManager.INVENTORY_ITEM_SIZE,
"type": TYPE_VECTOR2
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.DIALOG_MANAGERS,
register_setting(
ESCProjectSettingsManager.DIALOG_MANAGERS,
[],
{
"type": TYPE_STRING_ARRAY
@@ -144,16 +142,16 @@ func set_escoria_ui_settings():
# Prepare the settings in the Escoria main category
func set_escoria_main_settings():
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.GAME_VERSION,
register_setting(
ESCProjectSettingsManager.GAME_VERSION,
"",
{
"type": TYPE_STRING
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.GAME_START_SCRIPT,
register_setting(
ESCProjectSettingsManager.GAME_START_SCRIPT,
"",
{
"type": TYPE_STRING,
@@ -162,16 +160,16 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.FORCE_QUIT,
register_setting(
ESCProjectSettingsManager.FORCE_QUIT,
true,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.COMMAND_DIRECTORIES,
register_setting(
ESCProjectSettingsManager.COMMAND_DIRECTORIES,
[
"res://addons/escoria-core/game/core-scripts/esc/commands"
],
@@ -180,8 +178,8 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.TEXT_LANG,
register_setting(
ESCProjectSettingsManager.TEXT_LANG,
TranslationServer.get_locale(),
{
"type": TYPE_STRING,
@@ -189,8 +187,8 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.VOICE_LANG,
register_setting(
ESCProjectSettingsManager.VOICE_LANG,
TranslationServer.get_locale(),
{
"type": TYPE_STRING,
@@ -198,8 +196,8 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SAVEGAMES_PATH,
register_setting(
ESCProjectSettingsManager.SAVEGAMES_PATH,
"user://saves/",
{
"type": TYPE_STRING,
@@ -207,8 +205,8 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SETTINGS_PATH,
register_setting(
ESCProjectSettingsManager.SETTINGS_PATH,
"user://",
{
"type": TYPE_STRING,
@@ -216,8 +214,8 @@ func set_escoria_main_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.GAME_MIGRATION_PATH,
register_setting(
ESCProjectSettingsManager.GAME_MIGRATION_PATH,
"",
{
"type": TYPE_STRING,
@@ -228,42 +226,42 @@ func set_escoria_main_settings():
# Prepare the settings in the Escoria debug category
func set_escoria_debug_settings():
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.TERMINATE_ON_WARNINGS,
register_setting(
ESCProjectSettingsManager.TERMINATE_ON_WARNINGS,
false,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.TERMINATE_ON_ERRORS,
register_setting(
ESCProjectSettingsManager.TERMINATE_ON_ERRORS,
true,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.DEVELOPMENT_LANG,
register_setting(
ESCProjectSettingsManager.DEVELOPMENT_LANG,
"en",
{
"type": TYPE_STRING
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.LOG_LEVEL,
register_setting(
ESCProjectSettingsManager.LOG_LEVEL,
"ERROR",
{
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM,
"hint_string": "ERROR,WARNING,INFO,DEBUG"
"hint_string": "ERROR,WARNING,INFO,DEBUG,TRACE"
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.LOG_FILE_PATH,
register_setting(
ESCProjectSettingsManager.LOG_FILE_PATH,
"user://",
{
"type": TYPE_STRING,
@@ -271,8 +269,8 @@ func set_escoria_debug_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.LOG_FILE_PATH,
register_setting(
ESCProjectSettingsManager.CRASH_MESSAGE,
"We're sorry, but the game crashed. Please send us the " +
"following files:\n\n%s",
{
@@ -281,16 +279,16 @@ func set_escoria_debug_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.ENABLE_ROOM_SELECTOR,
register_setting(
ESCProjectSettingsManager.ENABLE_ROOM_SELECTOR,
false,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.ROOM_SELECTOR_ROOM_DIR,
register_setting(
ESCProjectSettingsManager.ROOM_SELECTOR_ROOM_DIR,
"",
{
"type": TYPE_STRING,
@@ -301,8 +299,8 @@ func set_escoria_debug_settings():
# Prepare the settings in the Escoria sound settings
func set_escoria_sound_settings():
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.MASTER_VOLUME,
register_setting(
ESCProjectSettingsManager.MASTER_VOLUME,
1,
{
"type": TYPE_REAL,
@@ -311,8 +309,8 @@ func set_escoria_sound_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.MUSIC_VOLUME,
register_setting(
ESCProjectSettingsManager.MUSIC_VOLUME,
1,
{
"type": TYPE_REAL,
@@ -321,8 +319,8 @@ func set_escoria_sound_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SFX_VOLUME,
register_setting(
ESCProjectSettingsManager.SFX_VOLUME,
1,
{
"type": TYPE_REAL,
@@ -331,8 +329,8 @@ func set_escoria_sound_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SPEECH_VOLUME,
register_setting(
ESCProjectSettingsManager.SPEECH_VOLUME,
1,
{
"type": TYPE_REAL,
@@ -341,16 +339,16 @@ func set_escoria_sound_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SPEECH_ENABLED,
1,
register_setting(
ESCProjectSettingsManager.SPEECH_ENABLED,
true,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SPEECH_FOLDER,
register_setting(
ESCProjectSettingsManager.SPEECH_FOLDER,
"res://speech",
{
"type": TYPE_STRING,
@@ -358,8 +356,8 @@ func set_escoria_sound_settings():
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SPEECH_EXTENSION,
register_setting(
ESCProjectSettingsManager.SPEECH_EXTENSION,
"ogg",
{
"type": TYPE_STRING
@@ -374,16 +372,16 @@ func set_escoria_platform_settings():
# scenes.
# If set to true, all generic scenes (UI, inventory, etc) will be loaded
# as any other scene.
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SKIP_CACHE,
register_setting(
ESCProjectSettingsManager.SKIP_CACHE,
false,
{
"type": TYPE_BOOL
}
)
_get_escoria().project_settings_manager.register_setting(
_get_escoria().project_settings_manager.SKIP_CACHE_MOBILE,
register_setting(
ESCProjectSettingsManager.SKIP_CACHE_MOBILE,
true,
{
"type": TYPE_BOOL
@@ -391,7 +389,18 @@ func set_escoria_platform_settings():
)
# Uninstall plugin
func _exit_tree():
_disable_plugin()
# Register a new project setting if it hasn't been defined already
#
# #### Parameters
#
# - name: Name of the project setting
# - default: Default value
# - info: Property info for the setting
static func register_setting(name: String, default, info: Dictionary) -> void:
if not ProjectSettings.has_setting(name):
ProjectSettings.set_setting(
name,
default
)
info.name = name
ProjectSettings.add_property_info(info)

View File

@@ -29,3 +29,16 @@ func remove_item(inventory_item: ESCInventoryItem):
if c is ESCInventoryButton and c.global_id == inventory_item.global_id:
remove_child(c)
c.queue_free()
# Return an Inventory button from the container, using an ESCInventoryItem
#
# #### Parameters
# - inventory_item: Inventory item to return the button node from
func get_inventory_button(inventory_item: ESCInventoryItem) -> ESCInventoryButton:
var inventory_button = null
for c in get_children():
if c.global_id == inventory_item.global_id:
inventory_button = c
break
return inventory_button

View File

@@ -24,6 +24,7 @@ func _ready() -> void:
$VBoxContainer/MarginContainer/options/flags
for child in _flags_container.get_children():
_flags_container.remove_child(child)
child.queue_free()
_loaded_languages = []
@@ -38,7 +39,6 @@ func _ready() -> void:
_flags_container.add_child(_lang)
_lang.connect("gui_input", self, "_on_language_input", [lang])
# Show the options
func show():
backup_settings = escoria.settings.duplicate()

View File

@@ -12,12 +12,12 @@ var _options_paths = []
# Build up the list of rooms
func _ready():
var rooms_folder = ProjectSettings.get_setting(
"escoria/debug/room_selector_room_dir"
var rooms_folder = ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.ROOM_SELECTOR_ROOM_DIR
)
if rooms_folder == "" or \
not ProjectSettings.get_setting(
"escoria/debug/enable_room_selector"
not ESCProjectSettingsManager.get_setting(
ESCProjectSettingsManager.ENABLE_ROOM_SELECTOR
):
return
var dir = Directory.new()
@@ -44,8 +44,10 @@ func _ready():
])
else:
escoria.logger.report_warnings("room_select.gd:_ready()",
["A problem occurred while opening rooms folder."])
escoria.logger.warn(
self,
"A problem occurred while opening rooms folder %s." % str(path)
)
# Switch to the selected room

View File

@@ -2,32 +2,63 @@
tool
extends EditorPlugin
var _escoria
const MANAGER_CLASS="res://addons/escoria-dialog-simple/esc_dialog_simple.gd"
func _init() -> void:
_escoria = preload("res://addons/escoria-core/game/escoria.tscn")\
.instance()
# Register ourselves after setup
func _ready() -> void:
call_deferred("_register")
# Override function to return the plugin name.
func get_plugin_name():
return "escoria-dialog-simple"
# Unregister ourselves
func _exit_tree() -> void:
_escoria.deregister_dialog_manager(MANAGER_CLASS)
func disable_plugin():
print("Disabling plugin Escoria Dialog Simple")
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE,
"",
{}
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.AVATARS_PATH,
null,
{}
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.TEXT_SPEED_PER_CHARACTER,
null,
{}
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.FAST_TEXT_SPEED_PER_CHARACTER,
null,
{}
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.MAX_TIME_TO_DISAPPEAR,
null,
{}
)
EscoriaPlugin.deregister_dialog_manager(MANAGER_CLASS)
# Add ourselves to the list of dialog managers
func _register():
_escoria.register_dialog_manager(MANAGER_CLASS)
_escoria.project_settings_manager.register_setting(
_escoria.project_settings_manager.AVATARS_PATH,
func enable_plugin():
print("Enabling plugin Escoria Dialog Simple")
if EscoriaPlugin.register_dialog_manager(self, MANAGER_CLASS):
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.DEFAULT_DIALOG_TYPE,
"floating",
{
"type": TYPE_STRING
}
)
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.AVATARS_PATH,
"",
{
"type": TYPE_STRING,
@@ -35,26 +66,31 @@ func _register():
}
)
_escoria.project_settings_manager.register_setting(
_escoria.project_settings_manager.TEXT_SPEED_PER_CHARACTER,
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.TEXT_SPEED_PER_CHARACTER,
0.1,
{
"type": TYPE_REAL
}
)
_escoria.project_settings_manager.register_setting(
_escoria.project_settings_manager.FAST_TEXT_SPEED_PER_CHARACTER,
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.FAST_TEXT_SPEED_PER_CHARACTER,
0.25,
{
"type": TYPE_REAL
}
)
_escoria.project_settings_manager.register_setting(
_escoria.project_settings_manager.MAX_TIME_TO_DISAPPEAR,
ESCProjectSettingsManager.register_setting(
ESCProjectSettingsManager.MAX_TIME_TO_DISAPPEAR,
1.0,
{
"type": TYPE_REAL
}
)
else:
get_editor_interface().set_plugin_enabled(
get_plugin_name(),
false
)

Some files were not shown because too many files have changed in this diff Show More