diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 16aad1a..333df3a 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -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 := { diff --git a/classes/deck/nodes/dictionary_get_key.gd b/classes/deck/nodes/dictionary_get_key.gd index 9d165f7..bebcc8e 100644 --- a/classes/deck/nodes/dictionary_get_key.gd +++ b/classes/deck/nodes/dictionary_get_key.gd @@ -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 diff --git a/classes/deck/nodes/if_true.gd b/classes/deck/nodes/if_true.gd index 18ee775..73b54f5 100644 --- a/classes/deck/nodes/if_true.gd +++ b/classes/deck/nodes/if_true.gd @@ -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) diff --git a/classes/deck/nodes/print.gd b/classes/deck/nodes/print.gd index f54e308..9f07832 100644 --- a/classes/deck/nodes/print.gd +++ b/classes/deck/nodes/print.gd @@ -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 diff --git a/classes/deck/nodes/process_node.gd b/classes/deck/nodes/process_node.gd index bea6576..809cd4c 100644 --- a/classes/deck/nodes/process_node.gd +++ b/classes/deck/nodes/process_node.gd @@ -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 diff --git a/classes/deck/nodes/set_deck_var.gd b/classes/deck/nodes/set_deck_var.gd index f2121d3..f7a46d6 100644 --- a/classes/deck/nodes/set_deck_var.gd +++ b/classes/deck/nodes/set_deck_var.gd @@ -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) diff --git a/classes/deck/nodes/twitch_send_chat.gd b/classes/deck/nodes/twitch_send_chat.gd index 75cf5f0..f18803f 100644 --- a/classes/deck/nodes/twitch_send_chat.gd +++ b/classes/deck/nodes/twitch_send_chat.gd @@ -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 diff --git a/classes/deck/nodes/vector_compose.gd b/classes/deck/nodes/vector_compose.gd index 363f1da..466d89f 100644 --- a/classes/deck/nodes/vector_compose.gd +++ b/classes/deck/nodes/vector_compose.gd @@ -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 diff --git a/classes/deck/nodes/vector_multiply.gd b/classes/deck/nodes/vector_multiply.gd index 83b09ad..6783eb1 100644 --- a/classes/deck/nodes/vector_multiply.gd +++ b/classes/deck/nodes/vector_multiply.gd @@ -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