123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #include "Inventory.h"
- #include "Area.h"
- #include "Registries.h"
- using namespace Framework;
- Inventory::Inventory(const Framework::Vec3<float> location, bool hasInventory)
- : ReferenceCounter(),
- location(location)
- {
- if (hasInventory)
- {
- pullSlotsOrder = new Framework::RCArray<ItemSlot>();
- pushSlotsOrder = new Framework::RCArray<ItemSlot>();
- }
- else
- {
- pullSlotsOrder = 0;
- pushSlotsOrder = 0;
- }
- }
- Inventory::~Inventory()
- {
- if (pullSlotsOrder)
- pullSlotsOrder->release();
- if (pushSlotsOrder)
- pushSlotsOrder->release();
- }
- void Inventory::loadInventory(Framework::StreamReader* zReader)
- {
- if (pushSlotsOrder)
- {
- for (auto slot : *pushSlotsOrder)
- {
- int size = 0;
- zReader->lese((char*)&size, 4);
- if (size != 0)
- {
- int id = 0;
- zReader->lese((char*)&id, 4);
- Item* item = STATIC_REGISTRY(ItemType).zElement(id)->loadItem(zReader);
- slot->setItems(new ItemStack(item, size));
- }
- else
- slot->setItems(0);
- }
- }
- }
- void Inventory::addSlot(ItemSlot* slot)
- {
- int pullPrio = slot->getPullPriority();
- int pushPrio = slot->getPushPriority();
- int index = 0;
- for (auto stack : *pullSlotsOrder)
- {
- if (stack->getPullPriority() > pullPrio)
- break;
- index++;
- }
- pullSlotsOrder->add(dynamic_cast<ItemSlot*>(slot->getThis()), index);
- index = 0;
- for (auto stack : *pushSlotsOrder)
- {
- if (stack->getPushPriority() > pushPrio)
- break;
- index++;
- }
- pushSlotsOrder->add(slot, index);
- }
- Framework::Iterator<ItemSlot*> Inventory::begin()
- {
- return pullSlotsOrder->begin();
- }
- Framework::Iterator<ItemSlot*> Inventory::end()
- {
- return pullSlotsOrder->end();
- }
|