mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
47 lines
1.2 KiB
GDScript
47 lines
1.2 KiB
GDScript
extends Node
|
|
|
|
const BASE_NODE_PATH := "res://classes/deck/nodes/"
|
|
|
|
# Dictionary[node_type, NodeDescriptor]
|
|
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 script_path := BASE_NODE_PATH.path_join(current_file)
|
|
var node: DeckNode = load(script_path).new() as DeckNode
|
|
var descriptor := NodeDescriptor.new(script_path, node.name, node.description, node.aliases)
|
|
nodes[node.node_type] = descriptor
|
|
current_file = dir.get_next()
|
|
|
|
|
|
func instance_node(type: String) -> DeckNode:
|
|
if !nodes.has(type):
|
|
return null
|
|
|
|
return load(nodes[type]["script_path"]).new()
|
|
|
|
|
|
class NodeDescriptor:
|
|
var name: String
|
|
var description: String
|
|
var aliases: String
|
|
|
|
var script_path: String
|
|
|
|
|
|
func _init(p_script_path: String, p_name: String, p_description: String, p_aliases: Array[String]) -> void:
|
|
script_path = p_script_path
|
|
|
|
name = p_name
|
|
description = p_description
|
|
aliases = p_aliases.reduce(
|
|
func(accum, el) -> void:
|
|
accum += el
|
|
, "")
|