summaryrefslogtreecommitdiff
path: root/src/nodemetadata.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-05-05 14:30:46 -0400
committerkwolekr <kwolekr@minetest.net>2015-05-05 16:21:59 -0400
commitb785577f03d00c83236782876def4c900edbba4e (patch)
tree389f3baa9e4b3d6abcab1d752a248bcdc933b52d /src/nodemetadata.cpp
parentb45df9d6a73d97671cbdd38d77e9b153a80fb458 (diff)
downloadminetest-b785577f03d00c83236782876def4c900edbba4e.tar.gz
minetest-b785577f03d00c83236782876def4c900edbba4e.tar.bz2
minetest-b785577f03d00c83236782876def4c900edbba4e.zip
Add core.find_nodes_with_meta() script API
Diffstat (limited to 'src/nodemetadata.cpp')
-rw-r--r--src/nodemetadata.cpp34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index 1e40a1630..bd54d2256 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -157,10 +157,21 @@ NodeMetadataList::~NodeMetadataList()
clear();
}
-NodeMetadata* NodeMetadataList::get(v3s16 p)
+std::vector<v3s16> NodeMetadataList::getAllKeys()
{
- std::map<v3s16, NodeMetadata*>::const_iterator n = m_data.find(p);
- if(n == m_data.end())
+ std::vector<v3s16> keys;
+
+ std::map<v3s16, NodeMetadata *>::const_iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it)
+ keys.push_back(it->first);
+
+ return keys;
+}
+
+NodeMetadata *NodeMetadataList::get(v3s16 p)
+{
+ std::map<v3s16, NodeMetadata *>::const_iterator n = m_data.find(p);
+ if (n == m_data.end())
return NULL;
return n->second;
}
@@ -168,8 +179,7 @@ NodeMetadata* NodeMetadataList::get(v3s16 p)
void NodeMetadataList::remove(v3s16 p)
{
NodeMetadata *olddata = get(p);
- if(olddata)
- {
+ if (olddata) {
delete olddata;
m_data.erase(p);
}
@@ -183,16 +193,15 @@ void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
void NodeMetadataList::clear()
{
- for(std::map<v3s16, NodeMetadata*>::iterator
- i = m_data.begin();
- i != m_data.end(); i++)
- {
- delete i->second;
+ std::map<v3s16, NodeMetadata*>::iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it) {
+ delete it->second;
}
m_data.clear();
}
-std::string NodeMetadata::getString(const std::string &name, unsigned short recursion) const
+std::string NodeMetadata::getString(const std::string &name,
+ unsigned short recursion) const
{
std::map<std::string, std::string>::const_iterator it;
it = m_stringvars.find(name);
@@ -211,7 +220,8 @@ void NodeMetadata::setString(const std::string &name, const std::string &var)
}
}
-std::string NodeMetadata::resolveString(const std::string &str, unsigned short recursion) const
+std::string NodeMetadata::resolveString(const std::string &str,
+ unsigned short recursion) const
{
if (recursion > 1) {
return str;