2011-04-04 04:13:08 +02:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2011-04-04 04:13:08 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
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
|
2011-04-04 04:13:08 +02:00
|
|
|
(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
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2011-04-04 04:13:08 +02:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2011-04-04 04:13:08 +02:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2011-04-04 04:13:08 +02:00
|
|
|
|
2017-06-04 21:00:04 +02:00
|
|
|
#include <unordered_set>
|
2017-01-31 15:45:28 +01:00
|
|
|
#include "metadata.h"
|
2011-04-04 04:13:08 +02:00
|
|
|
|
|
|
|
/*
|
2011-11-13 11:48:05 +01:00
|
|
|
NodeMetadata stores arbitary amounts of data for special blocks.
|
|
|
|
Used for furnaces, chests and signs.
|
2011-04-04 04:13:08 +02:00
|
|
|
|
2011-11-13 11:48:05 +01:00
|
|
|
There are two interaction methods: inventory menu and text input.
|
|
|
|
Only one can be used for a single metadata, thus only inventory OR
|
|
|
|
text input should exist in a metadata.
|
2011-04-04 04:13:08 +02:00
|
|
|
*/
|
|
|
|
|
2011-04-04 14:13:19 +02:00
|
|
|
class Inventory;
|
2015-09-18 13:45:42 +02:00
|
|
|
class IItemDefManager;
|
2011-04-04 14:13:19 +02:00
|
|
|
|
2017-01-31 15:45:28 +01:00
|
|
|
class NodeMetadata : public Metadata
|
2011-04-04 04:13:08 +02:00
|
|
|
{
|
|
|
|
public:
|
2015-09-18 13:45:42 +02:00
|
|
|
NodeMetadata(IItemDefManager *item_def_mgr);
|
2012-03-19 01:08:04 +01:00
|
|
|
~NodeMetadata();
|
2015-05-05 20:30:46 +02:00
|
|
|
|
2017-05-10 15:29:21 +02:00
|
|
|
void serialize(std::ostream &os, u8 version, bool disk=true) const;
|
|
|
|
void deSerialize(std::istream &is, u8 version);
|
2015-05-05 20:30:46 +02:00
|
|
|
|
2012-03-19 01:08:04 +01:00
|
|
|
void clear();
|
2016-09-19 20:06:39 +02:00
|
|
|
bool empty() const;
|
2012-03-19 01:08:04 +01:00
|
|
|
|
|
|
|
// The inventory
|
2015-05-19 08:24:14 +02:00
|
|
|
Inventory *getInventory()
|
2012-03-19 01:08:04 +01:00
|
|
|
{
|
|
|
|
return m_inventory;
|
|
|
|
}
|
2011-11-28 16:11:14 +01:00
|
|
|
|
2017-05-10 15:29:21 +02:00
|
|
|
inline bool isPrivate(const std::string &name) const
|
|
|
|
{
|
|
|
|
return m_privatevars.count(name) != 0;
|
|
|
|
}
|
|
|
|
void markPrivate(const std::string &name, bool set);
|
|
|
|
|
2011-04-04 04:13:08 +02:00
|
|
|
private:
|
2017-05-10 15:29:21 +02:00
|
|
|
int countNonPrivate() const;
|
|
|
|
|
2012-03-19 01:08:04 +01:00
|
|
|
Inventory *m_inventory;
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_set<std::string> m_privatevars;
|
2011-04-04 04:13:08 +02:00
|
|
|
};
|
|
|
|
|
2012-03-19 01:08:04 +01:00
|
|
|
|
2011-04-04 23:24:47 +02:00
|
|
|
/*
|
|
|
|
List of metadata of all the nodes of a block
|
|
|
|
*/
|
|
|
|
|
2011-04-04 04:13:08 +02:00
|
|
|
class NodeMetadataList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
~NodeMetadataList();
|
|
|
|
|
2017-05-10 15:29:21 +02:00
|
|
|
void serialize(std::ostream &os, u8 blockver, bool disk=true) const;
|
2015-09-18 13:45:42 +02:00
|
|
|
void deSerialize(std::istream &is, IItemDefManager *item_def_mgr);
|
2015-05-05 20:30:46 +02:00
|
|
|
|
|
|
|
// Add all keys in this list to the vector keys
|
|
|
|
std::vector<v3s16> getAllKeys();
|
2011-04-04 04:13:08 +02:00
|
|
|
// Get pointer to data
|
2015-05-05 20:30:46 +02:00
|
|
|
NodeMetadata *get(v3s16 p);
|
2011-04-04 04:13:08 +02:00
|
|
|
// Deletes data
|
|
|
|
void remove(v3s16 p);
|
|
|
|
// Deletes old data and sets a new one
|
|
|
|
void set(v3s16 p, NodeMetadata *d);
|
2012-03-19 01:08:04 +01:00
|
|
|
// Deletes all
|
|
|
|
void clear();
|
2015-05-05 20:30:46 +02:00
|
|
|
|
2011-04-04 04:13:08 +02:00
|
|
|
private:
|
2016-09-19 20:06:39 +02:00
|
|
|
int countNonEmpty() const;
|
|
|
|
|
2015-05-05 20:30:46 +02:00
|
|
|
std::map<v3s16, NodeMetadata *> m_data;
|
2011-04-04 04:13:08 +02:00
|
|
|
};
|