diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 3876f31..459b12a 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -145,19 +145,9 @@ func add_incoming_connection(to_port: int, from_node: String, from_port: int) -> incoming_connection_added.emit(to_port) -## Request a value from an incoming connection on this node's input port at [param on_port]. +## Asynchronously request a value from an incoming connection on this node's input port at [param on_port]. ## Returns [code]null[/code] if no incoming connection exists on that port. ## The connected node may also return [code]null[/code]. -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]) - - -## Asynchronous version of [method request_value]. func request_value_async(on_port: int) -> Variant: if !incoming_connections.has(on_port): return null @@ -305,29 +295,21 @@ func _post_load() -> void: ## 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: +## 1. The direct result of [method request value], called asynchronously. [br] +## 2. The result of [method Port.value_callback], if it's not equal to [param empty_value]. [br] +## 3. The input [Port] at index [param input_port]'s stored [member Port.value], if it's not equal to [param empty_value]. [br] +## 4. [code]null[/code].[br] +func resolve_input_port_value_async(input_port: int, empty_value: Variant = null) -> Variant: + var request = await request_value_async(input_port) + if request != null: + return request + elif get_input_ports()[input_port].value_callback.get_object() && get_input_ports()[input_port].value_callback.call() != empty_value: return get_input_ports()[input_port].value_callback.call() - elif get_input_ports()[input_port].value != null: + elif get_input_ports()[input_port].value != empty_value: return get_input_ports()[input_port].value else: return null -func resolve_input_port_value_async(input_port: int) -> Variant: - if await request_value_async(input_port) != null: - return await request_value_async(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: diff --git a/classes/deck/nodes/general/array_get_index.gd b/classes/deck/nodes/general/array_get_index.gd index c330f88..7d9a18d 100644 --- a/classes/deck/nodes/general/array_get_index.gd +++ b/classes/deck/nodes/general/array_get_index.gd @@ -27,12 +27,12 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - var arr = request_value(0) + var arr = await request_value_async(0) if arr == null: DeckHolder.logger.log_node("Array index: Input array is null. Returning null.", Logger.LogType.ERROR) return null - var idx := int(resolve_input_port_value(1)) + var idx := int(await resolve_input_port_value_async(1)) if idx < 0: idx = (arr as Array).size() + idx diff --git a/classes/deck/nodes/general/dictionary_get_key.gd b/classes/deck/nodes/general/dictionary_get_key.gd index 0f73304..8d4ef23 100644 --- a/classes/deck/nodes/general/dictionary_get_key.gd +++ b/classes/deck/nodes/general/dictionary_get_key.gd @@ -27,11 +27,11 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var d = request_value(0) + var d = await request_value_async(0) if d == null: return null - var key = resolve_input_port_value(1) + var key = await resolve_input_port_value_async(1) if key == null: return null diff --git a/classes/deck/nodes/general/expression_node.gd b/classes/deck/nodes/general/expression_node.gd index 0f3eada..2c3f605 100644 --- a/classes/deck/nodes/general/expression_node.gd +++ b/classes/deck/nodes/general/expression_node.gd @@ -40,7 +40,7 @@ func _value_request(_from_port : int) -> Variant: return null - var res = expr.execute([_belonging_to.variable_stack, request_value(0)]) + var res = expr.execute([_belonging_to.variable_stack, await request_value_async(0)]) if expr.has_execute_failed(): DeckHolder.logger.log_node("Expression Execution Failed: %s" % text, Logger.LogType.ERROR) diff --git a/classes/deck/nodes/general/if_true.gd b/classes/deck/nodes/general/if_true.gd index 3ab91ba..fcba112 100644 --- a/classes/deck/nodes/general/if_true.gd +++ b/classes/deck/nodes/general/if_true.gd @@ -29,9 +29,5 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void if to_input_port != 1: return - if resolve_input_port_value(0): + if await resolve_input_port_value_async(0): send(0, data, extra_data) - elif ports[0].value: - send(0, data, extra_data) - - diff --git a/classes/deck/nodes/general/is_equal.gd b/classes/deck/nodes/general/is_equal.gd index 61ce909..d1169fd 100644 --- a/classes/deck/nodes/general/is_equal.gd +++ b/classes/deck/nodes/general/is_equal.gd @@ -28,7 +28,7 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - var a = resolve_input_port_value(0) - var b = resolve_input_port_value(1) + var a = await resolve_input_port_value_async(0) + var b = await resolve_input_port_value_async(1) return a == b diff --git a/classes/deck/nodes/general/print.gd b/classes/deck/nodes/general/print.gd index aad9b61..67a5e7f 100644 --- a/classes/deck/nodes/general/print.gd +++ b/classes/deck/nodes/general/print.gd @@ -36,7 +36,7 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void if to_input_port != 1: return - var data_to_print = str(resolve_input_port_value(0)) + var data_to_print = str(await resolve_input_port_value_async(0)) if data_to_print == null: data_to_print = str(data) if (data_to_print as String).is_empty(): diff --git a/classes/deck/nodes/general/process_node.gd b/classes/deck/nodes/general/process_node.gd index 8ed01b5..90fe1a6 100644 --- a/classes/deck/nodes/general/process_node.gd +++ b/classes/deck/nodes/general/process_node.gd @@ -32,7 +32,7 @@ func _event_received(event_name: StringName, event_data: Dictionary = {}) -> voi if event_name != &"process": return - var run = resolve_input_port_value(0) == true + var run = await resolve_input_port_value_async(0) == true if !run: return diff --git a/classes/deck/nodes/general/set_deck_var.gd b/classes/deck/nodes/general/set_deck_var.gd index cc9e7d9..50e72aa 100644 --- a/classes/deck/nodes/general/set_deck_var.gd +++ b/classes/deck/nodes/general/set_deck_var.gd @@ -38,21 +38,10 @@ func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> vo if to_input_port != 2: return - var var_name: String = resolve_input_port_value(0) - var var_value: Variant = resolve_input_port_value(1) + var var_name: String = await resolve_input_port_value_async(0) + var var_value: Variant = await resolve_input_port_value_async(1) #_belonging_to.variable_stack[var_name] = var_value _belonging_to.set_variable(var_name, var_value) send(0, var_value) - -# 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) - 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/general/string_split.gd b/classes/deck/nodes/general/string_split.gd index 4785b4c..5b59da2 100644 --- a/classes/deck/nodes/general/string_split.gd +++ b/classes/deck/nodes/general/string_split.gd @@ -28,11 +28,11 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - if !resolve_input_port_value(1): + var delimiter = await resolve_input_port_value_async(1) + if !delimiter: DeckHolder.logger.log_node("Split: could not resolve delimiter. Returning: []", Logger.LogType.ERROR) return [] - var string := str(resolve_input_port_value(0)) - var del := str(resolve_input_port_value(1)) + var string = await resolve_input_port_value_async(0) - return Array(string.split(del)) + return Array(string.split(delimiter)) diff --git a/classes/deck/nodes/group/group_input_node.gd b/classes/deck/nodes/group/group_input_node.gd index 1be0115..f8195c3 100644 --- a/classes/deck/nodes/group/group_input_node.gd +++ b/classes/deck/nodes/group/group_input_node.gd @@ -77,4 +77,4 @@ func _post_load() -> void: func _value_request(from_port: int) -> Variant: - return group_node.request_value(group_node.get_input_ports()[from_port].index_of_type) + return await group_node.request_value_async(group_node.get_input_ports()[from_port].index_of_type) diff --git a/classes/deck/nodes/group/group_node.gd b/classes/deck/nodes/group/group_node.gd index c09a21a..fbcaece 100644 --- a/classes/deck/nodes/group/group_node.gd +++ b/classes/deck/nodes/group/group_node.gd @@ -78,4 +78,4 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []): func _value_request(from_port: int) -> Variant: - return output_node.request_value(from_port) + return await output_node.request_value_async(from_port) diff --git a/classes/deck/nodes/math/vector_add.gd b/classes/deck/nodes/math/vector_add.gd index 04f0465..0248445 100644 --- a/classes/deck/nodes/math/vector_add.gd +++ b/classes/deck/nodes/math/vector_add.gd @@ -24,8 +24,8 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var va = request_value(0) - var vb = request_value(1) + var va = await request_value_async(0) + var vb = await request_value_async(1) if !va || !vb: DeckHolder.logger.log_node("Vector Add: one of the vectors is invalid.", Logger.LogType.ERROR) diff --git a/classes/deck/nodes/math/vector_compose.gd b/classes/deck/nodes/math/vector_compose.gd index fd8292f..a24b834 100644 --- a/classes/deck/nodes/math/vector_compose.gd +++ b/classes/deck/nodes/math/vector_compose.gd @@ -27,6 +27,6 @@ func _init() -> void: func _value_request(_on_port: int) -> Dictionary: - var x = float(resolve_input_port_value(0)) - var y = float(resolve_input_port_value(1)) + var x = float(await resolve_input_port_value_async(0)) + var y = float(await resolve_input_port_value_async(1)) return {"x": x, "y": y} diff --git a/classes/deck/nodes/math/vector_decompose.gd b/classes/deck/nodes/math/vector_decompose.gd index fe45c82..89cabb3 100644 --- a/classes/deck/nodes/math/vector_decompose.gd +++ b/classes/deck/nodes/math/vector_decompose.gd @@ -25,7 +25,7 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - var v = request_value(0) + var v = await request_value_async(0) if !v: DeckHolder.logger.log_node("Vector Decompose: the vector is invalid.", Logger.LogType.ERROR) return null diff --git a/classes/deck/nodes/math/vector_dot.gd b/classes/deck/nodes/math/vector_dot.gd index df72f15..3763b4c 100644 --- a/classes/deck/nodes/math/vector_dot.gd +++ b/classes/deck/nodes/math/vector_dot.gd @@ -25,8 +25,8 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var va = request_value(0) - var vb = request_value(1) + var va = await request_value_async(0) + var vb = await request_value_async(1) if !va || !vb: DeckHolder.logger.log_node("Vector Dot: one of the vectors is invalid.", Logger.LogType.ERROR) diff --git a/classes/deck/nodes/math/vector_multiply.gd b/classes/deck/nodes/math/vector_multiply.gd index 8c2ce46..9d415f2 100644 --- a/classes/deck/nodes/math/vector_multiply.gd +++ b/classes/deck/nodes/math/vector_multiply.gd @@ -26,7 +26,7 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var v = request_value(0) + var v = await request_value_async(0) if !v: DeckHolder.logger.log_node("Vector Mult: the vector is invalid.", Logger.LogType.ERROR) @@ -36,6 +36,6 @@ func _value_request(_on_port: int) -> Variant: DeckHolder.logger.log_node("Vector Mult: the vector is invalid.", Logger.LogType.ERROR) return null - var s = float(resolve_input_port_value(1)) + var s = float(await resolve_input_port_value_async(1)) return {"x": v.x * s, "y": v.y * s} diff --git a/classes/deck/nodes/math/vector_normalize.gd b/classes/deck/nodes/math/vector_normalize.gd index a683e53..327593a 100644 --- a/classes/deck/nodes/math/vector_normalize.gd +++ b/classes/deck/nodes/math/vector_normalize.gd @@ -21,7 +21,7 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var v = request_value(0) + var v = await request_value_async(0) if !v: DeckHolder.logger.log_node("Vector Normalize: the vector is invalid.", Logger.LogType.ERROR) return null diff --git a/classes/deck/nodes/math/vector_subtract.gd b/classes/deck/nodes/math/vector_subtract.gd index 8432839..8867fed 100644 --- a/classes/deck/nodes/math/vector_subtract.gd +++ b/classes/deck/nodes/math/vector_subtract.gd @@ -24,8 +24,8 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var va = request_value(0) - var vb = request_value(1) + var va = await request_value_async(0) + var vb = await request_value_async(1) if !va || !vb: DeckHolder.logger.log_node("Vector Sub: one of the vectors is invalid.", Logger.LogType.ERROR) diff --git a/classes/deck/nodes/obs/obs_decompose_transform.gd b/classes/deck/nodes/obs/obs_decompose_transform.gd index af159c4..9af1163 100644 --- a/classes/deck/nodes/obs/obs_decompose_transform.gd +++ b/classes/deck/nodes/obs/obs_decompose_transform.gd @@ -30,7 +30,7 @@ func _init() -> void: func _value_request(on_port: int) -> Variant: - var t = request_value(0) + var t = await request_value_async(0) if t == null: return null diff --git a/classes/deck/nodes/obs/obs_search_source.gd b/classes/deck/nodes/obs/obs_search_source.gd index f65ae00..7215863 100644 --- a/classes/deck/nodes/obs/obs_search_source.gd +++ b/classes/deck/nodes/obs/obs_search_source.gd @@ -37,21 +37,16 @@ func _value_request(_on_output_port: int) -> Variant: if noobs == null: noobs = Connections.obs_websocket - var scene_name: String - if request_value(0) != null: - scene_name = request_value(0) - elif get_input_ports()[0].value_callback.get_object() && get_input_ports()[0].value_callback.call() != "": - scene_name = get_input_ports()[0].value_callback.call() - if scene_name.is_empty(): + var scene_name_req = await resolve_input_port_value_async(0, "") + if scene_name_req == null: return null - - var source_name: String - if request_value(1) != null: - source_name = request_value(1) - elif get_input_ports()[1].value_callback.get_object() && get_input_ports()[1].value_callback.call() != "": - source_name = get_input_ports()[1].value_callback.call() - if source_name.is_empty(): + + var source_name_req = await resolve_input_port_value_async(1, "") + if source_name_req == null: return null + + var scene_name: String = scene_name_req + var source_name: String = source_name_req if cached_scene_name == scene_name && cached_source_name == scene_name: return cached_id diff --git a/classes/deck/nodes/obs/obs_set_source_transform.gd b/classes/deck/nodes/obs/obs_set_source_transform.gd index 7bb6cc9..a3c3496 100644 --- a/classes/deck/nodes/obs/obs_set_source_transform.gd +++ b/classes/deck/nodes/obs/obs_set_source_transform.gd @@ -57,27 +57,26 @@ func _receive(to_input_port: int, _data: Variant, _extra_data: Array = []) -> vo if lock: return + var scene_name_req = await resolve_input_port_value_async(InputPorts.SCENE_NAME, "") + if scene_name_req == null: + return + var scene_name: String - if request_value(InputPorts.SCENE_NAME) != null: - scene_name = request_value(InputPorts.SCENE_NAME) - elif get_input_ports()[InputPorts.SCENE_NAME].value_callback.get_object() && get_input_ports()[InputPorts.SCENE_NAME].value_callback.call() != "": - scene_name = get_input_ports()[InputPorts.SCENE_NAME].value_callback.call() if scene_name.is_empty(): return - var source_id: float - var res_as = await request_value_async(InputPorts.SOURCE_ID) - if res_as != null: - source_id = res_as - elif get_input_ports()[InputPorts.SOURCE_ID].value_callback.get_object() && get_input_ports()[InputPorts.SOURCE_ID].value_callback.call() != null: - source_id = get_input_ports()[InputPorts.SOURCE_ID].value_callback.call() + var source_id_req = await resolve_input_port_value_async(InputPorts.SOURCE_ID) + if source_id_req == null: + return + + var source_id: float = source_id_req - var xform: Dictionary - if request_value(InputPorts.XFORM) != null: - xform = request_value(InputPorts.XFORM) - elif get_input_ports()[InputPorts.XFORM].value_callback.get_object() && get_input_ports()[InputPorts.XFORM].value_callback.call() != null: - xform = get_input_ports()[InputPorts.XFORM].value_callback.call() + var xform_req = await resolve_input_port_value_async(InputPorts.XFORM) + if xform_req == null: + return + + var xform: Dictionary = xform_req if xform.is_empty(): return diff --git a/classes/deck/nodes/obs/obs_switch_scene.gd b/classes/deck/nodes/obs/obs_switch_scene.gd index ce635b1..ab57754 100644 --- a/classes/deck/nodes/obs/obs_switch_scene.gd +++ b/classes/deck/nodes/obs/obs_switch_scene.gd @@ -32,11 +32,11 @@ func _receive(on_input_port: int, _data: Variant, _extra_data: Array = []) -> vo if noobs == null: noobs = Connections.obs_websocket - var scene_name: String - if request_value(0) != null: - scene_name = request_value(0) - elif get_input_ports()[0].value_callback.get_object() && get_input_ports()[0].value_callback.call() != "": - scene_name = get_input_ports()[0].value_callback.call() + var scene_name_req = await resolve_input_port_value_async(0, "") + if scene_name_req == null: + return + + var scene_name: String = scene_name_req if scene_name.is_empty(): return diff --git a/classes/deck/nodes/obs/obs_vector_to_position.gd b/classes/deck/nodes/obs/obs_vector_to_position.gd index c29b7fa..4d82a18 100644 --- a/classes/deck/nodes/obs/obs_vector_to_position.gd +++ b/classes/deck/nodes/obs/obs_vector_to_position.gd @@ -20,7 +20,7 @@ func _init() -> void: func _value_request(_on_port: int) -> Variant: - var v = request_value(0) + var v = await request_value_async(0) if !v: return null diff --git a/classes/deck/nodes/twitch/twitch_request_user_info.gd b/classes/deck/nodes/twitch/twitch_request_user_info.gd index 5b3b9a9..b99e856 100644 --- a/classes/deck/nodes/twitch/twitch_request_user_info.gd +++ b/classes/deck/nodes/twitch/twitch_request_user_info.gd @@ -42,8 +42,8 @@ func switch_user_input_type(value): func _value_request(from_port): - var user_input = resolve_input_port_value(0) - var as_id = resolve_input_port_value(1) + var user_input = await resolve_input_port_value_async(0) + var as_id = await resolve_input_port_value_async(1) var req_url := "https://api.twitch.tv/helix/users?" if as_id: diff --git a/classes/deck/nodes/twitch/twitch_send_chat.gd b/classes/deck/nodes/twitch/twitch_send_chat.gd index a3ed598..9db5a58 100644 --- a/classes/deck/nodes/twitch/twitch_send_chat.gd +++ b/classes/deck/nodes/twitch/twitch_send_chat.gd @@ -35,8 +35,8 @@ func _receive(to_input_port, data: Variant, extra_data: Array = []): return - var msg = resolve_input_port_value(0) - var channel = resolve_input_port_value(1) + var msg = await resolve_input_port_value_async(0) + var channel = await resolve_input_port_value_async(1) if channel == null: