Added autoloads; created jet factory pattern
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
class_name JetFactory extends Node
|
||||
|
||||
|
||||
const JET = preload("res://scenes/jet.tscn")
|
||||
|
||||
var ALLIES_JET: EaglePlus = EaglePlus.new()
|
||||
var AXIS_JET: SakerFalcon = SakerFalcon.new()
|
||||
var NEUTRAL_JET: EaglePlus = EaglePlus.new()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
func _get_jet_type(faction: int) -> Jet:
|
||||
if faction == Globals.FACTION.ALLIES:
|
||||
return create_allies_jet()
|
||||
if faction == Globals.FACTION.AXIS:
|
||||
return create_axis_jet()
|
||||
if faction == Globals.FACTION.NEUTRAL:
|
||||
return create_neutral_jet()
|
||||
|
||||
return create_neutral_jet()
|
||||
|
||||
|
||||
func create_player_jet(faction: int = 0) -> Jet:
|
||||
var jet: Jet = _get_jet_type(faction)
|
||||
|
||||
get_tree().root.add_child(jet)
|
||||
print("1")
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
print("2")
|
||||
jet.set_as_player()
|
||||
return jet
|
||||
|
||||
func create_cpu_jet(faction: int = 0) -> Jet:
|
||||
var jet = _get_jet_type(faction)
|
||||
|
||||
get_tree().root.add_child(jet)
|
||||
await get_tree().process_frame
|
||||
|
||||
jet.set_as_cpu()
|
||||
return jet
|
||||
|
||||
|
||||
func create_neutral_jet() -> Jet:
|
||||
var jet = JET.new()
|
||||
jet.add_child( NEUTRAL_JET.MODEL.instantiate() )
|
||||
return jet
|
||||
|
||||
func create_allies_jet() -> Jet:
|
||||
var jet = JET.instantiate()
|
||||
jet.add_child( ALLIES_JET.MODEL.instantiate() )
|
||||
return jet
|
||||
|
||||
func create_axis_jet() -> Jet:
|
||||
var jet = JET.instantiate()
|
||||
jet.add_child( AXIS_JET.MODEL.instantiate() )
|
||||
return jet
|
||||
@@ -0,0 +1 @@
|
||||
uid://c6b0hhfg0xdi4
|
||||
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dk32bn35qku60"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://c6b0hhfg0xdi4" path="res://scripts/factories/jet_factory.gd" id="1_k26y6"]
|
||||
|
||||
[node name="jet_factory" type="Node"]
|
||||
script = ExtResource("1_k26y6")
|
||||
Reference in New Issue
Block a user