summaryrefslogtreecommitdiff
path: root/src/nodedef.cpp
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2015-03-30 11:55:29 +0100
committerest31 <MTest31@outlook.com>2015-05-19 21:27:07 +0200
commit603297cc352cab685dd01dcd645999624ad17c0b (patch)
tree0be1fd0e2ab64578549ee94b3b7c9a3d1c868859 /src/nodedef.cpp
parent43702ec6ac0fae7c8ef04be82bcca72ba9bec017 (diff)
downloadminetest-603297cc352cab685dd01dcd645999624ad17c0b.tar.gz
minetest-603297cc352cab685dd01dcd645999624ad17c0b.tar.bz2
minetest-603297cc352cab685dd01dcd645999624ad17c0b.zip
Add texture overriding
Diffstat (limited to 'src/nodedef.cpp')
-rw-r--r--src/nodedef.cpp65
1 files changed, 63 insertions, 2 deletions
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index ac432d196..6c2e96c4f 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "exceptions.h"
#include "debug.h"
#include "gamedef.h"
+#include <fstream> // Used in applyTextureOverrides()
/*
NodeBox
@@ -397,6 +398,7 @@ public:
virtual content_t set(const std::string &name, const ContentFeatures &def);
virtual content_t allocateDummy(const std::string &name);
virtual void updateAliases(IItemDefManager *idef);
+ virtual void applyTextureOverrides(const std::string &override_filepath);
virtual void updateTextures(IGameDef *gamedef,
void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress),
void *progress_cbk_args);
@@ -670,7 +672,7 @@ content_t CNodeDefManager::set(const std::string &name, const ContentFeatures &d
j = m_group_to_items.find(group_name);
if (j == m_group_to_items.end()) {
m_group_to_items[group_name].push_back(
- std::make_pair(id, i->second));
+ std::make_pair(id, i->second));
} else {
GroupItems &items = j->second;
items.push_back(std::make_pair(id, i->second));
@@ -700,7 +702,66 @@ void CNodeDefManager::updateAliases(IItemDefManager *idef)
content_t id;
if (m_name_id_mapping.getId(convert_to, id)) {
m_name_id_mapping_with_aliases.insert(
- std::make_pair(name, id));
+ std::make_pair(name, id));
+ }
+ }
+}
+
+void CNodeDefManager::applyTextureOverrides(const std::string &override_filepath)
+{
+ infostream << "CNodeDefManager::applyTextureOverrides(): Applying "
+ "overrides to textures from " << override_filepath << std::endl;
+
+ std::ifstream infile(override_filepath.c_str());
+ std::string line;
+ int line_c = 0;
+ while (std::getline(infile, line)) {
+ line_c++;
+ if (trim(line) == "")
+ continue;
+ std::vector<std::string> splitted = str_split(line, ' ');
+ if (splitted.size() != 3) {
+ errorstream << override_filepath
+ << ":" << line_c << " Could not apply texture override \""
+ << line << "\": Syntax error" << std::endl;
+ continue;
+ }
+
+ content_t id;
+ if (!getId(splitted[0], id)) {
+ errorstream << override_filepath
+ << ":" << line_c << " Could not apply texture override \""
+ << line << "\": Unknown node \""
+ << splitted[0] << "\"" << std::endl;
+ continue;
+ }
+
+ ContentFeatures &nodedef = m_content_features[id];
+
+ if (splitted[1] == "top")
+ nodedef.tiledef[0].name = splitted[2];
+ else if (splitted[1] == "bottom")
+ nodedef.tiledef[1].name = splitted[2];
+ else if (splitted[1] == "right")
+ nodedef.tiledef[2].name = splitted[2];
+ else if (splitted[1] == "left")
+ nodedef.tiledef[3].name = splitted[2];
+ else if (splitted[1] == "back")
+ nodedef.tiledef[4].name = splitted[2];
+ else if (splitted[1] == "front")
+ nodedef.tiledef[5].name = splitted[2];
+ else if (splitted[1] == "all" || splitted[1] == "*")
+ for (int i = 0; i < 6; i++)
+ nodedef.tiledef[i].name = splitted[2];
+ else if (splitted[1] == "sides")
+ for (int i = 2; i < 6; i++)
+ nodedef.tiledef[i].name = splitted[2];
+ else {
+ errorstream << override_filepath
+ << ":" << line_c << " Could not apply texture override \""
+ << line << "\": Unknown node side \""
+ << splitted[1] << "\"" << std::endl;
+ continue;
}
}
}