29 lines
587 B
GDScript
29 lines
587 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()
|