feature: Added ability to use Escoria variables with the custom command
This commit is contained in:
committed by
Julian Murgia
parent
44425a3f92
commit
152d92372e
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user