From 768f65d929ee60ce14a9d94c2cbf585f8137a95c Mon Sep 17 00:00:00 2001 From: Duncan Brown Date: Fri, 15 Apr 2022 15:19:55 -0400 Subject: [PATCH] fix: allows for bare decimals (no leading 0) to be properly interpreted; also adds in additional validation for 'wait' command --- .../game/core-scripts/esc/commands/wait.gd | 18 ++++++++++++++++++ .../game/core-scripts/utils/esc_utils.gd | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd b/addons/escoria-core/game/core-scripts/esc/commands/wait.gd index ae96a049..6a5fb996 100644 --- a/addons/escoria-core/game/core-scripts/esc/commands/wait.gd +++ b/addons/escoria-core/game/core-scripts/esc/commands/wait.gd @@ -20,6 +20,24 @@ func configure() -> ESCCommandArgumentDescriptor: ) +# Validate whether the given arguments match the command descriptor +func validate(arguments: Array): + if not .validate(arguments): + return false + + # 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." + ] + ) + return false + + return true + # Run the command func run(command_params: Array) -> int: yield(escoria.get_tree().create_timer(float(command_params[0])), "timeout") diff --git a/addons/escoria-core/game/core-scripts/utils/esc_utils.gd b/addons/escoria-core/game/core-scripts/utils/esc_utils.gd index 9c068669..60a2e6dc 100644 --- a/addons/escoria-core/game/core-scripts/utils/esc_utils.gd +++ b/addons/escoria-core/game/core-scripts/utils/esc_utils.gd @@ -43,7 +43,7 @@ func get_typed_value(value: String, type_hint = []): var regex_bool = RegEx.new() regex_bool.compile("^true|false$") var regex_float = RegEx.new() - regex_float.compile("^-?[0-9]+\\.[0-9]+$") + regex_float.compile("^-?[0-9]*\\.[0-9]+$") var regex_int = RegEx.new() regex_int.compile("^-?[0-9]+$")