From c390e349fef4cb647c17f0c5b84819ea578246b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mikrut?= <41945903+qarmin@users.noreply.github.com> Date: Sat, 18 Sep 2021 21:01:07 +0200 Subject: [PATCH] Check classes in Godot4 (#62) --- Autoload/Autoload.gd | 1 + CreatingAllThings/CreatingAllThings.gd | 30 ++++++++++++++++++++++++ CreatingAllThings/CreatingAllThings.tscn | 6 +++++ 3 files changed, 37 insertions(+) create mode 100644 CreatingAllThings/CreatingAllThings.gd create mode 100644 CreatingAllThings/CreatingAllThings.tscn diff --git a/Autoload/Autoload.gd b/Autoload/Autoload.gd index ef6ef30..e95c24e 100644 --- a/Autoload/Autoload.gd +++ b/Autoload/Autoload.gd @@ -16,6 +16,7 @@ var os # Each scene runs alone const alone_steps : Array = [ + "res://CreatingAllThings/CreatingAllThings.tscn", "res://Nodes/Nodes.tscn", # "res://ReparentingDeleting/ReparentingDeleting.tscn", # Really slow in 4.0 "res://AutomaticBugs/FunctionExecutor.tscn", # Only Needs to be executed once, but this is workaround a little diff --git a/CreatingAllThings/CreatingAllThings.gd b/CreatingAllThings/CreatingAllThings.gd new file mode 100644 index 0000000..f0523ac --- /dev/null +++ b/CreatingAllThings/CreatingAllThings.gd @@ -0,0 +1,30 @@ +extends Node2D + +var available_classes : Array = [] +var exeptions : Array = ["SceneTree", "EditorSettings", "ProjectSettings", "InputEventShortcut", "InputMap"] + +func _ready(): + var cl : Array = Array(ClassDB.get_class_list()) + cl.sort() + for name_of_class in cl: + if !ClassDB.can_instantiate(name_of_class): + continue + if name_of_class in exeptions: + continue + if name_of_class.to_lower().find("server") != -1: + continue + + print("########### " + name_of_class) + print("GDSCRIPT CODE: var thing = ClassDB.instantiate(\"" + name_of_class + "\")") + print("GDSCRIPT CODE: str(" + name_of_class + ")") + + var thing = ClassDB.instantiate(name_of_class) + str(thing) + + if thing is Node: + print("GDSCRIPT CODE: thing.queue_free()") + thing.queue_free() + elif thing is Object && !(thing is RefCounted): + print("GDSCRIPT CODE: thing.free()") + thing.free() + diff --git a/CreatingAllThings/CreatingAllThings.tscn b/CreatingAllThings/CreatingAllThings.tscn new file mode 100644 index 0000000..aa4820b --- /dev/null +++ b/CreatingAllThings/CreatingAllThings.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://bj2rcig1emwek"] + +[ext_resource type="Script" path="res://CreatingAllThings/CreatingAllThings.gd" id="1_vqkfm"] + +[node name="CreatingAllThings" type="Node2D"] +script = ExtResource( "1_vqkfm" )