regression-test-project/Nodes/Nodes.gd

98 lines
2.5 KiB
GDScript3
Raw Normal View History

2021-03-27 15:53:32 +01:00
extends Node
2021-08-19 18:10:13 +02:00
# This script adds nodes to scene tree and removes them after certain amount
# of time
# Counters which are used to delete and adds nodes in loop
var TIME_TO_DELETE: float = 3.0
2021-08-19 18:10:13 +02:00
var time_to_delete: float = TIME_TO_DELETE
# List of disabled classes
var disabled_classes: Array = [
"NavigationAgent2D",
"NavigationAgent3D",
"GPUParticlesCollisionHeightField",
# Creating them is really slow in Godot 4.0
"ColorPicker",
"FileDialog",
"ColorPickerButton",
"PhysicalSkyMaterial",
"ProceduralSkyMaterial"
]
# List of all collected nodes
2021-08-19 18:10:13 +02:00
var classes: Array = []
var debug_enabled: bool = false
# Collects all classes which will be used
func collect() -> void:
for name_of_class in ClassDB.get_class_list():
if name_of_class in disabled_classes:
continue
if !ClassDB.can_instantiate(name_of_class):
continue
if ClassDB.is_parent_class(name_of_class, "Control"):
classes.append(name_of_class)
continue
if ClassDB.is_parent_class(name_of_class, "Node3D"):
classes.append(name_of_class)
continue
if ClassDB.is_parent_class(name_of_class, "Node2D"):
classes.append(name_of_class)
continue
if ClassDB.get_parent_class(name_of_class) == "Node":
classes.append(name_of_class)
continue
classes.sort()
if debug_enabled:
var to_print: String = "DEBUG: List of classes used in Nodes scene:\n"
to_print += "DEBUG: ["
for index in range(classes.size()):
to_print += '"' + classes[index] + '"'
2021-08-19 18:10:13 +02:00
if index != classes.size() - 1:
to_print += ", "
print(to_print)
# Adds nodes to scenes
func populate() -> void:
for _i in range(2): # Number of created instances of object
for name_of_class in classes:
add_child(ClassDB.instantiate(name_of_class))
# Populate nodes at start
func _ready() -> void:
collect()
populate()
2021-03-27 15:53:32 +01:00
func _process(delta: float) -> void:
2021-08-19 18:10:13 +02:00
# Moves nodes a little
for i in get_children():
if i is Control:
i._set_size(Vector2(200 * randf() - 100, 200 * randf() - 100))
if i is Node2D:
i.set_position(Vector2(1000 * randf() - 500, 1000 * randf() - 500))
if i is Node3D:
if i.get_name() != "Camera3D":
i.set_scale(Vector3(delta + 1, delta + 1, delta + 1))
i.set_position(Vector3(10 * randf(), 10 * randf(), 10 * randf()))
2021-08-19 18:10:13 +02:00
2021-03-27 15:53:32 +01:00
time_to_delete -= delta
2021-08-19 18:10:13 +02:00
# Delete and adds later nodes
2021-03-27 15:53:32 +01:00
if time_to_delete < 0:
2021-08-19 18:10:13 +02:00
if debug_enabled:
print("DEBUG: Deleting nodes")
2021-03-27 15:53:32 +01:00
time_to_delete += TIME_TO_DELETE
2021-08-19 18:10:13 +02:00
2021-04-04 12:52:42 +02:00
for i in get_children():
i.queue_free()
2021-08-19 18:10:13 +02:00
if debug_enabled:
print("DEBUG: Adding nodes")
populate()