From 389fe31ace38a8f53c210ff5ae823eae1780dfc8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Tue, 5 Apr 2011 00:24:47 +0300 Subject: changed node metadata format to better accomodate future needs and problems --- src/nodemetadata.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 16 deletions(-) (limited to 'src/nodemetadata.cpp') diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp index 294db178f..2405e7601 100644 --- a/src/nodemetadata.cpp +++ b/src/nodemetadata.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapnode.h" #include "exceptions.h" #include "inventory.h" +#include /* NodeMetadata @@ -39,21 +40,39 @@ NodeMetadata::~NodeMetadata() NodeMetadata* NodeMetadata::deSerialize(std::istream &is) { + // Read id u8 buf[2]; is.read((char*)buf, 2); s16 id = readS16(buf); - + + // Read data + std::string data = deSerializeString(is); + + // Find factory function core::map::Node *n; n = m_types.find(id); if(n == NULL) { - dstream<<"NodeMetadata(): No factory for typeId="<addList("fuel", 1); + m_inventory->addList("src", 1); + m_inventory->addList("dst", 1); +} +FurnaceNodeMetadata::~FurnaceNodeMetadata() +{ + delete m_inventory; +} +u16 FurnaceNodeMetadata::typeId() const +{ + return CONTENT_FURNACE; +} +NodeMetadata* FurnaceNodeMetadata::clone() +{ + FurnaceNodeMetadata *d = new FurnaceNodeMetadata(); + *d->m_inventory = *m_inventory; + return d; +} +NodeMetadata* FurnaceNodeMetadata::create(std::istream &is) +{ + FurnaceNodeMetadata *d = new FurnaceNodeMetadata(); + d->m_inventory->deSerialize(is); + /*std::string params; + std::getline(is, params, '\n');*/ + return d; +} +void FurnaceNodeMetadata::serializeBody(std::ostream &os) +{ + m_inventory->serialize(os); + // This line will contain the other parameters + //os<<"\n"; +} +std::string FurnaceNodeMetadata::infoText() +{ + return "Furnace"; +} +void FurnaceNodeMetadata::inventoryModified() +{ + dstream<<"Furnace inventory modification callback"<