30 lines
658 B
GDScript3
30 lines
658 B
GDScript3
|
extends Panel
|
||
|
|
||
|
const ItemClass = preload("res://Item.gd");
|
||
|
|
||
|
var slots = Array();
|
||
|
|
||
|
func _ready():
|
||
|
slots.resize(512);
|
||
|
slots.insert(1, get_node("Grid/Slot1"));
|
||
|
slots.insert(2, get_node("Grid/Slot2"));
|
||
|
slots.insert(3, get_node("Grid/Slot3"));
|
||
|
|
||
|
func getSlotByType(type):
|
||
|
return slots[type];
|
||
|
|
||
|
func getItemByType(type):
|
||
|
return slots[type].item;
|
||
|
|
||
|
func getFreeSlot():
|
||
|
for i in range(1, 3):
|
||
|
if !slots[i].item:
|
||
|
return slots[i];
|
||
|
|
||
|
func AddToHotbar(itemName, itemIcon):
|
||
|
var slot = getFreeSlot()
|
||
|
if not slot:
|
||
|
return false
|
||
|
slot.setItem(ItemClass.new(itemName, itemIcon, null, 100, Global.SlotType.SLOT_DEFAULT))
|
||
|
return true
|