2023-06-24 05:39:50 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
const BASE_NODE_PATH := "res://classes/deck/nodes/"
|
2023-07-21 07:30:12 +02:00
|
|
|
|
|
|
|
# Dictionary[node_type, NodeDescriptor]
|
2023-06-24 05:39:50 +02:00
|
|
|
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"):
|
2023-07-21 07:30:12 +02:00
|
|
|
# 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
|
2023-06-24 05:39:50 +02:00
|
|
|
current_file = dir.get_next()
|
|
|
|
|
|
|
|
|
|
|
|
func instance_node(type: String) -> DeckNode:
|
|
|
|
if !nodes.has(type):
|
|
|
|
return null
|
|
|
|
|
2023-07-21 07:30:12 +02:00
|
|
|
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
|
|
|
|
, "")
|