mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
58 lines
1.4 KiB
GDScript3
58 lines
1.4 KiB
GDScript3
|
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.input_ports[from_port].type
|
||
|
var type_b: Types = to_node.output_ports[to_port].type
|
||
|
var err: DeckType = (type_assoc[type_b] as GDScript).from(type_assoc[type_a])
|
||
|
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
|