2023-12-15 22:44:25 +01:00
|
|
|
# (c) 2023-present Eroax
|
|
|
|
# (c) 2023-present Yagich
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2023-11-27 10:28:36 +01:00
|
|
|
extends DeckNode
|
|
|
|
|
|
|
|
var thread : Thread
|
|
|
|
|
|
|
|
func _init():
|
|
|
|
name = "Delay"
|
|
|
|
node_type = name.to_snake_case()
|
2023-12-15 22:44:25 +01:00
|
|
|
description = "A node that passes through its' input after the set time."
|
2023-11-27 10:33:14 +01:00
|
|
|
category = "general"
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
add_output_port(DeckType.Types.ANY, "Value")
|
|
|
|
|
2023-11-27 10:33:14 +01:00
|
|
|
add_input_port(DeckType.Types.NUMERIC, "Delay Time", "field")
|
2023-12-15 22:44:25 +01:00
|
|
|
add_input_port(DeckType.Types.ANY, "Value", "field")
|
|
|
|
|
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
|
2023-12-15 22:44:25 +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))
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
|
|
|
|
func handle_delay(data):
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
var goal_time = Time.get_ticks_msec() + (int(get_input_ports()[0].value_callback.call()) * 1000)
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
while Time.get_ticks_msec() < goal_time:
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
pass
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
#print("Delay over")
|
2024-01-19 10:52:51 +01:00
|
|
|
send.call_deferred(0, data)
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
|
|
|
|
func _notification(what):
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
if what == NOTIFICATION_PREDELETE and thread != null:
|
2023-12-15 22:44:25 +01:00
|
|
|
|
2023-11-27 10:28:36 +01:00
|
|
|
thread.wait_to_finish()
|
2023-12-15 22:44:25 +01:00
|
|
|
|
|
|
|
|