diff --git a/addons/escoria-core/game/core-scripts/esc/commands/custom.gd b/addons/escoria-core/game/core-scripts/esc/commands/custom.gd index 2e9bea32..fbafde4a 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/custom.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/custom.gd @@ -81,6 +81,11 @@ func run(command_params: Array) -> int: var object = escoria.object_manager.get_object( command_params[0] ) + # 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]) + object.node.get_node(command_params[1]).call( command_params[2], command_params[3] diff --git a/addons/escoria-core/game/core-scripts/esc/commands/print.gd b/addons/escoria-core/game/core-scripts/esc/commands/print.gd index e550535f..3c6403c5 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/print.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/print.gd @@ -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.logger.replace_globals(command_params[0])) + print(escoria.esc_compiler.replace_globals(command_params[0])) return ESCExecution.RC_OK diff --git a/addons/escoria-core/game/core-scripts/esc/commands/say.gd b/addons/escoria-core/game/core-scripts/esc/commands/say.gd index 4c2bed58..04ef1c9f 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/say.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/say.gd @@ -101,7 +101,7 @@ func run(command_params: Array) -> int: return ESCExecution.RC_ERROR # Replace the names of any globals in "{ }" with their value - command_params[1] = escoria.logger.replace_globals(command_params[1]) + command_params[1] = escoria.esc_compiler.replace_globals(command_params[1]) escoria.dialog_player.say( command_params[0], diff --git a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd index 7ba18108..0bd04c95 100644 --- a/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd +++ b/addons/escoria-core/game/core-scripts/esc/esc_compiler.gd @@ -27,6 +27,8 @@ var _dialog_regex var _dialog_end_regex var _dialog_option_regex var _group_regex +# Regex to match globals in debug strings +var _globals_regex: RegEx # The currently compiled event var _current_event = null @@ -82,7 +84,9 @@ func _init(): _dialog_option_regex.compile(ESCDialogOption.REGEX) _group_regex = RegEx.new() _group_regex.compile(ESCGroup.REGEX) - + # Use look-ahead/behind to capture the term in braces + _globals_regex = RegEx.new() + _globals_regex.compile("(?<=\\{)(.*)(?=\\})") # Load an ESC file from a file resource func load_esc_file(path: String) -> ESCScript: @@ -258,3 +262,18 @@ func _compile(lines: Array, path: String = "") -> Array: ] ) 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 diff --git a/addons/escoria-core/game/core-scripts/log/esc_logger.gd b/addons/escoria-core/game/core-scripts/log/esc_logger.gd index 6786e7df..225a448a 100644 --- a/addons/escoria-core/game/core-scripts/log/esc_logger.gd +++ b/addons/escoria-core/game/core-scripts/log/esc_logger.gd @@ -19,9 +19,6 @@ var crash_savegame_filename # Did we crash already? onready var crashed = false -# Regex to match globals in debug strings -var globals_regex: RegEx - # Valid log levels enum { LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG_TRACE } @@ -56,24 +53,6 @@ func _init(): File.WRITE ) - # Use look-ahead/behind to capture the term in braces - globals_regex = RegEx.new() - globals_regex.compile("(?<=\\{)(.*)(?=\\})") - -# 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 # Log a trace message # @@ -88,7 +67,7 @@ func replace_globals(string: String) -> String: func trace(string: String, args = []): if _get_log_level() >= LOG_TRACE and !crashed: var argsstr = str(args) if !args.empty() else "" - string = replace_globals(string) + string = escoria.esc_compiler.replace_globals(string) _log("(T)\t" + string + " \t" + argsstr) @@ -104,7 +83,7 @@ func trace(string: String, args = []): # * args: Additional information func debug(string: String, args = []): if _get_log_level() >= LOG_DEBUG and !crashed: - string = replace_globals(string) + string = escoria.esc_compiler.replace_globals(string) var argsstr = str(args) if !args.empty() else "" _log("(D)\t" + string + " \t" + argsstr) @@ -128,7 +107,7 @@ func info(string: String, args = []): argsstr.append(p.global_id) else: argsstr.append(str(arg)) - string = replace_globals(string) + string = escoria.esc_compiler.replace_globals(string) _log("(I)\t" + string + " \t" + str(argsstr)) @@ -145,7 +124,7 @@ func info(string: String, args = []): func warning(string: String, args = []): if _get_log_level() >= LOG_WARNING and !crashed: var argsstr = str(args) if !args.empty() else "" - string = replace_globals(string) + string = escoria.esc_compiler.replace_globals(string) _log("(W)\t" + string + " \t" + argsstr, true) if escoria.project_settings_manager.get_setting( @@ -180,7 +159,7 @@ func warning(string: String, args = []): 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 = replace_globals(string) + string = escoria.esc_compiler.replace_globals(string) _log("(E)\t" + string + " \t" + argsstr, true) if escoria.project_settings_manager.get_setting( diff --git a/game/rooms/room03/esc/room03_bridge.esc b/game/rooms/room03/esc/room03_bridge.esc index 48d58ac8..6796b781 100644 --- a/game/rooms/room03/esc/room03_bridge.esc +++ b/game/rooms/room03/esc/room03_bridge.esc @@ -1,8 +1,6 @@ # THIS ROOMS FEATURES AN OPEN BRIDGE WITH A ***BROKEN*** BUTTON TO USE IN ORDER TO OPEN - :setup -custom r3_r_exit door_enabler enable_door a b c 1 2 345 # If the room hasn't been visited previously, open the bridge and break the button > [!room3_visited] @@ -12,6 +10,9 @@ custom r3_r_exit door_enabler enable_door a b c 1 2 345 # Set a global for the button state so we can write test logic for it # This will start the animation with the check in the "ready:" state below. set_global r3_button_broken true + # The parameters aren't used by the disable_door function, + # they're there as an example of how to pass parameters. + custom r3_r_exit door_enabler disable_door a b c 1 2 345 {r3_button_broken} > [r3_bridge_closed] # Make set_state IMMEDIATE to reach the final frame immediately @@ -31,16 +32,16 @@ custom r3_r_exit door_enabler enable_door a b c 1 2 345 # > [r3_button_broken] # set_state r3_button button_broken stop - + > [eq ESC_LAST_SCENE room4] # Set the bridge closed and button fixed or else you cant get back to the left hand side # if you started the game in room 4 set_global r3_bridge_closed true set_global r3_button_broken false - + # Turn off the button's smoke animation #set_state r3_button button_repaired true - + teleport player r3_r_exit # Set the bridge state which will also run the bridge closing animation set_state r3_bridge bridge_close true @@ -49,7 +50,7 @@ custom r3_r_exit door_enabler enable_door a b c 1 2 345 # Don't make the right platform a separate object you can click. This is only valid when # the bridge is open set_interactive r3_right_platform false - set_interactive r3_r_exit true + set_interactive r3_r_exit true # We use a custom function to enable the collision polygon on the door # to enable it to work as a door once the bridge is closed. custom r3_r_exit door_enabler enable_door @@ -66,6 +67,6 @@ custom r3_r_exit door_enabler enable_door a b c 1 2 345 set_state r3_button button_repaired true > [r3_bridge_closed] # This is for when you close the bridge then go back to room 2 - # Set the bridge closed + # Set the bridge closed set_global r3_bridge_closed true