39 lines
796 B
GDScript
39 lines
796 B
GDScript
extends Node3D
|
|
class_name WeaponContainer
|
|
|
|
var slots: Array[WeaponSlot]
|
|
var current_slot: WeaponSlot = null
|
|
var current_weapon: Weapon
|
|
|
|
signal slot_selected()
|
|
|
|
func _ready():
|
|
for slot in get_children():
|
|
assert(slot is WeaponSlot)
|
|
slots.push_back(slot as WeaponSlot)
|
|
|
|
for slot in range(slots.size()):
|
|
if current_slot == null:
|
|
select_slot(slot)
|
|
else:
|
|
break
|
|
|
|
assert(current_slot != null)
|
|
|
|
func select_slot(index: int):
|
|
assert(index < slots.size())
|
|
|
|
if slots[index].has_weapon:
|
|
current_slot = slots[index]
|
|
current_weapon = current_slot.weapon
|
|
slot_selected.emit()
|
|
|
|
func first_free_slot() -> WeaponSlot:
|
|
for slot in slots:
|
|
if not slot.has_weapon:
|
|
return slot
|
|
return null
|
|
|
|
func refresh_current_slot() -> void:
|
|
var index = slots.find(current_slot)
|
|
select_slot(index)
|