Hello! I decided to study the inventory system using this demo:
https://github.com/szechset/PC-Inventory-Demo
I decided to make an item generator in order to delve a little more into this system and faced the fact that I needed a container for the generator, similar to the inventory.
I added code to generate slots and items from the inventory example and ran into the problem that Godot reads both dictionaries
Inventory:
func _ready():
if !dictionary_inv.itemDictionary.empty():
for item in dictionary_inv.itemDictionary:
var itemType = dictionary_inv.itemDictionary[item].itemType
var itemName = dictionary_inv.itemDictionary[item].itemName
var itemIcon = dictionary_inv.itemDictionary[item].itemIcon
var itemStack = dictionary_inv.itemDictionary[item].itemStack
var itemStackMax = dictionary_inv.itemDictionary[item].itemStackMax
var itemStackValue = dictionary_inv.itemDictionary[item].itemStackValue
var itemEq = dictionary_inv.itemDictionary[item].itemEq
itemList.append(ItemClass.new(itemType, itemName, itemIcon, itemStack, itemStackMax, itemStackValue, itemEq, null))
for i in range(inventorySize):
var slot = SlotClass.new(i, 'none')
slotList.append(slot)
$inv_ui/zpa/Container/GridContainer.add_child(slot)
if !dictionary_inv.itemDictionary.empty():
var x = 0
var itemDelete = Array()
for i in dictionary_inv.itemDictionary:
if i < inventorySize:
if dictionary_inv.itemDictionary[i].itemStack:
if dictionary_inv.itemDictionary[i].itemStackValue > dictionary_inv.itemDictionary[i].itemStackMax:
itemDelete.append(i)
itemList.remove(x)
else:
slotList[i].setItem(itemList[x])
slotUsed.append(itemList[x].itemIndex)
x += 1
else:
slotList[i].setItem(itemList[x])
slotUsed.append(itemList[x].itemIndex)
x += 1
elif i >= inventorySize and i < (inventorySize + eqSize):
if dictionary_inv.itemDictionary[i].itemEq.has(slotList[i].slotEq):
slotList[i].setItem(itemList[x])
x += 1
elif !dictionary_inv.itemDictionary[i].itemEq.has(slotList[i].slotEq):
itemDelete.append(i)
itemList.remove(x)
else:
itemDelete.append(i)
itemList.remove(x)
for i in itemDelete:
dictionary_inv.itemDictionary.erase(i)
slotUsed.sort()
Duplicate lines for the item container:
if !allItemn.allItem.empty():
for item in allItemn.allItem:
var itemType = allItemn.allItem[item].itemType
var itemName = allItemn.allItem[item].itemName
var itemIcon = allItemn.allItem[item].itemIcon
var itemStack = allItemn.allItem[item].itemStack
var itemStackMax = allItemn.allItem[item].itemStackMax
var itemStackValue = allItemn.allItem[item].itemStackValue
var itemEq = allItemn.allItem[item].itemEq
itemList.append(ItemClass.new(itemType, itemName, itemIcon, itemStack, itemStackMax, itemStackValue, itemEq, null))
for j in range(creative):
var slot = SlotClass.new(j, 'none')
slotList.append(slot)
$creative_container/ScrollContainer/GridContainer.add_child(slot)
if !allItemn.allItem.empty():
var x = 0
var itemDelete = Array()
for j in allItemn.allItem:
if j < creative:
if allItemn.allItem[j].itemStack:
if allItemn.allItem[j].itemStackValue > allItemn.allItem[j].itemStackMax:
itemDelete.append(j)
itemList.remove(x)
else:
slotList[j].setItem(itemList[x])
slotUsed.append(itemList[x].itemIndex)
x += 1
else:
slotList[j].setItem(itemList[x])
slotUsed.append(itemList[x].itemIndex)
x += 1
elif j >= creative and j < (creative):
if allItemn.allItem[j].itemEq.has(slotList[j].slotEq):
slotList[j].setItem(itemList[x])
x += 1
elif !allItemn.allItem[j].itemEq.has(slotList[j].slotEq):
itemDelete.append(j)
itemList.remove(x)
else:
itemDelete.append(j)
itemList.remove(x)
for j in itemDelete:
allItemn.allItem.erase(j)
slotUsed.sort()
But items are loaded into both inventory and container using 2 dictionaries at once.