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. 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()) 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 func disconnect_nodes(from_node: DeckNode, to_node: DeckNode, from_port: int, to_port: int) -> void: var hash = {to_node._id: to_port}.hash() from_node.remove_outgoing_connection(from_port, hash)