mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
make expression node input typed as ANY (#174)
Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/174 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
parent
b5cd7336a4
commit
afd868270c
1 changed files with 8 additions and 11 deletions
|
@ -5,18 +5,17 @@ extends DeckNode
|
||||||
|
|
||||||
var expr = Expression.new()
|
var expr = Expression.new()
|
||||||
|
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
name = "Expression"
|
name = "Expression"
|
||||||
node_type = name.to_snake_case()
|
node_type = "expression"
|
||||||
description = "A node returning the result of a mathematical expression."
|
description = "A node returning the result of a mathematical expression."
|
||||||
|
|
||||||
props_to_serialize = []
|
|
||||||
|
|
||||||
# TODO: order of ports is changed
|
# TODO: order of ports is changed
|
||||||
# due to https://github.com/godotengine/godot/issues/85558
|
# due to https://github.com/godotengine/godot/issues/85558
|
||||||
# when it's fixed, switch it back
|
# when it's fixed, switch it back
|
||||||
add_input_port(
|
add_input_port(
|
||||||
DeckType.Types.DICTIONARY,
|
DeckType.Types.ANY,
|
||||||
"Expression Input",
|
"Expression Input",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -27,30 +26,28 @@ func _init():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func parse(input: Dictionary) -> Variant:
|
func parse(input: Variant) -> Variant:
|
||||||
var text = get_output_ports()[0].value
|
var text = get_output_ports()[0].value
|
||||||
|
|
||||||
var err = expr.parse(text, ["deck_var", "input"])
|
var err := expr.parse(text, ["deck_var", "input"])
|
||||||
if err != OK:
|
if err != OK:
|
||||||
|
|
||||||
DeckHolder.logger.log_node("Expression parse failed: %s" % err, Logger.LogType.ERROR)
|
DeckHolder.logger.log_node("Expression parse failed: %s" % err, Logger.LogType.ERROR)
|
||||||
printerr(err)
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
var res = expr.execute([_belonging_to.variable_stack, input])
|
var res = expr.execute([_belonging_to.variable_stack, input])
|
||||||
if expr.has_execute_failed():
|
if expr.has_execute_failed():
|
||||||
|
DeckHolder.logger.log_node("Expression Execution Failed: %s" % expr.get_error_text(), Logger.LogType.ERROR)
|
||||||
DeckHolder.logger.log_node("Expression Execution Failed: %s" % text, Logger.LogType.ERROR)
|
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
func _value_request(_from_port : int) -> Variant:
|
func _value_request(_from_port : int) -> Variant:
|
||||||
var input = await request_value_async(0)
|
var input = await request_value_async(0)
|
||||||
if input != null:
|
if input != null:
|
||||||
return parse(input)
|
return parse(input)
|
||||||
else:
|
else:
|
||||||
return parse({})
|
return parse(null)
|
||||||
|
|
||||||
|
|
||||||
func _receive(_on_input_port: int, data: Variant) -> void:
|
func _receive(_on_input_port: int, data: Variant) -> void:
|
||||||
|
|
Loading…
Reference in a new issue