feat: implement loadout management system, interactive pause menu, and weapon slot switching functionality
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
extends Node3D
|
||||
class_name WeaponManager
|
||||
|
||||
var player: CharacterBody3D
|
||||
var camera: Camera3D
|
||||
|
||||
var active_slot: int = 1 # 1: Primary 1, 2: Primary 2, 3: Special
|
||||
var weapons: Dictionary = {} # slot_index: Node3D
|
||||
|
||||
func _ready() -> void:
|
||||
set_process_input(true)
|
||||
|
||||
# Wait one frame for LoadoutManager to be fully ready if needed
|
||||
await get_tree().process_frame
|
||||
_build_loadout()
|
||||
|
||||
func _build_loadout() -> void:
|
||||
# Clear existing weapons
|
||||
for w in weapons.values():
|
||||
if is_instance_valid(w):
|
||||
w.queue_free()
|
||||
weapons.clear()
|
||||
|
||||
var l = LoadoutManager.get_active_loadout()
|
||||
|
||||
_spawn_weapon(1, l["primary_1"])
|
||||
_spawn_weapon(2, l["primary_2"])
|
||||
_spawn_weapon(3, l["special"])
|
||||
|
||||
_equip_slot(1)
|
||||
|
||||
func _spawn_weapon(slot: int, weapon_id: String) -> void:
|
||||
if weapon_id == "" or weapon_id == "none" or not LoadoutManager.weapon_db.has(weapon_id):
|
||||
return
|
||||
|
||||
var w_data = LoadoutManager.weapon_db[weapon_id]
|
||||
var script_path = w_data["script"]
|
||||
if script_path == "":
|
||||
return
|
||||
|
||||
var script = load(script_path)
|
||||
if script:
|
||||
var w = script.new()
|
||||
w.name = "Weapon_" + str(slot) + "_" + weapon_id
|
||||
# Assuming all weapons have player and camera vars
|
||||
if "player" in w: w.player = player
|
||||
if "camera" in w: w.camera = camera
|
||||
add_child(w)
|
||||
weapons[slot] = w
|
||||
w.visible = false
|
||||
w.set_process_input(false)
|
||||
|
||||
func _equip_slot(slot: int) -> void:
|
||||
if weapons.has(active_slot):
|
||||
var w = weapons[active_slot]
|
||||
w.visible = false
|
||||
w.set_process_input(false)
|
||||
|
||||
active_slot = slot
|
||||
|
||||
if weapons.has(active_slot):
|
||||
var w = weapons[active_slot]
|
||||
w.visible = true
|
||||
w.set_process_input(true)
|
||||
print("Equipped slot ", slot)
|
||||
else:
|
||||
print("Slot ", slot, " is empty!")
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
|
||||
return
|
||||
|
||||
if event.is_action_pressed("weapon_1"):
|
||||
_equip_slot(1)
|
||||
elif event.is_action_pressed("weapon_2"):
|
||||
_equip_slot(2)
|
||||
elif event.is_action_pressed("weapon_3"):
|
||||
_equip_slot(3)
|
||||
@@ -0,0 +1 @@
|
||||
uid://bp5ujeumiq5j
|
||||
Reference in New Issue
Block a user