mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
receive callbacks
This commit is contained in:
parent
39a18a4087
commit
6b43e807d6
5 changed files with 64 additions and 12 deletions
|
@ -4,15 +4,24 @@ extends DeckNode
|
|||
func _init() -> void:
|
||||
add_input_port(
|
||||
Deck.Types.STRING,
|
||||
"Input",
|
||||
"Text to print",
|
||||
"field"
|
||||
)
|
||||
|
||||
add_input_port(
|
||||
Deck.Types.BOOL,
|
||||
"Trigger",
|
||||
"button"
|
||||
)
|
||||
|
||||
name = "Print"
|
||||
|
||||
|
||||
func _receive(_to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
# we only have one port, so we can skip checking which port we received on
|
||||
var data_to_print = data.get_value()
|
||||
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
||||
if to_port != 1:
|
||||
return
|
||||
|
||||
# var data_to_print = data.get_value()
|
||||
var data_to_print = input_ports[0].value_callback.call()
|
||||
print(data_to_print)
|
||||
print("extra data: ", extra_data)
|
||||
|
|
|
@ -3,9 +3,15 @@ class_name Port
|
|||
var type: Deck.Types
|
||||
var label: String
|
||||
var descriptor: String
|
||||
var value_callback: Callable
|
||||
|
||||
|
||||
func _init(p_type: Deck.Types, p_label: String, p_descriptor: String = "") -> void:
|
||||
func _init(
|
||||
p_type: Deck.Types,
|
||||
p_label: String,
|
||||
p_descriptor: String = "",
|
||||
p_value_callback: Callable = Callable()) -> void:
|
||||
type = p_type
|
||||
label = p_label
|
||||
descriptor = p_descriptor
|
||||
value_callback = p_value_callback
|
||||
|
|
|
@ -12,6 +12,10 @@ func get_value() -> Variant:
|
|||
return _value
|
||||
|
||||
|
||||
func set_value(new_value: Variant) -> void:
|
||||
_value = new_value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
return null
|
||||
|
||||
|
@ -32,6 +36,10 @@ class DeckTypeError extends DeckType:
|
|||
|
||||
|
||||
class DeckTypeNumeric extends DeckType:
|
||||
func _init(value: float = 0.0) -> void:
|
||||
_value = value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
if other is DeckTypeNumeric:
|
||||
return other
|
||||
|
@ -58,6 +66,10 @@ class DeckTypeNumeric extends DeckType:
|
|||
|
||||
|
||||
class DeckTypeString extends DeckType:
|
||||
func _init(value: String = "") -> void:
|
||||
_value = value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
if other is DeckTypeString:
|
||||
return other
|
||||
|
@ -67,6 +79,10 @@ class DeckTypeString extends DeckType:
|
|||
|
||||
|
||||
class DeckTypeBool extends DeckType:
|
||||
func _init(value: bool = false) -> void:
|
||||
_value = value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
if other is DeckTypeBool:
|
||||
return other
|
||||
|
@ -83,6 +99,10 @@ class DeckTypeBool extends DeckType:
|
|||
|
||||
|
||||
class DeckTypeArray extends DeckType:
|
||||
func _init(value: Array = []) -> void:
|
||||
_value = value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
if other is DeckTypeString:
|
||||
var inst := DeckTypeArray.new()
|
||||
|
@ -95,6 +115,10 @@ class DeckTypeArray extends DeckType:
|
|||
|
||||
|
||||
class DeckTypeDictionary extends DeckType:
|
||||
func _init(value: Dictionary = {}) -> void:
|
||||
_value = value
|
||||
|
||||
|
||||
static func from(other: DeckType):
|
||||
if other is DeckTypeString:
|
||||
var inst := DeckTypeDictionary.new()
|
||||
|
|
|
@ -24,11 +24,12 @@ func add_label(text: String) -> void:
|
|||
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
|
||||
|
||||
func add_field() -> void:
|
||||
func add_field(placeholder: String = "") -> void:
|
||||
var le := LineEdit.new()
|
||||
add_child(le)
|
||||
move_child(le, 1)
|
||||
le.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
le.placeholder_text = placeholder
|
||||
|
||||
le.text_changed.connect(
|
||||
func(new_text: String):
|
||||
|
|
|
@ -13,15 +13,20 @@ var port_drawer_scene := preload("res://port_drawer.tscn")
|
|||
|
||||
func _ready() -> void:
|
||||
name_label.text = node.name
|
||||
for input_port in node.input_ports:
|
||||
for i in node.input_ports.size():
|
||||
var input_port := node.input_ports[i]
|
||||
var port_drawer: PortDrawer = port_drawer_scene.instantiate()
|
||||
elements_container.add_child(port_drawer)
|
||||
port_drawer.set_input_enabled(true)
|
||||
match input_port.descriptor:
|
||||
"field":
|
||||
port_drawer.add_field()
|
||||
# "button":
|
||||
# port_drawer.add_button(input_port.label)
|
||||
port_drawer.add_field(input_port.label)
|
||||
input_port.value_callback = port_drawer.get_text
|
||||
"button":
|
||||
port_drawer.add_button(input_port.label)
|
||||
port_drawer.button_pressed.connect(func():
|
||||
node._receive(i, DeckType.DeckTypeString.new("memes"))
|
||||
)
|
||||
_:
|
||||
port_drawer.add_label(input_port.label)
|
||||
|
||||
|
@ -32,7 +37,14 @@ func _ready() -> void:
|
|||
var port_drawer: PortDrawer = elements_container.get_child(i)
|
||||
port_drawer.set_output_enabled(true)
|
||||
var output_port := node.output_ports[i]
|
||||
if output_port.descriptor == "button":
|
||||
match output_port.descriptor:
|
||||
"field":
|
||||
port_drawer.add_field(output_port.label)
|
||||
output_port.value_callback = port_drawer.get_text
|
||||
"button":
|
||||
port_drawer.add_button(output_port.label)
|
||||
_:
|
||||
port_drawer.add_label(output_port.label)
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue