mirror of
https://github.com/Relintai/regression-test-project.git
synced 2024-11-12 10:25:30 +01:00
88 lines
2.8 KiB
GDScript
88 lines
2.8 KiB
GDScript
extends Node
|
|
|
|
### Script:
|
|
### - takes all available classes
|
|
### - checks if method is allowed
|
|
### - checks each argument if is allowed(in case e.g. adding new, to prevent crashes due not recognizing types)
|
|
### - print info if needed to console
|
|
### - execute function with parameters
|
|
### - removes all objects/nodes to prevent memory leak
|
|
|
|
var debug_print: bool = true
|
|
var add_to_tree: bool = false # Adds nodes to tree, freeze godot when removing a lot of nodes
|
|
var use_parent_methods: bool = false # Allows Node2D use Node methods etc. - it is a little slow option which rarely shows
|
|
var use_always_new_object: bool = true # Don't allow to "remeber" other function effects
|
|
var exiting: bool = false
|
|
|
|
|
|
func _ready() -> void:
|
|
ValueCreator.number = 100
|
|
|
|
tests_all_functions()
|
|
|
|
|
|
# Test all functions
|
|
func tests_all_functions() -> void:
|
|
for name_of_class in BasicData.get_list_of_available_classes():
|
|
if debug_print:
|
|
print("\n#################### " + name_of_class + " ####################")
|
|
|
|
var object: Object = ClassDB.instance(name_of_class)
|
|
assert(object != null, "Object must be instantable")
|
|
if add_to_tree:
|
|
if object is Node:
|
|
add_child(object)
|
|
var method_list: Array = ClassDB.class_get_method_list(name_of_class, !use_parent_methods)
|
|
|
|
# Removes excluded methods
|
|
BasicData.remove_disabled_methods(method_list, BasicData.function_exceptions)
|
|
|
|
for method_data in method_list:
|
|
if !BasicData.check_if_is_allowed(method_data):
|
|
continue
|
|
|
|
var arguments: Array = ParseArgumentType.parse_and_return_objects(method_data, name_of_class, debug_print)
|
|
|
|
if debug_print:
|
|
var to_print: String = "GDSCRIPT CODE: "
|
|
if (
|
|
ClassDB.is_parent_class(name_of_class, "Object")
|
|
&& !ClassDB.is_parent_class(name_of_class, "Node")
|
|
&& !ClassDB.is_parent_class(name_of_class, "Reference")
|
|
&& !ClassDB.class_has_method(name_of_class, "new")
|
|
):
|
|
to_print += 'ClassDB.instance("' + name_of_class + '").' + method_data["name"] + "("
|
|
else:
|
|
to_print += name_of_class.trim_prefix("_") + ".new()." + method_data["name"] + "("
|
|
|
|
for i in arguments.size():
|
|
to_print += ParseArgumentType.return_gdscript_code_which_run_this_object(arguments[i])
|
|
if i != arguments.size() - 1:
|
|
to_print += ", "
|
|
to_print += ")"
|
|
print(to_print)
|
|
|
|
object.callv(method_data["name"], arguments)
|
|
|
|
for argument in arguments:
|
|
if argument is Node:
|
|
argument.queue_free()
|
|
elif argument is Object && !(argument is Reference):
|
|
argument.free()
|
|
|
|
if use_always_new_object:
|
|
if object is Node:
|
|
object.queue_free()
|
|
elif object is Object && !(object is Reference):
|
|
object.free()
|
|
|
|
object = ClassDB.instance(name_of_class)
|
|
if add_to_tree:
|
|
if object is Node:
|
|
add_child(object)
|
|
|
|
if object is Node:
|
|
object.queue_free()
|
|
elif object is Object && !(object is Reference):
|
|
object.free()
|