X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Finventory.cpp;h=2ce50e0191592589a892898556d144891cb11d7c;hb=be4670fecfceabd6760153e9a5b4f9868614e573;hp=3d6707f60684b22a7209bc56456fc7bb00f7571b;hpb=f8c3743991a6897c7133bf35dc2699b8b5f9df7c;p=dragonfireclient.git diff --git a/src/inventory.cpp b/src/inventory.cpp index 3d6707f60..2ce50e019 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -1,25 +1,24 @@ /* -Minetest-c55 -Copyright (C) 2010-2011 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU Lesser General Public License for more details. -You should have received a copy of the GNU General Public License along +You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "inventory.h" #include "serialization.h" -#include "utility.h" #include "debug.h" #include #include "log.h" @@ -27,6 +26,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "strfnd.h" #include "content_mapnode.h" // For loading legacy MaterialItems #include "nameidmapping.h" // For loading legacy MaterialItems +#include "util/serialize.h" +#include "util/string.h" /* ItemStack @@ -174,7 +175,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef) // Convert old materials if(material <= 0xff) material = content_translate_from_19_to_internal(material); - if(material > MAX_CONTENT) + if(material > 0xfff) throw SerializationError("Too large material number"); // Convert old id to name NameIdMapping legacy_nimap; @@ -193,7 +194,7 @@ void ItemStack::deSerialize(std::istream &is, IItemDefManager *itemdef) is>>material; u16 materialcount; is>>materialcount; - if(material > MAX_CONTENT) + if(material > 0xfff) throw SerializationError("Too large material number"); // Convert old id to name NameIdMapping legacy_nimap; @@ -430,6 +431,7 @@ InventoryList::InventoryList(std::string name, u32 size, IItemDefManager *itemde { m_name = name; m_size = size; + m_width = 0; m_itemdef = itemdef; clearItems(); //m_dirty = false; @@ -458,10 +460,22 @@ void InventoryList::setSize(u32 newsize) m_size = newsize; } +void InventoryList::setWidth(u32 newwidth) +{ + m_width = newwidth; +} + +void InventoryList::setName(const std::string &name) +{ + m_name = name; +} + void InventoryList::serialize(std::ostream &os) const { //os.imbue(std::locale("C")); + os<<"Width "<> m_width; + if (iss.fail()) + throw SerializationError("incorrect width property"); + } else if(name == "Item") { if(item_i > getSize() - 1) @@ -521,10 +542,6 @@ void InventoryList::deSerialize(std::istream &is) throw SerializationError("too many items"); m_items[item_i++].clear(); } - else - { - throw SerializationError("Unknown inventory identifier"); - } } } @@ -537,6 +554,7 @@ InventoryList & InventoryList::operator = (const InventoryList &other) { m_items = other.m_items; m_size = other.m_size; + m_width = other.m_width; m_name = other.m_name; m_itemdef = other.m_itemdef; //setDirty(true); @@ -544,6 +562,26 @@ InventoryList & InventoryList::operator = (const InventoryList &other) return *this; } +bool InventoryList::operator == (const InventoryList &other) +{ + if(m_size != other.m_size) + return false; + if(m_width != other.m_width) + return false; + if(m_name != other.m_name) + return false; + for(u32 i=0; i Inventory::getLists() +{ + std::vector lists; + for(u32 i=0; i