2023-06-10 19:13:16 +02:00
|
|
|
class_name Deck
|
|
|
|
|
|
|
|
var nodes: Dictionary
|
|
|
|
|
|
|
|
enum Types{
|
|
|
|
ERROR = -1,
|
|
|
|
BOOL,
|
|
|
|
NUMERIC,
|
|
|
|
STRING,
|
|
|
|
ARRAY,
|
|
|
|
DICTIONARY,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static var type_assoc: Dictionary = {
|
|
|
|
Types.ERROR: DeckType.DeckTypeError,
|
|
|
|
Types.BOOL: DeckType.DeckTypeBool,
|
|
|
|
Types.NUMERIC: DeckType.DeckTypeNumeric,
|
|
|
|
Types.STRING: DeckType.DeckTypeString,
|
|
|
|
Types.ARRAY: DeckType.DeckTypeArray,
|
|
|
|
Types.DICTIONARY: DeckType.DeckTypeDictionary,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func add_node(node: GDScript, meta: Dictionary = {}) -> DeckNode:
|
|
|
|
# TODO: accept instances of DeckNode instead of instancing here?
|
|
|
|
var uuid := UUID.v4()
|
|
|
|
var node_inst: DeckNode = node.new() as DeckNode
|
|
|
|
nodes[uuid] = node_inst
|
|
|
|
node_inst._belonging_to = self
|
|
|
|
node_inst._id = uuid
|
|
|
|
|
|
|
|
if !meta.is_empty():
|
|
|
|
for k in meta:
|
|
|
|
node_inst.set_meta(k, meta[k])
|
|
|
|
|
|
|
|
return node_inst
|
|
|
|
|
|
|
|
|
|
|
|
func get_node(uuid: String) -> DeckNode:
|
|
|
|
return nodes.get(uuid)
|
|
|
|
|
|
|
|
|
|
|
|
func connect_nodes(from_node: DeckNode, to_node: DeckNode, from_port: int, to_port: int) -> bool:
|
|
|
|
# first, check that we can do the type conversion.
|
2023-06-11 17:39:11 +02:00
|
|
|
var type_a: Types = from_node.output_ports[from_port].type
|
|
|
|
var type_b: Types = to_node.input_ports[to_port].type
|
|
|
|
var err: DeckType = (type_assoc[type_b]).from(type_assoc[type_a].new())
|
2023-06-10 19:13:16 +02:00
|
|
|
if err is DeckType.DeckTypeError:
|
|
|
|
print(err.error_message)
|
|
|
|
return false
|
|
|
|
|
|
|
|
# TODO: prevent duplicate connections
|
|
|
|
|
|
|
|
from_node.add_outgoing_connection(from_port, to_node._id, to_port)
|
|
|
|
return true
|