failures.append(core.stringify_variables("Data is not of expected type(s) %expected% (is %got%)",{"expected":types_string,"got":type_string(typeof(data))}))
CoreTypes.ValidationType.MATCHES_CLASS:
# If not an object, skip
iftypeof(data)!=Variant.Type.TYPE_OBJECT:
logger.warn("Can't match class as data is not of type Object")
continue
ifrule["exact"]:
# Only check if class name matches specified class
ifdata.get_class()!=rule["class"]:
failures.append(core.stringify_variables("Expected exact class %expected% but data is of class %got%",{"expected":rule["class"],"got":data.get_class()}))
else:
# Check if class is or inherits specified class
if!data.is_class(rule["class"]):
failures.append(core.stringify_variables("Expected class %expected% but data is of class %got%",{"expected":rule["class"],"got":data.get_class()}))
CoreTypes.ValidationType.IN_RANGE:
# If not an int or float, skip
match(rule["matched_against"]):
"integer":
iftypeof(data)!=Variant.Type.TYPE_INT:
logger.warn("Can't match class as data is not of type int")
continue
"float":
iftypeof(data)!=Variant.Type.TYPE_FLOAT:
logger.warn("Can't match class as data is not of type float")
continue
_:logger.crash(core.stringify_variables("Invalid 'matched_against' value %value% for IN_RANGE",{"value":rule["matched_against"]}))
# Check if from is bigger than to
ifrule["from"]>rule["to"]:
logger.error(core.stringify_variables("Can't match invalid %type% range %from% to %to%",{"type":rule["matched_against"],"from":rule["from"],"to":rule["to"]}))
continue
# Perform checks
ifdata<rule["from"]:failures.append(core.stringify_variables("Data is smaller than %type% range start %expected%",{"type":rule["matched_against"],"expected":rule["from"]}))
ifdata>rule["to"]:failures.append(core.stringify_variables("Data is larger than %type% range end %expected%",{"type":rule["matched_against"],"expected":rule["to"]}))
CoreTypes.ValidationType.HAS_MINIMUM:
# If not an int or float, skip
match(rule["matched_against"]):
"integer":
iftypeof(data)!=Variant.Type.TYPE_INT:
logger.warn("Can't determine if data has minimum value as data is not of type int")
continue
"float":
iftypeof(data)!=Variant.Type.TYPE_FLOAT:
logger.warn("Can't determine if data has minimum value as data is not of type float")
continue
_:logger.crash(core.stringify_variables("Invalid 'matched_against' value %value% for HAS_MINIMUM",{"value":rule["matched_against"]}))
# Perform check
ifdata<rule["minimum"]:failures.append(core.stringify_variables("Data is smaller than minimum %type% value %expected%",{"type":rule["matched_against"],"expected":rule["minimum"]}))
CoreTypes.ValidationType.HAS_MAXIMUM:
# If not an int or float, skip
match(rule["matched_against"]):
"integer":
iftypeof(data)!=Variant.Type.TYPE_INT:
logger.warn("Can't determine if data has maximum value as data is not of type int")
continue
"float":
iftypeof(data)!=Variant.Type.TYPE_FLOAT:
logger.warn("Can't determine if data has maximum value as data is not of type float")
continue
_:logger.crash(core.stringify_variables("Invalid 'matched_against' value %value% for HAS_MINIMUM",{"value":rule["matched_against"]}))
# Perform check
ifdata>rule["maximum"]:failures.append(core.stringify_variables("Data is smaller than minimum %type% value %expected%",{"type":rule["matched_against"],"expected":rule["maximum"]}))
CoreTypes.ValidationType.HAS_VALUES:
# Used later
varsuccess:bool=false
ifrule["all_required"]:
# Invert usage
success=true
forvalueinrule["values"]:
ifdata!=value:
# One value did not match
success=false
if!success:failures.append("Data did not match all provided values")
else:
forvalueinrule["values"]:
ifdata==value:
# One value did match
success=true
if!success:failures.append("Data did not match a single provided value")
logger.warn("Can't determine if data contains values as data is not of type String or StringName")
continue
varsuccesses:int=0
forvalueinrule["values"]:
ifdata.contains(value):
successes+=1
# Success if equals or bigger than 'minimum_matches'
ifsuccesses<rule["minimum_matches"]:failures.append(core.stringify_variables("Data did matched %got% out of %expected% expected strings",{"got":successes,"expected":rule["minimum_matches"]}))