Files

48 lines
1.0 KiB
GDScript
Raw Permalink Normal View History

class_name SpawnController extends BaseController
@export var jet_factory: JetFactory
func _ready() -> void:
pass
func _controller_message(event: BaseEvent) -> void:
if event is BaseCreateJetEvent:
if event is CreateAlliesJetEvent:
spawn_allies_jet()
elif event is CreateAxisJetEvent:
spawn_axis_jet()
elif event is CreateNeutralJetEvent:
spawn_neutral_jet()
func spawn_neutral_jet():
var _jet = spawn_jet(
Globals.Faction.NEUTRAL, jet_factory.create_cpu_jet
)
func spawn_allies_jet():
var _jet = spawn_jet.call(
Globals.Faction.ALLIES, jet_factory.create_cpu_jet
)
func spawn_axis_jet():
var _jet = spawn_jet(
Globals.Faction.AXIS, jet_factory.create_cpu_jet
)
func spawn_jet(faction: Globals.Faction, callback: Callable) -> Jet:
var jet: Jet = null
for spawner: Spawner in get_children():
if not spawner.faction == faction: continue
if not spawner.is_available: continue
jet = callback.call(faction)
jets_collection.add_child.call(jet)
spawner.align_to_position.call_deferred(jet)
return jet