2023-11-27 10:21:43 +01:00
|
|
|
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 = []
|
2023-12-04 15:16:39 +01:00
|
|
|
|
2023-12-04 21:05:15 +01:00
|
|
|
# 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(
|
2023-12-08 12:36:19 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-12-04 21:05:15 +01:00
|
|
|
"Expression Text",
|
|
|
|
"codeblock"
|
|
|
|
)
|
2023-11-27 10:21:43 +01:00
|
|
|
|
|
|
|
|
2023-12-04 15:16:39 +01:00
|
|
|
|
|
|
|
func _value_request(_from_port : int) -> Variant:
|
|
|
|
|
2023-11-27 10:21:43 +01:00
|
|
|
var text = get_output_ports()[0].value_callback.call()
|
2023-12-04 15:16:39 +01:00
|
|
|
|
2023-12-04 21:05:15 +01:00
|
|
|
var err = expr.parse(text, ["deck_var", "input"])
|
2023-11-27 10:21:43 +01:00
|
|
|
if err != OK:
|
2023-12-04 15:16:39 +01:00
|
|
|
|
2023-11-27 10:21:43 +01:00
|
|
|
printerr(err)
|
|
|
|
return null
|
2023-12-04 15:16:39 +01:00
|
|
|
|
|
|
|
|
2023-12-04 21:05:15 +01:00
|
|
|
var res = expr.execute([_belonging_to.variable_stack, request_value(0)])
|
2023-11-27 10:21:43 +01:00
|
|
|
if expr.has_execute_failed():
|
2023-12-04 15:16:39 +01:00
|
|
|
|
2023-11-27 10:21:43 +01:00
|
|
|
printerr("Expression Execution Failed: ", text)
|
|
|
|
return null
|
2023-12-04 15:16:39 +01:00
|
|
|
|
|
|
|
|
2023-11-27 10:21:43 +01:00
|
|
|
return res
|
2023-12-04 15:16:39 +01:00
|
|
|
|