mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add an API for buttons on ports (#96)
closes #91 Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/96 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
parent
715086f204
commit
677e7b36c5
19 changed files with 82 additions and 95 deletions
|
@ -80,8 +80,8 @@ func add_input_port(
|
|||
type: DeckType.Types,
|
||||
label: String,
|
||||
descriptor: String = "",
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> void:
|
||||
add_port(type, label, PortType.INPUT, get_input_ports().size(), descriptor, usage)
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> Port:
|
||||
return add_port(type, label, PortType.INPUT, get_input_ports().size(), descriptor, usage)
|
||||
|
||||
|
||||
## Add an output port to this node. Usually only used at initialization.
|
||||
|
@ -89,8 +89,8 @@ func add_output_port(
|
|||
type: DeckType.Types,
|
||||
label: String,
|
||||
descriptor: String = "",
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> void:
|
||||
add_port(type, label, PortType.OUTPUT, get_output_ports().size(), descriptor, usage)
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> Port:
|
||||
return add_port(type, label, PortType.OUTPUT, get_output_ports().size(), descriptor, usage)
|
||||
|
||||
|
||||
## Add a virtual port to this node. Usually only used at initialization.
|
||||
|
@ -98,8 +98,8 @@ func add_virtual_port(
|
|||
type: DeckType.Types,
|
||||
label: String,
|
||||
descriptor: String = "",
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> void:
|
||||
add_port(type, label, PortType.VIRTUAL, get_virtual_ports().size(), descriptor, usage)
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> Port:
|
||||
return add_port(type, label, PortType.VIRTUAL, get_virtual_ports().size(), descriptor, usage)
|
||||
|
||||
|
||||
## Add a port to this node. Usually only used at initialization.
|
||||
|
@ -108,7 +108,7 @@ func add_port(type: DeckType.Types,
|
|||
port_type: PortType,
|
||||
index_of_type: int,
|
||||
descriptor: String = "",
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> void:
|
||||
usage: Port.UsageType = Port.UsageType.BOTH) -> Port:
|
||||
var port := Port.new(type, label, ports.size(), port_type, index_of_type, descriptor, usage)
|
||||
ports.append(port)
|
||||
port_added.emit(ports.size() - 1)
|
||||
|
@ -117,6 +117,7 @@ func add_port(type: DeckType.Types,
|
|||
port_value_updated.emit(port.index, new_value)
|
||||
)
|
||||
ports_updated.emit()
|
||||
return port
|
||||
|
||||
|
||||
## Remove a port from this node.
|
||||
|
@ -305,6 +306,12 @@ func get_all_ports() -> Array[Port]:
|
|||
return ports
|
||||
|
||||
|
||||
func press_button(port_idx: int) -> void:
|
||||
var port := ports[port_idx]
|
||||
if port.descriptor.split(":")[0] == "button":
|
||||
port.button_pressed.emit()
|
||||
|
||||
|
||||
## Get a sibling node by its' ID.
|
||||
func get_node(uuid: String) -> DeckNode:
|
||||
return _belonging_to.get_node(uuid)
|
||||
|
|
|
@ -9,8 +9,11 @@ func _init() -> void:
|
|||
node_type = "button"
|
||||
description = "A button to trigger certain nodes that have a trigger input."
|
||||
|
||||
add_output_port(
|
||||
DeckType.Types.BOOL,
|
||||
var port := add_output_port(
|
||||
DeckType.Types.ANY,
|
||||
"Press me",
|
||||
"button"
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
)
|
||||
|
||||
port.button_pressed.connect(send.bind(port.index_of_type, null))
|
||||
|
|
|
@ -3,16 +3,12 @@
|
|||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
extends DeckNode
|
||||
|
||||
var times_activated := 0
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
name = "Print"
|
||||
node_type = name.to_snake_case()
|
||||
description = "Print a value to the console."
|
||||
|
||||
props_to_serialize = [&"times_activated"]
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.ANY,
|
||||
"Data to print",
|
||||
|
@ -20,32 +16,24 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Trigger",
|
||||
"button"
|
||||
)
|
||||
|
||||
add_output_port(
|
||||
DeckType.Types.BOOL,
|
||||
"On Trigger",
|
||||
"label"
|
||||
)
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
).button_pressed.connect(_receive.bind(1, null))
|
||||
|
||||
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
if to_input_port != 1:
|
||||
return
|
||||
var data_to_print := ""
|
||||
if to_input_port == 1:
|
||||
data = await resolve_input_port_value_async(0)
|
||||
|
||||
var data_to_print = str(await resolve_input_port_value_async(0))
|
||||
if data_to_print == null or (data_to_print as String).is_empty():
|
||||
if data == null:
|
||||
data_to_print = "<nothing>"
|
||||
else:
|
||||
data_to_print = str(data)
|
||||
if (data_to_print as String).is_empty():
|
||||
|
||||
if data_to_print.is_empty():
|
||||
data_to_print = "<nothing>"
|
||||
|
||||
times_activated += 1
|
||||
|
||||
# var data_to_print = input_ports[0].value_callback.call()
|
||||
#print(data_to_print)
|
||||
#print("extra data: ", extra_data)
|
||||
DeckHolder.logger.log_node(data_to_print)
|
||||
send(0, true)
|
||||
|
|
|
@ -22,11 +22,11 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Set",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
)
|
||||
).button_pressed.connect(_receive.bind(2, null))
|
||||
|
||||
add_output_port(
|
||||
DeckType.Types.ANY,
|
||||
|
|
|
@ -21,16 +21,13 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_virtual_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Refresh",
|
||||
"button"
|
||||
)
|
||||
).button_pressed.connect(refresh)
|
||||
|
||||
|
||||
func _receive(on_virtual_port: int, _data: Variant) -> void:
|
||||
if on_virtual_port != 0:
|
||||
return
|
||||
|
||||
func refresh() -> void:
|
||||
if noobs == null:
|
||||
noobs = Connections.obs_websocket
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ func _init() -> void:
|
|||
"Set",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
)
|
||||
).button_pressed.connect(_receive.bind(2, null))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -40,11 +40,11 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Set",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER
|
||||
)
|
||||
).button_pressed.connect(_receive.bind(InputPorts.SET, null))
|
||||
|
||||
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
|
|
|
@ -41,7 +41,7 @@ func _init() -> void:
|
|||
"Set",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
)
|
||||
).button_pressed.connect(_receive.bind(InputPorts.SET, null))
|
||||
|
||||
get_input_ports()[2].set_value(true)
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Switch",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
)
|
||||
).button_pressed.connect(_receive.bind(1, null))
|
||||
|
||||
|
||||
func _receive(on_input_port: int, data: Variant) -> void:
|
||||
|
|
|
@ -31,16 +31,13 @@ func _init() -> void:
|
|||
)
|
||||
|
||||
add_virtual_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Request",
|
||||
"button"
|
||||
)
|
||||
).button_pressed.connect(request)
|
||||
|
||||
|
||||
func _receive(on_virtual_port: int, _data: Variant) -> void:
|
||||
if on_virtual_port != 2:
|
||||
return
|
||||
|
||||
func request() -> void:
|
||||
if noobs == null:
|
||||
noobs = Connections.obs_websocket
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@ func _init() -> void:
|
|||
add_output_port(DeckType.Types.DICTIONARY, "dictionary", "", Port.UsageType.TRIGGER)
|
||||
add_output_port(DeckType.Types.DICTIONARY, "vector", "", Port.UsageType.TRIGGER)
|
||||
|
||||
add_input_port(DeckType.Types.ANY, "Send", "button")
|
||||
add_input_port(DeckType.Types.ANY, "Send", "button").button_pressed.connect(do)
|
||||
|
||||
|
||||
func _receive(_to_input_port: int, _data: Variant) -> void:
|
||||
func do() -> void:
|
||||
var id := UUID.v4()
|
||||
send(0, get_output_ports()[0].value, id)
|
||||
send(1, get_output_ports()[1].value, id)
|
||||
|
|
|
@ -25,19 +25,18 @@ func _init() -> void:
|
|||
add_output_port(DeckType.Types.DICTIONARY, "DICTIONARY")
|
||||
add_output_port(DeckType.Types.ANY, "ANY")
|
||||
|
||||
add_input_port(DeckType.Types.BOOL, "Send", "button")
|
||||
add_input_port(DeckType.Types.ANY, "Send", "button").button_pressed.connect(do)
|
||||
|
||||
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
if to_input_port == 6:
|
||||
func do() -> void:
|
||||
send(0, false)
|
||||
send(1, 1.0)
|
||||
send(2, "string")
|
||||
send(3, ["foo", "bar", 5.3])
|
||||
send(4, {"foo": "bar", 1: 2})
|
||||
send(5, null)
|
||||
return
|
||||
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
print("received data %s of type %s on port %s, expected type %s, converted v %s, converted type %s" % [
|
||||
data, typeof(data), to_input_port, DeckType.GODOT_TYPES_MAP[get_input_ports()[to_input_port].type],
|
||||
DeckType.convert_value(data, get_input_ports()[to_input_port].type),
|
||||
|
|
|
@ -36,9 +36,7 @@ func _init():
|
|||
DeckType.Types.ANY,
|
||||
"Add Subscription", "button",
|
||||
Port.UsageType.TRIGGER
|
||||
)
|
||||
|
||||
|
||||
).button_pressed.connect(_receive.bind(inputs.add, null))
|
||||
|
||||
|
||||
func _receive(to_input_port, data: Variant) -> void:
|
||||
|
|
|
@ -15,8 +15,12 @@ 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", Port.UsageType.TRIGGER)
|
||||
|
||||
add_input_port(
|
||||
DeckType.Types.ANY,
|
||||
"Join Channel",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER
|
||||
).button_pressed.connect(_receive.bind(1, null))
|
||||
|
||||
|
||||
func _receive(to_input_port, data: Variant):
|
||||
|
|
|
@ -15,11 +15,16 @@ 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", Port.UsageType.TRIGGER)
|
||||
add_input_port(
|
||||
DeckType.Types.ANY,
|
||||
"Leave Channel",
|
||||
"button",
|
||||
Port.UsageType.TRIGGER
|
||||
).button_pressed.connect(_receive.bind(1, null))
|
||||
|
||||
|
||||
|
||||
func _receive(to_input_port, data: Variant):
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
|
||||
var channel
|
||||
|
||||
|
|
|
@ -22,10 +22,7 @@ func _init():
|
|||
DeckType.Types.ANY,
|
||||
"Remove Subscription",
|
||||
"button"
|
||||
)
|
||||
|
||||
|
||||
|
||||
).button_pressed.connect(_receive.bind(1, null))
|
||||
|
||||
|
||||
func _receive(to_input_port, data: Variant):
|
||||
|
|
|
@ -27,14 +27,14 @@ func _init():
|
|||
"field"
|
||||
)
|
||||
add_input_port(
|
||||
DeckType.Types.BOOL,
|
||||
DeckType.Types.ANY,
|
||||
"Send",
|
||||
"button"
|
||||
)
|
||||
"button",
|
||||
Port.UsageType.TRIGGER,
|
||||
).button_pressed.connect(_receive.bind(inputs.send, null))
|
||||
|
||||
|
||||
|
||||
func _receive(to_input_port, data: Variant):
|
||||
func _receive(to_input_port: int, data: Variant) -> void:
|
||||
|
||||
data = str(data)
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ var index: int
|
|||
var value: Variant
|
||||
|
||||
signal value_updated(new_value: Variant)
|
||||
signal button_pressed()
|
||||
|
||||
|
||||
func _init(
|
||||
|
|
|
@ -9,13 +9,4 @@ extends DescriptorContainer
|
|||
|
||||
func _setup(port: Port, node: DeckNode) -> void:
|
||||
button.text = port.label
|
||||
if port.port_type == DeckNode.PortType.OUTPUT:
|
||||
button.pressed.connect(
|
||||
func():
|
||||
node.send(port.index_of_type, true)
|
||||
)
|
||||
else:
|
||||
button.pressed.connect(
|
||||
func():
|
||||
node._receive(port.index_of_type, true)
|
||||
)
|
||||
button.pressed.connect(node.press_button.bind(port.index))
|
||||
|
|
Loading…
Reference in a new issue