fix up the spinbox descriptor and switch delay node to use SceneTreeTimer (#99)

closes #76

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/99
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-03-11 06:22:55 +00:00 committed by yagich
parent 677e7b36c5
commit 3886414374
2 changed files with 25 additions and 32 deletions

View file

@ -10,36 +10,29 @@ func _init():
node_type = name.to_snake_case() node_type = name.to_snake_case()
description = "A node that passes through its' input after the set time." description = "A node that passes through its' input after the set time."
add_output_port(DeckType.Types.ANY, "Value") add_input_port(
DeckType.Types.NUMERIC,
"Delay Time",
"spinbox:unbounded:0.01",
Port.UsageType.VALUE_REQUEST,
)
add_input_port(DeckType.Types.NUMERIC, "Delay Time", "field") add_input_port(
add_input_port(DeckType.Types.ANY, "Value", "field") DeckType.Types.ANY,
"Value",
"",
Port.UsageType.TRIGGER,
)
add_output_port(
DeckType.Types.ANY,
"Value",
"",
Port.UsageType.TRIGGER,
)
func _receive(_to_input_port : int, data: Variant) -> void: func _receive(_to_input_port : int, data: Variant) -> void:
var time: float = await resolve_input_port_value_async(0)
thread = Thread.new() await Engine.get_main_loop().create_timer(time).timeout
thread.start(handle_delay.bind(data)) send(0, data)
func handle_delay(data):
var goal_time = Time.get_ticks_msec() + (int(get_input_ports()[0].value_callback.call()) * 1000)
while Time.get_ticks_msec() < goal_time:
pass
#print("Delay over")
send.call_deferred(0, data)
func _notification(what):
if what == NOTIFICATION_PREDELETE and thread != null:
thread.wait_to_finish()

View file

@ -14,14 +14,14 @@ func _setup(port: Port, _node: DeckNode) -> void:
spin_box.allow_greater = true spin_box.allow_greater = true
spin_box.allow_lesser = true spin_box.allow_lesser = true
if descriptor.size() > 2: if descriptor.size() > 2:
spin_box.step = float(descriptor[1]) spin_box.step = float(descriptor[2])
else: else:
spin_box.step = 1.0 spin_box.step = 1.0
else: else:
spin_box.min_value = float(descriptor[1]) spin_box.min_value = float(descriptor[2])
if descriptor.size() > 2: if descriptor.size() > 2:
spin_box.max_value = float(descriptor[2]) spin_box.max_value = float(descriptor[3])
if descriptor.size() > 3: if descriptor.size() > 3:
spin_box.step = float(descriptor[3]) spin_box.step = float(descriptor[4])
port.value_callback = spin_box.get_value port.value_callback = spin_box.get_value
spin_box.value_changed.connect(port.set_value) spin_box.value_changed.connect(port.set_value)