From 2d5fcd25f628415dd11ef0f0ba94381275b4595e Mon Sep 17 00:00:00 2001 From: Eroax Date: Mon, 26 Feb 2024 11:36:19 +0000 Subject: [PATCH] Reworks Twitch Nodes to work with the new Triggers Workflow. (#82) Closes #59 by reworking Twitch Nodes to use the new Trigger workflow that allows inputs that trigger through Ports with Port.UsageType.BOTH as well the functionality for Port.UsageType.VALUE_REQUEST and Port.UsageType.TRIGGER. Co-authored-by: Eroax Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/82 --- addons/no_twitch/chat_socket.gd | 8 ++- addons/no_twitch/twitch_connection.gd | 5 +- classes/deck/nodes/math/vector_add.gd | 37 +++++++++- classes/deck/nodes/math/vector_compose.gd | 17 +++++ classes/deck/nodes/math/vector_decompose.gd | 14 +++- classes/deck/nodes/math/vector_dot.gd | 42 ++++++++++-- classes/deck/nodes/math/vector_multiply.gd | 45 ++++++++++-- classes/deck/nodes/math/vector_normalize.gd | 18 ++++- classes/deck/nodes/math/vector_subtract.gd | 43 ++++++++++-- .../deck/nodes/twitch/twitch_account_info.gd | 8 +-- .../twitch_add_eventsub_subscription.gd | 68 +++++++++++++------ .../deck/nodes/twitch/twitch_chat_received.gd | 19 +++--- .../nodes/twitch/twitch_eventsub_event.gd | 24 +++---- classes/deck/nodes/twitch/twitch_join_chat.gd | 15 ++-- .../deck/nodes/twitch/twitch_leave_chat.gd | 15 ++-- .../twitch_remove_eventsub_subscription.gd | 30 +++++--- .../nodes/twitch/twitch_request_user_info.gd | 41 +++++++++-- classes/deck/nodes/twitch/twitch_send_chat.gd | 48 ++++++++++--- classes/types/deck_type.gd | 10 +++ 19 files changed, 404 insertions(+), 103 deletions(-) diff --git a/addons/no_twitch/chat_socket.gd b/addons/no_twitch/chat_socket.gd index b5ef776..fc8ef21 100644 --- a/addons/no_twitch/chat_socket.gd +++ b/addons/no_twitch/chat_socket.gd @@ -148,6 +148,12 @@ func send_chat(msg : String, channel : String = ""): if channel.is_empty(): + if channels.is_empty(): + + push_error("NoTwitch Error: No Twitch channels have been joined.") + return + + channel = channels[0] @@ -166,6 +172,6 @@ func join_chat(channel : String): ## Utility function that handles leaving the supplied [param channel]'s chat. func leave_chat(channel : String): - send_chat("PART #" + channel) + send_text("PART #" + channel) channels.erase(channel) diff --git a/addons/no_twitch/twitch_connection.gd b/addons/no_twitch/twitch_connection.gd index d7a6d73..edd74e6 100644 --- a/addons/no_twitch/twitch_connection.gd +++ b/addons/no_twitch/twitch_connection.gd @@ -315,8 +315,11 @@ class HTTPResponse: func request_complete(result: int, response_code: int, headers: PackedStringArray, body: PackedByteArray, http, storage): var info : Dictionary - if !body.is_empty(): + var str = body.get_string_from_utf8() + if !body.is_empty() and !JSON.parse_string(str) == null: + info = JSON.parse_string(body.get_string_from_utf8()) + info["result"] = result info["code"] = response_code diff --git a/classes/deck/nodes/math/vector_add.gd b/classes/deck/nodes/math/vector_add.gd index ed015d9..c23a29d 100644 --- a/classes/deck/nodes/math/vector_add.gd +++ b/classes/deck/nodes/math/vector_add.gd @@ -22,25 +22,56 @@ func _init() -> void: "Result" ) +## Handles Trigger inputs, calculates. +func _receive(port : int, data : Variant) -> void: + + var va = data + if !DeckType.is_valid_vector(data): + + DeckHolder.logger.log_node("Vector Add: Port %d: Supplied data was not a valid Vector. Please ensure it is a Dictionary with keys 'x' and 'y'" % port) + return + + var vb + if port == 0: + + vb = await request_value_async(1) + + else: + + vb = await request_value_async(0) + + var added = add_vectors(va, vb) + + if added is Dictionary: + + send(0, added) + + func _value_request(_on_port: int) -> Variant: var va = await request_value_async(0) var vb = await request_value_async(1) + + return add_vectors(va, vb) + +func add_vectors(va, vb): + if not va or not vb: DeckHolder.logger.log_node("Vector Add: one of the vectors is invalid.", Logger.LogType.ERROR) return null - if not (va as Dictionary).has("x") or not (va as Dictionary).has("y"): + if !DeckType.is_valid_vector(va): DeckHolder.logger.log_node("Vector Add: one of the vectors is invalid.", Logger.LogType.ERROR) return null - if not (vb as Dictionary).has("x") or not (vb as Dictionary).has("y"): + if !DeckType.is_valid_vector(vb): DeckHolder.logger.log_node("Vector Add: one of the vectors is invalid.", Logger.LogType.ERROR) return null var res := {} res["x"] = va["x"] + vb["x"] res["y"] = va["y"] + vb["y"] - + return res + diff --git a/classes/deck/nodes/math/vector_compose.gd b/classes/deck/nodes/math/vector_compose.gd index a24b834..b1ec0b9 100644 --- a/classes/deck/nodes/math/vector_compose.gd +++ b/classes/deck/nodes/math/vector_compose.gd @@ -25,6 +25,23 @@ func _init() -> void: "Vector" ) +func _receive(port : int, data : Variant) -> void: + + var x + var y + if port == 0: + + x = data + y = await resolve_input_port_value_async(1) + + else: + + y = data + x = await resolve_input_port_value_async(0) + + + send(0, {"x" : float(x), "y" : float(y)}) + func _value_request(_on_port: int) -> Dictionary: var x = float(await resolve_input_port_value_async(0)) diff --git a/classes/deck/nodes/math/vector_decompose.gd b/classes/deck/nodes/math/vector_decompose.gd index aee3c05..46763c6 100644 --- a/classes/deck/nodes/math/vector_decompose.gd +++ b/classes/deck/nodes/math/vector_decompose.gd @@ -24,13 +24,25 @@ func _init() -> void: ) +func _receive(port : int, data : Variant) -> void: + + if !data or !DeckType.is_valid_vector(data): + DeckHolder.logger.log_node("Vector Decompose: the vector is invalid.", Logger.LogType.ERROR) + return + + + var id = UUID.v4() + send(0, data.x, id) + send(1, data.y, id) + + func _value_request(on_port: int) -> Variant: var v = await request_value_async(0) if not v: DeckHolder.logger.log_node("Vector Decompose: the vector is invalid.", Logger.LogType.ERROR) return null - if not (v as Dictionary).has("x") or not (v as Dictionary).has("y"): + if !DeckType.is_valid_vector(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 e0ee5a4..aef1aee 100644 --- a/classes/deck/nodes/math/vector_dot.gd +++ b/classes/deck/nodes/math/vector_dot.gd @@ -24,20 +24,52 @@ func _init() -> void: ) +func _receive(port : int, data : Variant) -> void: + + if !DeckType.is_valid_vector(data): + + DeckHolder.logger.log_node("Vector Dot: Port %d: Supplied data was not a valid Vector. Please ensure it is a Dictionary with keys 'x' and 'y'" % port) + return + + var va = data + var vb + + if port == 0: + + vb = await resolve_input_port_value_async(1) + + else: + + vb = await resolve_input_port_value_async(0) + + + var dot = dot_vectors(va, vb) + if dot: + + send(0, dot) + + + func _value_request(_on_port: int) -> Variant: var va = await request_value_async(0) var vb = await request_value_async(1) + + return dot_vectors(va, vb) + +func dot_vectors(va, vb): + if not va or not vb: DeckHolder.logger.log_node("Vector Dot: one of the vectors is invalid.", Logger.LogType.ERROR) return null - - if not (va as Dictionary).has("x") or not (va as Dictionary).has("y"): + + if !DeckType.is_valid_vector(va): DeckHolder.logger.log_node("Vector Dot: one of the vectors is invalid.", Logger.LogType.ERROR) return null - - if not (vb as Dictionary).has("x") or not (vb as Dictionary).has("y"): + + if !DeckType.is_valid_vector(vb): DeckHolder.logger.log_node("Vector Dot: one of the vectors is invalid.", Logger.LogType.ERROR) return null - + return va.x * vb.x + va.y * vb.y + diff --git a/classes/deck/nodes/math/vector_multiply.gd b/classes/deck/nodes/math/vector_multiply.gd index 0654b87..e7295c9 100644 --- a/classes/deck/nodes/math/vector_multiply.gd +++ b/classes/deck/nodes/math/vector_multiply.gd @@ -25,17 +25,48 @@ func _init() -> void: ) +func _receive(port : int, data : Variant) -> void: + + var vec + var scale + + if port == 0: + + vec = data + scale = float(await resolve_input_port_value_async(1)) + + else: + + scale = data + vec = await request_value_async(0) + + + var multiplied = multiply_by_scalar(vec, scale) + if multiplied is Dictionary: + + send(0, multiplied) + + + func _value_request(_on_port: int) -> Variant: - var v = await request_value_async(0) + + var vec = await request_value_async(0) + var scale = float(await resolve_input_port_value_async(1)) + + return multiply_by_scalar(vec, scale) + - if not v: + +func multiply_by_scalar(vec, scale): + + if not vec: DeckHolder.logger.log_node("Vector Mult: the vector is invalid.", Logger.LogType.ERROR) return null - - if not (v as Dictionary).has("x") or not (v as Dictionary).has("y"): + + if !DeckType.is_valid_vector(vec): DeckHolder.logger.log_node("Vector Mult: the vector is invalid.", Logger.LogType.ERROR) return null + + return {"x": vec.x * scale, "y": vec.y * scale} + - 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 2f0f69c..def01c3 100644 --- a/classes/deck/nodes/math/vector_normalize.gd +++ b/classes/deck/nodes/math/vector_normalize.gd @@ -20,13 +20,29 @@ func _init() -> void: ) +func _receive(port : int, data : Variant) -> void: + + var normalized = normalize_vector(data) + if !normalized is Dictionary: + return + + send(0, normalized) + + func _value_request(_on_port: int) -> Variant: + var v = await request_value_async(0) + + return normalize_vector(v) + + +func normalize_vector(v): + if not v: DeckHolder.logger.log_node("Vector Normalize: the vector is invalid.", Logger.LogType.ERROR) return null - if not (v as Dictionary).has("x") or not (v as Dictionary).has("y"): + if !DeckType.is_valid_vector(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 cc33038..347a137 100644 --- a/classes/deck/nodes/math/vector_subtract.gd +++ b/classes/deck/nodes/math/vector_subtract.gd @@ -23,24 +23,55 @@ func _init() -> void: ) +func _receive(port : int, data : Variant) -> void: + + var va = data + if !DeckType.is_valid_vector(data): + + DeckHolder.logger.log_node("Vector Sub: Port %d: Supplied data was not a valid Vector. Please ensure it is a Dictionary with keys 'x' and 'y'" % port) + return + + var vb + if port == 0: + + vb = await request_value_async(1) + + else: + + vb = await request_value_async(0) + + + var calc = subtract_vectors(va, vb) + + if calc is Dictionary: + + send(0, calc) + + + func _value_request(_on_port: int) -> Variant: var va = await request_value_async(0) var vb = await request_value_async(1) + + return subtract_vectors(va, vb) +func subtract_vectors(va, vb): + if not va or not vb: DeckHolder.logger.log_node("Vector Sub: one of the vectors is invalid.", Logger.LogType.ERROR) return null - - if not (va as Dictionary).has("x") or not (va as Dictionary).has("y"): + + if !DeckType.is_valid_vector(va): DeckHolder.logger.log_node("Vector Sub: one of the vectors is invalid.", Logger.LogType.ERROR) return null - - if not (vb as Dictionary).has("x") or not (vb as Dictionary).has("y"): + + if !DeckType.is_valid_vector(vb): DeckHolder.logger.log_node("Vector Sub: one of the vectors is invalid.", Logger.LogType.ERROR) return null - + var res := {} res["x"] = va["x"] - vb["x"] res["y"] = va["y"] - vb["y"] - + return res + diff --git a/classes/deck/nodes/twitch/twitch_account_info.gd b/classes/deck/nodes/twitch/twitch_account_info.gd index f002c88..8f6c711 100644 --- a/classes/deck/nodes/twitch/twitch_account_info.gd +++ b/classes/deck/nodes/twitch/twitch_account_info.gd @@ -11,10 +11,10 @@ func _init(): props_to_serialize = [] - add_output_port(DeckType.Types.STRING, "Login") - add_output_port(DeckType.Types.STRING, "Display Name") - add_output_port(DeckType.Types.STRING, "Profile Picture URL") - add_output_port(DeckType.Types.DICTIONARY, "User Dictionary") + add_output_port(DeckType.Types.STRING, "Login", "", Port.UsageType.VALUE_REQUEST) + add_output_port(DeckType.Types.STRING, "Display Name", "", Port.UsageType.VALUE_REQUEST) + add_output_port(DeckType.Types.STRING, "Profile Picture URL", "", Port.UsageType.VALUE_REQUEST) + add_output_port(DeckType.Types.DICTIONARY, "User Dictionary", "", Port.UsageType.VALUE_REQUEST) #{ #"id": "141981764", diff --git a/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd b/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd index 2efe1ea..70dcc72 100644 --- a/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd +++ b/classes/deck/nodes/twitch/twitch_add_eventsub_subscription.gd @@ -4,6 +4,14 @@ extends DeckNode +enum inputs { + + event_name, + sub_data, + add + +} + var subscription_data : Twitch_Connection.EventSub_Subscription func _init(): @@ -14,38 +22,60 @@ func _init(): props_to_serialize = [] #Event Name - add_input_port(DeckType.Types.STRING, "Event Name", "field") + add_input_port( + DeckType.Types.STRING, + "Event Name", "field" + ) #Subscription Data - add_input_port(DeckType.Types.DICTIONARY, "Subscription Data") + add_input_port( + DeckType.Types.DICTIONARY, + "Subscription Data" + ) #Trigger - add_input_port(DeckType.Types.ANY, "Add Subscription", "button") + add_input_port( + DeckType.Types.ANY, + "Add Subscription", "button", + Port.UsageType.TRIGGER + ) -func _receive(to_input_port, _data: Variant): +func _receive(to_input_port, data: Variant) -> void: - if to_input_port != 2: + var event + var sub_data + + match to_input_port: - return + inputs.event_name: + + event = str(data) + sub_data = await resolve_input_port_value_async(1) + + inputs.sub_data: + + if data == null or not data is Dictionary: + DeckHolder.logger.log_node("%s: Port %d: Incorrect Subscription Data Connected, please supply a Dictionary with condition and if needed, version. Last supplied Data was: " + str(data), Logger.LogType.ERROR) + return + + + sub_data = data + event = await resolve_input_port_value_async(0) + + inputs.add: + + event = await resolve_input_port_value_async(0) + sub_data = await resolve_input_port_value_async(1) + - var input_data = await resolve_input_port_value_async(1) - - - if input_data == null or "condition" not in input_data.keys(): - DeckHolder.logger.log_node(name + ": Incorrect Subscription Data Connected, please supply a Dictionary with condition and if needed, version. Last supplied Data was: " + str(input_data), Logger.LogType.ERROR) - return - - - var sub_type = await resolve_input_port_value_async(0) - # Creates an instance of Twitch_Connection.EventSub_Subscription to store the data with all the given inputs. - subscription_data = Twitch_Connection.EventSub_Subscription.new(sub_type, input_data.condition) + subscription_data = Twitch_Connection.EventSub_Subscription.new(event, sub_data) # Checks if the data has a version field, if so sets it on the EventSub_Subscription - if input_data.has("version"): + if sub_data.has("version"): - subscription_data.version = input_data.version + subscription_data.version = sub_data.version # Calls the connection to add the Subscription diff --git a/classes/deck/nodes/twitch/twitch_chat_received.gd b/classes/deck/nodes/twitch/twitch_chat_received.gd index 1a693ac..d831663 100644 --- a/classes/deck/nodes/twitch/twitch_chat_received.gd +++ b/classes/deck/nodes/twitch/twitch_chat_received.gd @@ -27,21 +27,22 @@ func _init(): func _event_received(event_name : StringName, event_data : Dictionary = {}): - + if event_name != &"twitch_chat": - + return - - + username = event_data.username message = event_data.message channel = event_data.channel tags = event_data - send(0, username) - send(1, message) - send(2, channel) - send(3, tags) - send(4, true) + + var id = UUID.v4() + send(0, username, id) + send(1, message, id) + send(2, channel, id) + send(3, tags, id) + send(4, true, id) func _value_request(on_port: int) -> Variant: diff --git a/classes/deck/nodes/twitch/twitch_eventsub_event.gd b/classes/deck/nodes/twitch/twitch_eventsub_event.gd index 663cc82..8132043 100644 --- a/classes/deck/nodes/twitch/twitch_eventsub_event.gd +++ b/classes/deck/nodes/twitch/twitch_eventsub_event.gd @@ -9,17 +9,16 @@ func _init(): name = "Twitch EventSub Event" node_type = name.to_snake_case() description = "Listens for a specific Event from Twitch EventSub." - + props_to_serialize = [] - + # Adds a port that allows specifying what type of event to listen for. - add_input_port(DeckType.Types.STRING, "Event Name", "field") + add_input_port(DeckType.Types.STRING, "Event Name", "field", Port.UsageType.VALUE_REQUEST) # Adds a port that outputs when the Event has been received - add_output_port(DeckType.Types.ANY, "Event Received") + add_output_port(DeckType.Types.ANY, "Event Received", "", Port.UsageType.TRIGGER) # Adds a port that outputs the data received when the Event has been received. - add_output_port(DeckType.Types.DICTIONARY, "Event Data") - - + add_output_port(DeckType.Types.DICTIONARY, "Event Data", "", Port.UsageType.BOTH) + func _event_received(event_name: StringName, event_data: Dictionary = {}): @@ -39,16 +38,17 @@ func _event_received(event_name: StringName, event_data: Dictionary = {}): cached_event_data = event_data.payload # Sends to indicate that the specified event has happened. - send(0, null) + send(0, event_data) send(1, event_data) + func _value_request(port): - + if port != 1: - + return - - + + return cached_event_data diff --git a/classes/deck/nodes/twitch/twitch_join_chat.gd b/classes/deck/nodes/twitch/twitch_join_chat.gd index 171851e..d587def 100644 --- a/classes/deck/nodes/twitch/twitch_join_chat.gd +++ b/classes/deck/nodes/twitch/twitch_join_chat.gd @@ -15,16 +15,21 @@ func _init(): add_input_port(DeckType.Types.STRING, "Channel", "field") # Adds Trigger for leaving the specified channel - add_input_port(DeckType.Types.ANY, "Join Channel", "button") + add_input_port(DeckType.Types.ANY, "Join Channel", "button", Port.UsageType.TRIGGER) -func _receive(to_input_port, _data: Variant): +func _receive(to_input_port, data: Variant): - if to_input_port != 1: + var channel + + if to_input_port == 0: - return + channel = data + + if to_input_port == 1 or not channel is String: + channel = await resolve_input_port_value_async(0) - Connections.twitch.join_channel(await resolve_input_port_value_async(0)) + Connections.twitch.join_channel(channel) diff --git a/classes/deck/nodes/twitch/twitch_leave_chat.gd b/classes/deck/nodes/twitch/twitch_leave_chat.gd index 31fdc5d..39640e8 100644 --- a/classes/deck/nodes/twitch/twitch_leave_chat.gd +++ b/classes/deck/nodes/twitch/twitch_leave_chat.gd @@ -15,16 +15,21 @@ func _init(): add_input_port(DeckType.Types.STRING, "Channel", "field") # Adds Trigger for leaving the specified channel - add_input_port(DeckType.Types.ANY, "Leave Channel", "button") + add_input_port(DeckType.Types.ANY, "Leave Channel", "button", Port.UsageType.TRIGGER) -func _receive(to_input_port, _data: Variant): +func _receive(to_input_port, data: Variant): - if to_input_port != 1: + var channel + + if to_input_port == 0: - return + channel = data + + if to_input_port == 1 or not channel is String: + channel = await resolve_input_port_value_async(0) - Connections.twitch.leave_channel(await resolve_input_port_value_async(0)) + Connections.twitch.leave_channel(channel) diff --git a/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd b/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd index b4c7287..b5b39d0 100644 --- a/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd +++ b/classes/deck/nodes/twitch/twitch_remove_eventsub_subscription.gd @@ -8,23 +8,37 @@ func _init(): name = "Twitch Remove EventSub Subscription" node_type = name.to_snake_case() description = "Removes an EventSub Subscription by it's type." - + appears_in_search = false + props_to_serialize = [] - add_input_port(DeckType.Types.STRING, "Subscription Type", "field") - add_input_port(DeckType.Types.ANY, "Remove Subscription", "button") + add_input_port( + DeckType.Types.STRING, + "Subscription Type", + "field" + ) + + add_input_port( + DeckType.Types.ANY, + "Remove Subscription", + "button" + ) + -func _receive(to_input_port, _data: Variant): +func _receive(to_input_port, data: Variant): - if to_input_port != 1: + var sub_type + if to_input_port == 0: - return + sub_type = str(data) + + else: + + sub_type = await resolve_input_port_value_async(0) - - var sub_type = await resolve_input_port_value_async(0) Connections.twitch.remove_eventsub_subscription_type(sub_type).response_completed.connect(eventsub_response_received) diff --git a/classes/deck/nodes/twitch/twitch_request_user_info.gd b/classes/deck/nodes/twitch/twitch_request_user_info.gd index d97fa0f..d147b59 100644 --- a/classes/deck/nodes/twitch/twitch_request_user_info.gd +++ b/classes/deck/nodes/twitch/twitch_request_user_info.gd @@ -12,15 +12,27 @@ func _init(): props_to_serialize = [] # Adds the User input. - add_input_port(DeckType.Types.STRING, "User Login", "field") + add_input_port( + DeckType.Types.STRING, + "User ID", + "field" + ) # Adds the Checkbox for using IDs vs Logins and sets it to true. - add_input_port(DeckType.Types.BOOL, "User Input as ID", "checkbox") + add_input_port( + DeckType.Types.BOOL, + "User Input as ID", + "checkbox", + Port.UsageType.VALUE_REQUEST + ) get_input_ports()[1].set_value(true) get_input_ports()[1].value_updated.connect(switch_user_input_type) - add_output_port(DeckType.Types.ANY, "User Info") + add_output_port( + DeckType.Types.ANY, + "User Info" + ) func switch_user_input_type(value): @@ -40,19 +52,37 @@ func switch_user_input_type(value): +func _receive(port, data) -> void: + + if not port == 0: + + return + + + data = str(data) + + var req_resp = await request_user_info(data, await resolve_input_port_value_async(1)) + send(0, req_resp) + + func _value_request(_from_port): var user_input = await resolve_input_port_value_async(0) var as_id = await resolve_input_port_value_async(1) + return await request_user_info(user_input, as_id) + + +func request_user_info(user, as_id): + var req_url := "https://api.twitch.tv/helix/users?" if as_id: - req_url += "id=" + user_input + req_url += "id=" + user else: - req_url += "login=" + user_input + req_url += "login=" + user var resp = Connections.twitch.twitch_request(req_url) @@ -62,4 +92,3 @@ func _value_request(_from_port): return data - diff --git a/classes/deck/nodes/twitch/twitch_send_chat.gd b/classes/deck/nodes/twitch/twitch_send_chat.gd index b988ad0..2220672 100644 --- a/classes/deck/nodes/twitch/twitch_send_chat.gd +++ b/classes/deck/nodes/twitch/twitch_send_chat.gd @@ -3,6 +3,13 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) extends DeckNode +enum inputs { + + message, + channel, + send + +} func _init(): name = "Twitch Send Chat" @@ -19,7 +26,6 @@ func _init(): "Channel", "field" ) - add_input_port( DeckType.Types.BOOL, "Send", @@ -28,24 +34,46 @@ func _init(): -func _receive(to_input_port, _data: Variant): +func _receive(to_input_port, data: Variant): - if to_input_port != 2: - - return - + data = str(data) - var msg = await resolve_input_port_value_async(0) - var channel = await resolve_input_port_value_async(1) + var message + var channel + match to_input_port: + + inputs.message: + + message = data + + channel = await resolve_input_port_value_async(inputs.channel) + + inputs.channel: + + channel = data + + message = await resolve_input_port_value_async(inputs.message) + + inputs.send: + + channel = await resolve_input_port_value_async(inputs.channel) + message = await resolve_input_port_value_async(inputs.message) + + if channel == null: channel = "" - if msg == null: + if message == null: return + + if message.is_empty(): + + DeckHolder.logger.log_node("Twitch Send Chat: Port %d: Supplied message was empty." % [to_input_port]) - Connections.twitch.send_chat(msg, channel) + Connections.twitch.send_chat(message, channel) + diff --git a/classes/types/deck_type.gd b/classes/types/deck_type.gd index adb91a7..7c74457 100644 --- a/classes/types/deck_type.gd +++ b/classes/types/deck_type.gd @@ -54,3 +54,13 @@ static func convert_value(value: Variant, to: Types) -> Variant: static func type_str(type: Types) -> String: return str(Types.keys()[type]) + +## Validates whether the given Dictionary is a "Vector", AKA that it has an X and a Y key. +static func is_valid_vector(dict : Variant): + + if !dict is Dictionary: + + return false + + return dict.has("x") and dict.has("y") +