42 lines
1.0 KiB
GDScript
42 lines
1.0 KiB
GDScript
extends Node
|
|
|
|
## Local hotbar slot state mirror for NEO-29. Holds slot -> ability mapping from
|
|
## server-owned `HotbarLoadout` payloads.
|
|
signal hotbar_changed(slots: Array)
|
|
|
|
const SLOT_COUNT: int = 8
|
|
|
|
var _slots: Array = []
|
|
|
|
|
|
func _ready() -> void:
|
|
if _slots.is_empty():
|
|
_slots.resize(SLOT_COUNT)
|
|
for i in range(SLOT_COUNT):
|
|
_slots[i] = null
|
|
|
|
|
|
func apply_slots(slots: Array) -> void:
|
|
var normalized: Array = []
|
|
normalized.resize(SLOT_COUNT)
|
|
for i in range(SLOT_COUNT):
|
|
normalized[i] = null
|
|
for slot_variant in slots:
|
|
if not slot_variant is Dictionary:
|
|
continue
|
|
var slot: Dictionary = slot_variant
|
|
var idx: int = int(slot.get("slotIndex", -1))
|
|
if idx < 0 or idx >= SLOT_COUNT:
|
|
continue
|
|
var ability_variant: Variant = slot.get("abilityId", null)
|
|
if ability_variant is String and not (ability_variant as String).is_empty():
|
|
normalized[idx] = ability_variant as String
|
|
else:
|
|
normalized[idx] = null
|
|
_slots = normalized
|
|
hotbar_changed.emit(_slots.duplicate())
|
|
|
|
|
|
func slots_snapshot() -> Array:
|
|
return _slots.duplicate()
|