mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add helper function to resolve input port value to deck node
This commit is contained in:
parent
e0239dcae0
commit
a5094ce450
9 changed files with 30 additions and 55 deletions
|
@ -278,6 +278,23 @@ func _post_load() -> void:
|
|||
pass
|
||||
|
||||
|
||||
## A helper function to get a value on an input port. Returns the best match in the following
|
||||
## order of priority:[br]
|
||||
## 1. The direct result of [method request value]. [br]
|
||||
## 2. The result of [method Port.value_callback]. [br]
|
||||
## 3. The input [Port] at index [param input_port]'s stored [member Port.value]. [br]
|
||||
## 4. [code]null[/code].
|
||||
func resolve_input_port_value(input_port: int) -> Variant:
|
||||
if request_value(input_port) != null:
|
||||
return request_value(input_port)
|
||||
elif get_input_ports()[input_port].value_callback.get_object() && get_input_ports()[input_port].value_callback.call() != null:
|
||||
return get_input_ports()[input_port].value_callback.call()
|
||||
elif get_input_ports()[input_port].value != null:
|
||||
return get_input_ports()[input_port].value
|
||||
else:
|
||||
return null
|
||||
|
||||
|
||||
## Returns a [Dictionary] representation of this node.
|
||||
func to_dict(with_meta: bool = true) -> Dictionary:
|
||||
var d := {
|
||||
|
|
|
@ -29,17 +29,8 @@ func _value_request(_on_port: int) -> Variant:
|
|||
if d == null:
|
||||
return null
|
||||
|
||||
var key = get_value_for_input_port(1)
|
||||
var key = resolve_input_port_value(1)
|
||||
if key == null:
|
||||
return null
|
||||
|
||||
return d.get(key)
|
||||
|
||||
|
||||
func get_value_for_input_port(port: int) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
elif get_input_ports()[port].value_callback.get_object() && get_input_ports()[port].value_callback.call() != null:
|
||||
return get_input_ports()[port].value_callback.call()
|
||||
else:
|
||||
return null
|
||||
|
|
|
@ -27,7 +27,7 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void
|
|||
if to_input_port != 1:
|
||||
return
|
||||
|
||||
if request_value(0):
|
||||
if resolve_input_port_value(0):
|
||||
send(0, data, extra_data)
|
||||
elif ports[0].value:
|
||||
send(0, data, extra_data)
|
||||
|
|
|
@ -34,12 +34,8 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void
|
|||
if to_input_port != 1:
|
||||
return
|
||||
|
||||
var data_to_print
|
||||
if request_value(0) != null:
|
||||
data_to_print = str(request_value(0))
|
||||
elif get_input_ports()[0].value_callback.get_object() && get_input_ports()[0].value_callback.call() != "":
|
||||
data_to_print = str(get_input_ports()[0].value_callback.call())
|
||||
else:
|
||||
var data_to_print = resolve_input_port_value(0)
|
||||
if data_to_print == null:
|
||||
data_to_print = str(data)
|
||||
|
||||
times_activated += 1
|
||||
|
|
|
@ -30,11 +30,7 @@ func _event_received(event_name: StringName, event_data: Dictionary = {}) -> voi
|
|||
if event_name != &"process":
|
||||
return
|
||||
|
||||
var run := false
|
||||
if request_value(0) != null:
|
||||
run = request_value(0)
|
||||
elif ports[0].value_callback.get_object() && ports[0].value_callback.call() != null:
|
||||
run = ports[0].value_callback.call()
|
||||
var run := resolve_input_port_value(0) != null
|
||||
|
||||
if !run:
|
||||
return
|
||||
|
|
|
@ -36,8 +36,8 @@ func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> vo
|
|||
if to_input_port != 2:
|
||||
return
|
||||
|
||||
var var_name: String = get_value_for_port(0)
|
||||
var var_value: Variant = get_value_for_port(1)
|
||||
var var_name: String = resolve_input_port_value(0)
|
||||
var var_value: Variant = resolve_input_port_value(1)
|
||||
|
||||
_belonging_to.variable_stack[var_name] = var_value
|
||||
|
||||
|
@ -45,6 +45,7 @@ func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> vo
|
|||
|
||||
# this can probably go into DeckNode with a different name that makes it clear
|
||||
# that it prioritizes call-time resolution
|
||||
# EDIT: done, see DeckNode#resolve_input_port_value
|
||||
func get_value_for_port(port: int) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
|
|
|
@ -33,8 +33,8 @@ func _receive(to_input_port, data: Variant, extra_data: Array = []):
|
|||
return
|
||||
|
||||
|
||||
var msg = get_value_for_input_port(0)
|
||||
var channel = get_value_for_input_port(1)
|
||||
var msg = resolve_input_port_value(0)
|
||||
var channel = resolve_input_port_value(1)
|
||||
|
||||
if channel == null:
|
||||
|
||||
|
@ -46,12 +46,4 @@ func _receive(to_input_port, data: Variant, extra_data: Array = []):
|
|||
|
||||
|
||||
Connections.twitch.send_chat(msg, channel)
|
||||
|
||||
|
||||
func get_value_for_input_port(port: int) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
elif get_input_ports()[port].value_callback.get_object() && get_input_ports()[port].value_callback.call() != null:
|
||||
return get_input_ports()[port].value_callback.call()
|
||||
else:
|
||||
return null
|
||||
|
|
|
@ -25,15 +25,6 @@ func _init() -> void:
|
|||
|
||||
|
||||
func _value_request(_on_port: int) -> Dictionary:
|
||||
var x = float(get_value_for_input_port(0))
|
||||
var y = float(get_value_for_input_port(1))
|
||||
var x = float(resolve_input_port_value(0))
|
||||
var y = float(resolve_input_port_value(1))
|
||||
return {"x": x, "y": y}
|
||||
|
||||
|
||||
func get_value_for_input_port(port: int) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
elif get_input_ports()[port].value_callback.get_object() && get_input_ports()[port].value_callback.call() != null:
|
||||
return get_input_ports()[port].value_callback.call()
|
||||
else:
|
||||
return null
|
||||
|
|
|
@ -32,15 +32,6 @@ func _value_request(_on_port: int) -> Variant:
|
|||
if !(v as Dictionary).has("x") || !(v as Dictionary).has("y"):
|
||||
return null
|
||||
|
||||
var s = float(get_value_for_input_port(1))
|
||||
var s = float(resolve_input_port_value(1))
|
||||
|
||||
return {"x": v.x * s, "y": v.y * s}
|
||||
|
||||
|
||||
func get_value_for_input_port(port: int) -> Variant:
|
||||
if request_value(port) != null:
|
||||
return request_value(port)
|
||||
elif get_input_ports()[port].value_callback.get_object() && get_input_ports()[port].value_callback.call() != null:
|
||||
return get_input_ports()[port].value_callback.call()
|
||||
else:
|
||||
return null
|
||||
|
|
Loading…
Reference in a new issue