mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
51652ef277
first part of addressing #59 every `Port` now has a `usage_type` field that indicates whether it can be used for triggers (eg. sending and receiving events), value requests, or both. `Deck` has an additional method to validate if a potential connection is legal, which checks for the following in order: 1. the source and target nodes are not the same node; 2. the port usage is valid (trigger to trigger, value to value, both to any); 3. the port types are compatible 4. the connection doesn't already exist all node ports by default use the "both" usage, since that will be the most common use case (especially in cases where an input port can accept either a trigger and a value request but the output can only send one type), but it can be specified as an optional argument in `add_[input|output]_port()` usage types are represented in the renderer by different port icons: ![image](/attachments/28d3cfe9-c62c-4dd4-937d-64dbe87cb205) there is a reference implementation in the Compare Values and Twitch Chat Received nodes, since those were used as examples in #59. other nodes will be added as a separate PR later if this is merged, since behavior will vary greatly per node. Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/69 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
58 lines
1.2 KiB
GDScript
58 lines
1.2 KiB
GDScript
# (c) 2023-present Eroax
|
|
# (c) 2023-present Yagich
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
extends DeckNode
|
|
|
|
var username := ""
|
|
var message := ""
|
|
var channel := ""
|
|
var tags := {}
|
|
|
|
|
|
func _init():
|
|
name = "Twitch Chat Received"
|
|
node_type = "twitch_chat_received"
|
|
description = "Receives Twitch chat events from a Twitch connection."
|
|
|
|
add_output_port(DeckType.Types.STRING, "Username", "", Port.UsageType.TRIGGER)
|
|
add_output_port(DeckType.Types.STRING, "Message", "", Port.UsageType.TRIGGER)
|
|
add_output_port(DeckType.Types.STRING, "Channel", "", Port.UsageType.TRIGGER)
|
|
add_output_port(DeckType.Types.DICTIONARY, "Tags", "", Port.UsageType.TRIGGER)
|
|
|
|
add_output_port(
|
|
DeckType.Types.BOOL,
|
|
"On receive"
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
func _value_request(on_port: int) -> Variant:
|
|
match on_port:
|
|
0:
|
|
return username
|
|
1:
|
|
return message
|
|
2:
|
|
return channel
|
|
3:
|
|
return tags
|
|
_:
|
|
return null
|