Quit-Rolling-Around-gmtk-ja.../Management/ActiveController.gd

50 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

2022-07-31 17:35:44 +01:00
extends Node
var current_active : int = 0
func _process(_delta):
the_connecting()
the_pausing()
func the_pausing():
# iterate through the children, allowing only the current active node to run
for i in len(get_children()):
2022-08-14 11:24:48 +01:00
if get_child(i).has_signal("scene_finished"): # only change if active var should exist
get_child(i).active = true if i == current_active else false
2022-07-31 17:35:44 +01:00
func the_connecting():
# iterate through the children and connect up the child_finished method
for i in len(get_children()):
# connect the finished signal if it exists and
# if the failed finished isn't already connected
if (get_child(i).has_signal("scene_finished") and
get_child(i).get_signal_connection_list("scene_finished") == []):
2022-08-14 11:24:48 +01:00
get_child(i).connect("scene_finished", self, "child_finished")
2022-07-31 17:35:44 +01:00
# connect the failed signal if it exists and
# if the failed signal isn't already connected
if (get_child(i).has_signal("scene_failed") and
get_child(i).get_signal_connection_list("scene_failed") == []):
2022-08-14 11:24:48 +01:00
get_child(i).connect("scene_failed", self, "child_failed")
2022-07-31 17:35:44 +01:00
func child_finished():
# designed to be called from a signal
current_active += 1
if current_active >= len(get_children()):
current_active = 0
func child_failed():
# designed to be called from a signal
current_active -= 1
if current_active < 0:
current_active = len(get_children()) - 1