mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add call time resolution of port values
This commit is contained in:
parent
83d5fae1bd
commit
46169147a4
6 changed files with 124 additions and 3 deletions
|
@ -21,6 +21,8 @@ static var type_assoc: Dictionary = {
|
|||
Types.DICTIONARY: DeckType.DeckTypeDictionary,
|
||||
}
|
||||
|
||||
var variable_stack: Dictionary = {}
|
||||
|
||||
|
||||
func add_node(node: GDScript, meta: Dictionary = {}) -> DeckNode:
|
||||
# TODO: accept instances of DeckNode instead of instancing here?
|
||||
|
|
|
@ -4,6 +4,7 @@ var name: String
|
|||
var input_ports: Array[Port]
|
||||
var output_ports: Array[Port]
|
||||
var outgoing_connections: Dictionary
|
||||
var incoming_connections: Dictionary
|
||||
|
||||
var ports: Array[Port]
|
||||
|
||||
|
@ -49,7 +50,7 @@ func send(from_port: int, data: DeckType, extra_data: Array = []) -> void:
|
|||
# key is node uuid
|
||||
# value is input port on destination node
|
||||
for node in connection:
|
||||
_belonging_to.get_node(node)._receive(connection[node], data, extra_data)
|
||||
get_node(node)._receive(connection[node], data, extra_data)
|
||||
|
||||
|
||||
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
|
@ -68,6 +69,26 @@ func add_outgoing_connection(from_port: int, to_node: String, to_port: int) -> v
|
|||
var port_connections: Array = outgoing_connections.get(from_port, [])
|
||||
port_connections.append({to_node: to_port})
|
||||
outgoing_connections[from_port] = port_connections
|
||||
get_node(to_node).add_incoming_connection(to_port, _id, from_port)
|
||||
|
||||
|
||||
func add_incoming_connection(to_port: int, from_node: String, from_port: int) -> void:
|
||||
var connection := {from_node: from_port}
|
||||
incoming_connections[to_port] = connection
|
||||
|
||||
|
||||
func request_value(on_port: int) -> Variant:
|
||||
if !incoming_connections.has(on_port):
|
||||
return null
|
||||
|
||||
var connection: Dictionary = incoming_connections[on_port]
|
||||
var node := get_node(connection.keys()[0])
|
||||
return node._value_request(connection.values()[0])
|
||||
|
||||
|
||||
# override this
|
||||
func _value_request(from_port: int) -> Variant:
|
||||
return null
|
||||
|
||||
|
||||
func remove_outgoing_connection(from_port: int, connection_hash: int) -> void:
|
||||
|
|
16
classes/deck/nodes/get_deck_var.gd
Normal file
16
classes/deck/nodes/get_deck_var.gd
Normal file
|
@ -0,0 +1,16 @@
|
|||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
add_output_port(
|
||||
Deck.Types.STRING,
|
||||
"Variable",
|
||||
"field"
|
||||
)
|
||||
|
||||
name = "Get Deck Var"
|
||||
|
||||
|
||||
func _value_request(from_port: int) -> Variant:
|
||||
var key = ports[0].value_callback.call()
|
||||
return _belonging_to.variable_stack[key]
|
|
@ -27,7 +27,14 @@ func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
|||
if to_port != 1:
|
||||
return
|
||||
|
||||
var data_to_print = ports[0].value_callback.call() if ports[0].value_callback.call() != "" else data.get_value()
|
||||
var data_to_print
|
||||
if request_value(0) != null:
|
||||
data_to_print = request_value(0)
|
||||
elif ports[0].value_callback.call() != "":
|
||||
data_to_print = ports[0].value_callback.call()
|
||||
else:
|
||||
data_to_print = data.get_value()
|
||||
|
||||
# var data_to_print = input_ports[0].value_callback.call()
|
||||
print(data_to_print)
|
||||
print("extra data: ", extra_data)
|
||||
|
|
52
classes/deck/nodes/set_deck_var.gd
Normal file
52
classes/deck/nodes/set_deck_var.gd
Normal file
|
@ -0,0 +1,52 @@
|
|||
extends DeckNode
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
add_input_port(
|
||||
Deck.Types.STRING,
|
||||
"Variable Name",
|
||||
"field"
|
||||
)
|
||||
|
||||
add_input_port(
|
||||
Deck.Types.STRING,
|
||||
"Value",
|
||||
"field"
|
||||
)
|
||||
|
||||
add_input_port(
|
||||
Deck.Types.BOOL,
|
||||
"Set",
|
||||
"button"
|
||||
)
|
||||
|
||||
add_output_port(
|
||||
Deck.Types.STRING,
|
||||
"Value",
|
||||
"label"
|
||||
)
|
||||
|
||||
name = "Set Deck Var"
|
||||
|
||||
|
||||
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
if to_port != 2:
|
||||
return
|
||||
|
||||
var var_name: String = get_value_for_port(0, data)
|
||||
# String for now, until i figure out an Any type
|
||||
var var_value: String = get_value_for_port(1, data)
|
||||
|
||||
_belonging_to.variable_stack[var_name] = var_value
|
||||
|
||||
send(3, DeckType.DeckTypeString.new(var_value))
|
||||
|
||||
# this can probably go into DeckNode with a different name that makes it clear
|
||||
# that it prioritizes call-time resolution
|
||||
func get_value_for_port(port: int, data: DeckType) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
elif ports[port].value_callback.call() != "":
|
||||
return ports[port].value_callback.call()
|
||||
else:
|
||||
return data.get_value()
|
|
@ -5,15 +5,22 @@ const NODE_SCENE := preload("res://graph_node_renderer/deck_node_renderer_graph_
|
|||
var deck: Deck = Deck.new()
|
||||
var button_node = preload("res://classes/deck/nodes/button.gd")
|
||||
var print_node = preload("res://classes/deck/nodes/print.gd")
|
||||
|
||||
var get_var_node = preload("res://classes/deck/nodes/get_deck_var.gd")
|
||||
var set_var_node = preload("res://classes/deck/nodes/set_deck_var.gd")
|
||||
|
||||
func _ready() -> void:
|
||||
var add_button := Button.new()
|
||||
add_button.text = "Button"
|
||||
var add_print := Button.new()
|
||||
add_print.text = "Print"
|
||||
var get_var := Button.new()
|
||||
get_var.text = "Get Var"
|
||||
var set_var := Button.new()
|
||||
set_var.text = "Set Var"
|
||||
get_zoom_hbox().add_child(add_button)
|
||||
get_zoom_hbox().add_child(add_print)
|
||||
get_zoom_hbox().add_child(get_var)
|
||||
get_zoom_hbox().add_child(set_var)
|
||||
|
||||
add_button.pressed.connect(
|
||||
func():
|
||||
|
@ -31,6 +38,22 @@ func _ready() -> void:
|
|||
add_child(node_renderer)
|
||||
)
|
||||
|
||||
get_var.pressed.connect(
|
||||
func():
|
||||
var node := deck.add_node(get_var_node)
|
||||
var node_renderer: DeckNodeRendererGraphNode = NODE_SCENE.instantiate()
|
||||
node_renderer.node = node
|
||||
add_child(node_renderer)
|
||||
)
|
||||
|
||||
set_var.pressed.connect(
|
||||
func():
|
||||
var node := deck.add_node(set_var_node)
|
||||
var node_renderer: DeckNodeRendererGraphNode = NODE_SCENE.instantiate()
|
||||
node_renderer.node = node
|
||||
add_child(node_renderer)
|
||||
)
|
||||
|
||||
connection_request.connect(attempt_connection)
|
||||
disconnection_request.connect(attempt_disconnect)
|
||||
|
||||
|
|
Loading…
Reference in a new issue