2
0
Fork 0

Update to 5b0713f1cf3d125791f3cba8a6be93c675f80101

This commit is contained in:
JeremyStar™ 2024-05-11 11:52:45 +02:00
parent 161bf2e7a4
commit 69d110ef74
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -42,21 +42,21 @@ func _init(core_new: Core, schema_new: Dictionary, data_new: Dictionary, parent_
# Check Dictionary # Check Dictionary
_check_dictionary_recursive(schema) _check_dictionary_recursive(schema)
func _check_dictionary_recursive(parent_dict: Dictionary, path: String = "") -> bool: func _check_dictionary_recursive(schema_parent: Dictionary, path: String = "") -> bool:
var success: bool = false var success: bool = false
for key in parent_dict: for key in schema_parent:
if typeof(key) != TYPE_STRING: if typeof(key) != TYPE_STRING:
logger.error(core.stringify_variables("Could not parse schema: Schema key %key% is not of type String", { "key": path + "/" + key })) logger.error(core.stringify_variables("Could not parse schema: Schema key %key% is not of type String", { "key": path + "/" + key }))
success = false success = false
continue continue
match(typeof(parent_dict[key])): match(typeof(schema_parent[key])):
TYPE_OBJECT: TYPE_OBJECT:
if parent_dict[key].get_class() != "Node": if schema_parent[key].get_class() != "Node":
logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type Node", { "key": path + "/" + key })) logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type Node", { "key": path + "/" + key }))
success = false success = false
continue continue
TYPE_DICTIONARY: TYPE_DICTIONARY:
_check_dictionary_recursive(parent_dict[key], path + "/" + key) _check_dictionary_recursive(schema_parent[key], path + "/" + key)
_: _:
logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type CoreValidationSingle or Dictionary", { "key": path + "/" + key })) logger.error(core.stringify_variables("Could not parse schema: Schema value of %key% is not of type CoreValidationSingle or Dictionary", { "key": path + "/" + key }))
success = false success = false
@ -65,20 +65,20 @@ func _check_dictionary_recursive(parent_dict: Dictionary, path: String = "") ->
return success return success
func evaluate() -> Array[String]: func evaluate() -> Array[String]:
return _evaluate_recursive(str(randf()).repeat(50), schema) return _evaluate_recursive(str(randf()).repeat(50), schema, data)
func _evaluate_recursive(random: String, parent_dict: Dictionary, path: String = "") -> Array[String]: func _evaluate_recursive(random: String, schema_parent: Dictionary, data_parent: Dictionary, path: String = "") -> Array[String]:
var failed: Array[String] = [] var failed: Array[String] = []
for key in parent_dict: for key in schema_parent:
# Check if key exists in data # Check if key exists in data
if str(data.get(key, random)) == random: if str(data_parent.get(key, random)) == random:
# Does not exist, append error # Does not exist, append error
failed.append(core.stringify_variables("Key %key% is present in schema but missing in data", { "key": path + "/" + key })) failed.append(core.stringify_variables("Key %key% is present in schema but missing in data", { "key": path + "/" + key }))
else: else:
# Exists in data # Exists in data
if typeof(schema[key]) == TYPE_DICTIONARY: if typeof(schema[key]) == TYPE_DICTIONARY:
# Key is of type Dictionary, allow for recursion to happen # Key is of type Dictionary, allow for recursion to happen
failed.append_array(_evaluate_recursive(random, schema[key], path + "/" + key)) failed.append_array(_evaluate_recursive(random, schema[key], data[key], path + "/" + key))
else: else:
# Key is not of type Dictionary, evaluate against data # Key is not of type Dictionary, evaluate against data
schema[key].data = data[key] schema[key].data = data[key]