mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
48 lines
911 B
GDScript
48 lines
911 B
GDScript
extends DeckNode
|
|
|
|
var expr = Expression.new()
|
|
|
|
func _init():
|
|
name = "Expression"
|
|
node_type = name.to_snake_case()
|
|
description = "A Node holding a block of executable GDScript code."
|
|
category = "general"
|
|
|
|
props_to_serialize = []
|
|
|
|
# TODO: order of ports is changed
|
|
# due to https://github.com/godotengine/godot/issues/85558
|
|
# when it's fixed, switch it back
|
|
add_input_port(
|
|
DeckType.Types.DICTIONARY,
|
|
"Expression Input"
|
|
)
|
|
|
|
add_output_port(
|
|
DeckType.Types.STRING,
|
|
"Expression Text",
|
|
"codeblock"
|
|
)
|
|
|
|
|
|
|
|
func _value_request(_from_port : int) -> Variant:
|
|
|
|
var text = get_output_ports()[0].value_callback.call()
|
|
|
|
var err = expr.parse(text, ["deck_var", "input"])
|
|
if err != OK:
|
|
|
|
printerr(err)
|
|
return null
|
|
|
|
|
|
var res = expr.execute([_belonging_to.variable_stack, request_value(0)])
|
|
if expr.has_execute_failed():
|
|
|
|
printerr("Expression Execution Failed: ", text)
|
|
return null
|
|
|
|
|
|
return res
|
|
|