24 lines
599 B
GDScript
24 lines
599 B
GDScript
class_name StrategyStack extends Node
|
|
|
|
|
|
var active_action: ActionBase
|
|
|
|
|
|
func _init() -> void:
|
|
child_entered_tree.connect( add_action.bind() )
|
|
child_exiting_tree.connect( remove_action.bind() )
|
|
|
|
|
|
func add_action(action: ActionBase) -> void:
|
|
if active_action: return
|
|
active_action = action
|
|
|
|
func remove_action(action: ActionBase) -> void:
|
|
if not active_action == action: return
|
|
# NOTE: 1st node hasn't actually been removed yet
|
|
active_action = null if not get_child_count() > 1 else get_child(1)
|
|
|
|
func process_action(jet: Jet) -> void:
|
|
if not active_action: return
|
|
active_action.process(jet)
|