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:
|
func _init() -> void:
|
||||||
add_input_port(
|
add_input_port(
|
||||||
Deck.Types.STRING,
|
Deck.Types.STRING,
|
||||||
"Input",
|
"Text to print",
|
||||||
"field"
|
"field"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_input_port(
|
||||||
|
Deck.Types.BOOL,
|
||||||
|
"Trigger",
|
||||||
|
"button"
|
||||||
|
)
|
||||||
|
|
||||||
name = "Print"
|
name = "Print"
|
||||||
|
|
||||||
|
|
||||||
func _receive(_to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
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
|
if to_port != 1:
|
||||||
var data_to_print = data.get_value()
|
return
|
||||||
|
|
||||||
|
# var data_to_print = data.get_value()
|
||||||
|
var data_to_print = input_ports[0].value_callback.call()
|
||||||
print(data_to_print)
|
print(data_to_print)
|
||||||
print("extra data: ", extra_data)
|
print("extra data: ", extra_data)
|
||||||
|
|
|
@ -3,9 +3,15 @@ class_name Port
|
||||||
var type: Deck.Types
|
var type: Deck.Types
|
||||||
var label: String
|
var label: String
|
||||||
var descriptor: 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
|
type = p_type
|
||||||
label = p_label
|
label = p_label
|
||||||
descriptor = p_descriptor
|
descriptor = p_descriptor
|
||||||
|
value_callback = p_value_callback
|
||||||
|
|
|
@ -12,6 +12,10 @@ func get_value() -> Variant:
|
||||||
return _value
|
return _value
|
||||||
|
|
||||||
|
|
||||||
|
func set_value(new_value: Variant) -> void:
|
||||||
|
_value = new_value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
return null
|
return null
|
||||||
|
|
||||||
|
@ -32,6 +36,10 @@ class DeckTypeError extends DeckType:
|
||||||
|
|
||||||
|
|
||||||
class DeckTypeNumeric extends DeckType:
|
class DeckTypeNumeric extends DeckType:
|
||||||
|
func _init(value: float = 0.0) -> void:
|
||||||
|
_value = value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
if other is DeckTypeNumeric:
|
if other is DeckTypeNumeric:
|
||||||
return other
|
return other
|
||||||
|
@ -58,6 +66,10 @@ class DeckTypeNumeric extends DeckType:
|
||||||
|
|
||||||
|
|
||||||
class DeckTypeString extends DeckType:
|
class DeckTypeString extends DeckType:
|
||||||
|
func _init(value: String = "") -> void:
|
||||||
|
_value = value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
if other is DeckTypeString:
|
if other is DeckTypeString:
|
||||||
return other
|
return other
|
||||||
|
@ -67,6 +79,10 @@ class DeckTypeString extends DeckType:
|
||||||
|
|
||||||
|
|
||||||
class DeckTypeBool extends DeckType:
|
class DeckTypeBool extends DeckType:
|
||||||
|
func _init(value: bool = false) -> void:
|
||||||
|
_value = value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
if other is DeckTypeBool:
|
if other is DeckTypeBool:
|
||||||
return other
|
return other
|
||||||
|
@ -83,6 +99,10 @@ class DeckTypeBool extends DeckType:
|
||||||
|
|
||||||
|
|
||||||
class DeckTypeArray extends DeckType:
|
class DeckTypeArray extends DeckType:
|
||||||
|
func _init(value: Array = []) -> void:
|
||||||
|
_value = value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
if other is DeckTypeString:
|
if other is DeckTypeString:
|
||||||
var inst := DeckTypeArray.new()
|
var inst := DeckTypeArray.new()
|
||||||
|
@ -95,6 +115,10 @@ class DeckTypeArray extends DeckType:
|
||||||
|
|
||||||
|
|
||||||
class DeckTypeDictionary extends DeckType:
|
class DeckTypeDictionary extends DeckType:
|
||||||
|
func _init(value: Dictionary = {}) -> void:
|
||||||
|
_value = value
|
||||||
|
|
||||||
|
|
||||||
static func from(other: DeckType):
|
static func from(other: DeckType):
|
||||||
if other is DeckTypeString:
|
if other is DeckTypeString:
|
||||||
var inst := DeckTypeDictionary.new()
|
var inst := DeckTypeDictionary.new()
|
||||||
|
|
|
@ -24,11 +24,12 @@ func add_label(text: String) -> void:
|
||||||
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
l.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
|
|
||||||
|
|
||||||
func add_field() -> void:
|
func add_field(placeholder: String = "") -> void:
|
||||||
var le := LineEdit.new()
|
var le := LineEdit.new()
|
||||||
add_child(le)
|
add_child(le)
|
||||||
move_child(le, 1)
|
move_child(le, 1)
|
||||||
le.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
le.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||||
|
le.placeholder_text = placeholder
|
||||||
|
|
||||||
le.text_changed.connect(
|
le.text_changed.connect(
|
||||||
func(new_text: String):
|
func(new_text: String):
|
||||||
|
|
|
@ -13,15 +13,20 @@ var port_drawer_scene := preload("res://port_drawer.tscn")
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
name_label.text = node.name
|
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()
|
var port_drawer: PortDrawer = port_drawer_scene.instantiate()
|
||||||
elements_container.add_child(port_drawer)
|
elements_container.add_child(port_drawer)
|
||||||
port_drawer.set_input_enabled(true)
|
port_drawer.set_input_enabled(true)
|
||||||
match input_port.descriptor:
|
match input_port.descriptor:
|
||||||
"field":
|
"field":
|
||||||
port_drawer.add_field()
|
port_drawer.add_field(input_port.label)
|
||||||
# "button":
|
input_port.value_callback = port_drawer.get_text
|
||||||
# port_drawer.add_button(input_port.label)
|
"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)
|
port_drawer.add_label(input_port.label)
|
||||||
|
|
||||||
|
@ -32,7 +37,14 @@ func _ready() -> void:
|
||||||
var port_drawer: PortDrawer = elements_container.get_child(i)
|
var port_drawer: PortDrawer = elements_container.get_child(i)
|
||||||
port_drawer.set_output_enabled(true)
|
port_drawer.set_output_enabled(true)
|
||||||
var output_port := node.output_ports[i]
|
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_button(output_port.label)
|
||||||
|
_:
|
||||||
|
port_drawer.add_label(output_port.label)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue