2023-06-10 19:13:16 +02:00
|
|
|
class_name Port
|
2023-11-25 11:40:53 +01:00
|
|
|
## A data type representing a port of a [DeckNode].
|
|
|
|
##
|
|
|
|
## Ports are used for connections between [DeckNode]s and can contain data that is passed between
|
|
|
|
## them on a node.
|
2023-06-10 19:13:16 +02:00
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## The type index of this port.
|
2023-11-26 23:07:15 +01:00
|
|
|
var type: DeckType.Types
|
2023-11-25 11:40:53 +01:00
|
|
|
## The label of this port. Used by the renderer to display. How it's displayed depends on the renderer
|
|
|
|
## and the [member descriptor].
|
2023-06-10 19:13:16 +02:00
|
|
|
var label: String
|
2023-11-25 11:40:53 +01:00
|
|
|
## Hints to the renderer on how to display this port.[br]
|
|
|
|
## Can be either one of these: [code]button textfield spinbox slider textblock codeblock checkbox singlechoice multichoice[/code].[br]
|
|
|
|
## Additional descriptor properties can be specified after the type, delimited by a colon ([code]:[/code]).[br]
|
|
|
|
## @experimental
|
2023-06-10 19:13:16 +02:00
|
|
|
var descriptor: String
|
2023-11-25 11:40:53 +01:00
|
|
|
## A callback to get this port's value. Intended usage is by renderers that show an input field of some kind.
|
2023-06-10 20:23:57 +02:00
|
|
|
var value_callback: Callable
|
2023-06-10 19:13:16 +02:00
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## The type of this port (input, output or virtual)
|
2023-06-12 17:32:16 +02:00
|
|
|
var port_type: DeckNode.PortType
|
2023-11-25 11:40:53 +01:00
|
|
|
## The local index of this port.
|
2023-06-12 17:32:16 +02:00
|
|
|
var index_of_type: int
|
2023-11-25 11:40:53 +01:00
|
|
|
## The global index of this port.
|
2023-06-12 17:32:16 +02:00
|
|
|
var index: int
|
|
|
|
|
2023-11-25 11:40:53 +01:00
|
|
|
## The value of this port.
|
2023-12-08 07:33:37 +01:00
|
|
|
var value: Variant
|
2023-07-21 10:26:43 +02:00
|
|
|
|
2023-11-28 09:13:18 +01:00
|
|
|
signal value_updated(new_value: Variant)
|
|
|
|
|
2023-06-10 19:13:16 +02:00
|
|
|
|
2023-06-10 20:23:57 +02:00
|
|
|
func _init(
|
2023-11-26 23:07:15 +01:00
|
|
|
p_type: DeckType.Types,
|
2023-06-10 20:23:57 +02:00
|
|
|
p_label: String,
|
2023-06-12 17:32:16 +02:00
|
|
|
p_index: int,
|
|
|
|
p_port_type: DeckNode.PortType,
|
|
|
|
p_index_of_type: int,
|
2023-06-10 20:23:57 +02:00
|
|
|
p_descriptor: String = "",
|
2023-06-12 17:32:16 +02:00
|
|
|
# p_value_callback: Callable = Callable(),
|
|
|
|
) -> void:
|
2023-06-10 19:13:16 +02:00
|
|
|
type = p_type
|
|
|
|
label = p_label
|
|
|
|
descriptor = p_descriptor
|
2023-06-12 17:32:16 +02:00
|
|
|
# value_callback = p_value_callback
|
|
|
|
|
|
|
|
port_type = p_port_type
|
|
|
|
index_of_type = p_index_of_type
|
|
|
|
index = p_index
|
2023-07-21 10:26:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func set_value(v: Variant) -> void:
|
2023-12-08 07:33:37 +01:00
|
|
|
set_value_no_signal(v)
|
|
|
|
value_updated.emit(value)
|
|
|
|
|
|
|
|
|
|
|
|
func set_value_no_signal(v: Variant) -> void:
|
2023-11-27 10:09:45 +01:00
|
|
|
if v is Callable:
|
|
|
|
value = v.call()
|
|
|
|
return
|
|
|
|
|
2023-07-21 10:26:43 +02:00
|
|
|
value = v
|