miggor-StreamGraph/classes/deck/node_db.gd
2023-06-24 06:39:50 +03:00

27 lines
729 B
GDScript

extends Node
const BASE_NODE_PATH := "res://classes/deck/nodes/"
var nodes: Dictionary = {}
func _init() -> void:
var dir := DirAccess.open(BASE_NODE_PATH)
dir.list_dir_begin()
var current_file := dir.get_next()
while current_file != "":
print(current_file)
if current_file.ends_with(".gd"):
var f := FileAccess.open(BASE_NODE_PATH.path_join(current_file), FileAccess.READ)
var line := f.get_line()
if !line.begins_with("###type="):
current_file = dir.get_next()
continue
nodes[line.trim_prefix("###type=")] = BASE_NODE_PATH.path_join(current_file)
current_file = dir.get_next()
func instance_node(type: String) -> DeckNode:
if !nodes.has(type):
return null
return load(nodes[type]).new()