]> git.lizzy.rs Git - minetest.git/blobdiff - src/inventory.cpp
Update translation sources
[minetest.git] / src / inventory.cpp
index 2a7c32a44dc2d53f99d0f957a79ddc781e8d2d26..77ecf5876bf36500206ba8b7eb5697c0e7a2c033 100644 (file)
@@ -717,27 +717,13 @@ void InventoryList::moveItemSomewhere(u32 i, InventoryList *dest, u32 count)
        if (item1.empty())
                return;
 
-       // Try to add the item to destination list
-       u32 dest_size = dest->getSize();
-       // First try all the non-empty slots
-       for (u32 dest_i = 0; dest_i < dest_size; dest_i++) {
-               if (!m_items[dest_i].empty()) {
-                       item1 = dest->addItem(dest_i, item1);
-                       if (item1.empty()) return;
-               }
-       }
+       ItemStack leftover;
+       leftover = dest->addItem(item1);
 
-       // Then try all the empty ones
-       for (u32 dest_i = 0; dest_i < dest_size; dest_i++) {
-               if (m_items[dest_i].empty()) {
-                       item1 = dest->addItem(dest_i, item1);
-                       if (item1.empty()) return;
-               }
+       if (!leftover.empty()) {
+               // Add the remaining part back to the source item
+               addItem(i, leftover);
        }
-
-       // If we reach this, the item was not fully added
-       // Add the remaining part back to the source item
-       addItem(i, item1);
 }
 
 u32 InventoryList::moveItem(u32 i, InventoryList *dest, u32 dest_i,
@@ -799,17 +785,17 @@ Inventory::~Inventory()
 
 void Inventory::clear()
 {
-       m_dirty = true;
        for (auto &m_list : m_lists) {
                delete m_list;
        }
        m_lists.clear();
+       setModified();
 }
 
 Inventory::Inventory(IItemDefManager *itemdef)
 {
-       m_dirty = false;
        m_itemdef = itemdef;
+       setModified();
 }
 
 Inventory::Inventory(const Inventory &other)
@@ -822,12 +808,12 @@ Inventory & Inventory::operator = (const Inventory &other)
        // Gracefully handle self assignment
        if(this != &other)
        {
-               m_dirty = true;
                clear();
                m_itemdef = other.m_itemdef;
                for (InventoryList *list : other.m_lists) {
                        m_lists.push_back(new InventoryList(*list));
                }
+               setModified();
        }
        return *this;
 }
@@ -847,6 +833,7 @@ bool Inventory::operator == (const Inventory &other) const
 
 void Inventory::serialize(std::ostream &os, bool incremental) const
 {
+       //std::cout << "Serialize " << (int)incremental << ", n=" << m_lists.size() << std::endl;
        for (const InventoryList *list : m_lists) {
                if (!incremental || list->checkModified()) {
                        os << "List " << list->getName() << " " << list->getSize() << "\n";
@@ -881,7 +868,7 @@ void Inventory::deSerialize(std::istream &is)
 
                                delete list;
                                list = nullptr;
-                               m_dirty = true;
+                               setModified();
                        }
                        m_lists.erase(std::remove(m_lists.begin(), m_lists.end(),
                                        nullptr), m_lists.end());
@@ -934,7 +921,7 @@ void Inventory::deSerialize(std::istream &is)
 
 InventoryList * Inventory::addList(const std::string &name, u32 size)
 {
-       m_dirty = true;
+       setModified();
        s32 i = getListIndex(name);
        if(i != -1)
        {
@@ -980,7 +967,8 @@ bool Inventory::deleteList(const std::string &name)
        s32 i = getListIndex(name);
        if(i == -1)
                return false;
-       m_dirty = true;
+
+       setModified();
        delete m_lists[i];
        m_lists.erase(m_lists.begin() + i);
        return true;