miggor-StreamGraph/classes/deck/nodes/general/print.gd

40 lines
843 B
GDScript3
Raw Permalink Normal View History

# (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
func _init() -> void:
2023-07-21 07:30:12 +02:00
name = "Print"
node_type = name.to_snake_case()
description = "Print a value to the console."
2023-07-21 07:30:12 +02:00
add_input_port(
DeckType.Types.ANY,
"Data to print",
"field"
)
2023-06-10 20:23:57 +02:00
add_input_port(
DeckType.Types.ANY,
2023-06-10 20:23:57 +02:00
"Trigger",
"button",
Port.UsageType.TRIGGER,
).button_pressed.connect(_receive.bind(1, null))
2023-06-12 17:32:16 +02:00
func _receive(to_input_port: int, data: Variant) -> void:
var data_to_print := ""
if to_input_port == 1:
data = await resolve_input_port_value_async(0)
2023-06-10 20:23:57 +02:00
if data == null:
data_to_print = "<nothing>"
else:
data_to_print = str(data)
if data_to_print.is_empty():
data_to_print = "<nothing>"
DeckHolder.logger.log_node(data_to_print)