Added autoloads; created jet factory pattern
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
extends Node
|
||||
|
||||
|
||||
enum FACTION {
|
||||
ALLIES,
|
||||
AXIS,
|
||||
NEUTRAL
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://cvi0verbmp1lh
|
||||
@@ -1,7 +1,7 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cx5ewmp2xcuia"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://bhjfvc7gkrvah" path="res://base_environment.tscn" id="1_80nbo"]
|
||||
[ext_resource type="PackedScene" uid="uid://mtfp7066molc" path="res://scenes/jet.tscn" id="2_e2o6t"]
|
||||
[ext_resource type="PackedScene" uid="uid://dk32bn35qku60" path="res://scripts/factories/jet_factory.tscn" id="2_e2o6t"]
|
||||
|
||||
[node name="game" type="Node3D"]
|
||||
|
||||
@@ -10,4 +10,4 @@
|
||||
[node name="camera" type="Camera3D" parent="."]
|
||||
current = true
|
||||
|
||||
[node name="jet" parent="." instance=ExtResource("2_e2o6t")]
|
||||
[node name="jet_factory" parent="." instance=ExtResource("2_e2o6t")]
|
||||
|
||||
@@ -16,6 +16,10 @@ config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
boot_splash/show_image=false
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
Globals="*res://autoloads/globals.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/viewport_width=640
|
||||
|
||||
+8
-16
@@ -1,28 +1,19 @@
|
||||
class_name Jet extends Node3D
|
||||
|
||||
|
||||
var ALLIES_SIDE: EaglePlus = EaglePlus.new()
|
||||
var AXIS_SIDE: SakerFalcon = SakerFalcon.new()
|
||||
|
||||
@export_enum("CPU:0", "PLAYER:1") var control_mode: int = JetController.CPU_MODE
|
||||
@export_enum("Allies:0", "Axis:1") var CONFLICT_SIDE: int = ALLIES_SIDE.CONFLICT_SIDE
|
||||
|
||||
const JET_MODEL: Dictionary = {
|
||||
ALLIES_SIDE.CONFLICT_SIDE: ALLIES_SIDE.MODEL,
|
||||
AXIS_SIDE.CONFLICT_SIDE: AXIS_SIDE.MODEL
|
||||
}
|
||||
@export_enum("Allies:0", "Axis:1") var CONFLICT_SIDE: int
|
||||
|
||||
@onready var camera: Camera3D = $camera
|
||||
@onready var controller: JetController = $controller
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_load_jet(CONFLICT_SIDE)
|
||||
print("Jet ready: ", is_node_ready())
|
||||
print("Camera: ", camera)
|
||||
|
||||
if JetController.CPU_MODE == control_mode:
|
||||
set_as_cpu()
|
||||
elif JetController.PLAYER_MODE == control_mode:
|
||||
set_as_player()
|
||||
pass
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var action = controller.process(delta)
|
||||
@@ -36,11 +27,12 @@ func _process(delta: float) -> void:
|
||||
#var action = controller.unhandled_input(event)
|
||||
#if not action: return
|
||||
|
||||
func _load_jet(type: int = CONFLICT_SIDE):
|
||||
add_child( JET_MODEL[type].instantiate() )
|
||||
|
||||
func set_model(model: Node):
|
||||
add_child(model)
|
||||
|
||||
func set_as_player():
|
||||
print("Setting player. Ready: ", is_node_ready())
|
||||
print("Camera reference: ", camera)
|
||||
camera.current = true
|
||||
controller.control_mode = controller.PLAYER_MODE
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
|
||||
[node name="jet" type="Node3D"]
|
||||
script = ExtResource("1_l0pwp")
|
||||
control_mode = null
|
||||
CONFLICT_SIDE = null
|
||||
|
||||
[node name="camera" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 120, 350)
|
||||
|
||||
@@ -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