From 17cecf5ef3fea1e45db5f6f46927386ec5e00f95 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Thu, 9 May 2024 15:20:22 +0200 Subject: [PATCH] Fix multiple issues regarding validation cleanup Good that I'm writing unit tests for this shit. --- src/validation.gd | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/validation.gd b/src/validation.gd index dec2687..eefdc52 100644 --- a/src/validation.gd +++ b/src/validation.gd @@ -23,8 +23,19 @@ var singles: Array[CoreValidationSingle] # +++ module +++ func _cleanup() -> void: + # Schemas + var schemas_remove_enty: Array[CoreValidationSchema] = [] + for schema in schemas: + schemas_remove_enty.append(schema) + if !is_instance_valid(schema): continue + if !is_instance_valid(schema.parent): + logger.diag("Removing schema '" + schema.name + "'") + schema.queue_free() + for schema in schemas_remove_enty: + schemas.remove_at(schemas.find(schema)) + # Singles - var singles_remove_enty: Array[CoreLoggerInstance] = [] + var singles_remove_enty: Array[CoreValidationSingle] = [] for single in singles: singles_remove_enty.append(single) if !is_instance_valid(single): continue @@ -33,17 +44,6 @@ func _cleanup() -> void: single.queue_free() for single in singles_remove_enty: singles.remove_at(singles.find(single)) - - # Schemas - var schemas_remove_enty: Array[CoreLoggerInstance] = [] - for schema in schemas: - singles_remove_enty.append(schema) - if !is_instance_valid(schema): continue - if !is_instance_valid(schema.parent): - logger.diag("Removing schema '" + schema.name + "'") - schema.queue_free() - for schema in schemas_remove_enty: - schemas.remove_at(schemas.find(schema)) func _schedule() -> void: # Singles @@ -61,10 +61,12 @@ func _schedule() -> void: # +++ data validation +++ ## Returns a new [CoreValidationSingle] func get_single(data, parent: Node) -> CoreValidationSingle: - singles.append(parent) - return CoreValidationSingle.new(core, data, parent) + var single: CoreValidationSingle = CoreValidationSingle.new(core, data, parent) + singles.append(single) + return single ## Returns a new [CoreValidationSchema] -func get_schema(schema: Dictionary, parent: Node) -> CoreValidationSchema: - schemas.append(parent) - return CoreValidationSchema.new(core, schema, parent) +func get_schema(schema_dict: Dictionary, parent: Node) -> CoreValidationSchema: + var schema: CoreValidationSchema = CoreValidationSchema.new(core, schema_dict, parent) + schemas.append(schema) + return schema