Example #1
0
void ItemAttribute::serialize(PropWriteStream& stream) const
{
    bool ok;
    if(m_data.type() == typeid(std::string))
    {
        stream.addByte((uint8_t)STRING);
        stream.addLongString(getString(ok));
    }
    else if(m_data.type() == typeid(int32_t))
    {
        stream.addByte((uint8_t)INTEGER);
        stream.addLong(getInteger(ok));
    }
    else if(m_data.type() == typeid(float))
    {
        stream.addByte((uint8_t)FLOAT);
        stream.addLong(getFloat(ok));
    }
    else if(m_data.type() == typeid(bool))
    {
        stream.addByte((uint8_t)BOOLEAN);
        stream.addByte(getBoolean(ok));
    }
    else
        std::clog << "[ItemAttribute::serialize]: Invalid data type." << std::endl;
}
bool IOMapSerialize::saveTile(PropWriteStream& stream, const Tile* tile)
{
	int32_t tileCount = tile->getThingCount();
	if(!tileCount)
		return true;

	std::vector<Item*> items;
	Item* item = NULL;
	for(; tileCount > 0; --tileCount)
	{
		if((item = tile->__getThing(tileCount - 1)->getItem()) && // CHECKME: wouldn't it be better to use TileItemVector in here?
			(item->isMovable() || item->forceSerialize()))
			items.push_back(item);
	}

	tileCount = items.size(); //lame, but at least we don't need a new variable
	if(tileCount > 0)
	{
		stream.addShort(tile->getPosition().x);
		stream.addShort(tile->getPosition().y);
		stream.addByte(tile->getPosition().z);

		stream.addLong(tileCount);
		for(std::vector<Item*>::iterator it = items.begin(); it != items.end(); ++it)
			saveItem(stream, (*it));
	}

	return true;
}
Example #3
0
bool BedItem::serializeAttr(PropWriteStream& propWriteStream) const
{
	bool ret = Item::serializeAttr(propWriteStream);
	if(!sleeper)
		return ret;

	propWriteStream.addByte(ATTR_SLEEPERGUID);
	propWriteStream.addLong(sleeper);
	return ret;
}
void ItemAttribute::serialize(PropWriteStream& stream) const
{
	stream.addByte((uint8_t)type);
	switch(type)
	{
		case STRING:
			stream.addLongString(*getString());
			break;
		case INTEGER:
			stream.addLong(*(uint32_t*)getInteger());
			break;
		case FLOAT:
			stream.addLong(*(uint32_t*)getFloat());
			break;
		case BOOLEAN:
			stream.addByte(*(uint8_t*)getBoolean());
		default:
			break;
	}
}
bool IOMapSerialize::saveItem(PropWriteStream& stream, const Item* item)
{
	stream.addShort(item->getID());
	item->serializeAttr(stream);
	if(const Container* container = item->getContainer())
	{
		stream.addByte(ATTR_CONTAINER_ITEMS);
		stream.addLong(container->size());
		for(ItemList::const_reverse_iterator rit = container->getReversedItems(); rit != container->getReversedEnd(); ++rit)
			saveItem(stream, (*rit));
	}

	stream.addByte(ATTR_END);
	return true;
}