2023-11-27 10:28:36 +01:00
|
|
|
extends DeckNode
|
|
|
|
|
|
|
|
var thread : Thread
|
|
|
|
|
|
|
|
func _init():
|
|
|
|
name = "Delay"
|
|
|
|
node_type = name.to_snake_case()
|
|
|
|
description = "A Node that passes through the input after the set time."
|
2023-11-27 10:33:14 +01:00
|
|
|
category = "general"
|
2023-11-27 10:28:36 +01:00
|
|
|
|
2023-11-27 10:33:14 +01:00
|
|
|
add_output_port(DeckType.Types.STRING, "Value", "")
|
2023-11-27 10:28:36 +01:00
|
|
|
|
2023-11-27 10:33:14 +01:00
|
|
|
add_input_port(DeckType.Types.NUMERIC, "Delay Time", "field")
|
|
|
|
add_input_port(DeckType.Types.NUMERIC, "Value", "field")
|
2023-11-27 10:28:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-11-27 10:33:14 +01:00
|
|
|
func _receive(to_input_port : int, data: Variant, extra_data: Array = []) -> void:
|
2023-11-27 10:28:36 +01:00
|
|
|
|
|
|
|
thread = Thread.new()
|
|
|
|
thread.start(handle_delay.bind(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(0, data)
|
|
|
|
|
|
|
|
|
|
|
|
func _notification(what):
|
|
|
|
|
|
|
|
if what == NOTIFICATION_PREDELETE and thread != null:
|
|
|
|
|
|
|
|
thread.wait_to_finish()
|
|
|
|
|
|
|
|
|