aboutsummaryrefslogtreecommitdiff
path: root/src/nodedef.cpp
diff options
context:
space:
mode:
authorHugues Ross <hugues.ross@gmail.com>2020-04-14 14:41:29 -0400
committerGitHub <noreply@github.com>2020-04-14 20:41:29 +0200
commit5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7 (patch)
treede590965f9f1cf68a4b6ee7ca802aaa5c0b987ee /src/nodedef.cpp
parent7e21b3cd4883eb8b9eb7e9ca49e50f6f0c7bc0d6 (diff)
downloadminetest-5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7.tar.gz
minetest-5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7.tar.bz2
minetest-5cf6318117edcae6bf30d829d9e9dd9dbf1d4bf7.zip
Refactor texture overrides and add new features (#9600)
* Refactor texture overrides, and add new features: - Texture overrides can support multiple targets in one line - Texture override files can have comment lines - Item images/wield images can be overridden * Formatting changes * Address soime feedback - Pass vectors by const reference - Log syntax errors as warnings - Remove 'C' prefix from TextureOverrideSource * Simplify override target checks with an inline helper function * make linter happy * Apply feedback suggestions Co-Authored-By: rubenwardy <rw@rubenwardy.com> * Remove remaining != 0 checks * Update copyright notice Co-authored-by: sfan5 <sfan5@live.de> Co-authored-by: rubenwardy <rw@rubenwardy.com>
Diffstat (limited to 'src/nodedef.cpp')
-rw-r--r--src/nodedef.cpp67
1 files changed, 21 insertions, 46 deletions
diff --git a/src/nodedef.cpp b/src/nodedef.cpp
index b6eca9497..37332c3c6 100644
--- a/src/nodedef.cpp
+++ b/src/nodedef.cpp
@@ -1304,60 +1304,35 @@ void NodeDefManager::updateAliases(IItemDefManager *idef)
}
}
-void NodeDefManager::applyTextureOverrides(const std::string &override_filepath)
+void NodeDefManager::applyTextureOverrides(const std::vector<TextureOverride> &overrides)
{
infostream << "NodeDefManager::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++;
- // Also trim '\r' on DOS-style files
- line = trim(line);
- if (line.empty())
- 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;
- }
+ "overrides to textures" << std::endl;
+ for (const TextureOverride& texture_override : overrides) {
content_t id;
- if (!getId(splitted[0], id))
+ if (!getId(texture_override.id, id))
continue; // Ignore unknown node
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 (TileDef &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;
- }
+ if (texture_override.hasTarget(OverrideTarget::TOP))
+ nodedef.tiledef[0].name = texture_override.texture;
+
+ if (texture_override.hasTarget(OverrideTarget::BOTTOM))
+ nodedef.tiledef[1].name = texture_override.texture;
+
+ if (texture_override.hasTarget(OverrideTarget::RIGHT))
+ nodedef.tiledef[2].name = texture_override.texture;
+
+ if (texture_override.hasTarget(OverrideTarget::LEFT))
+ nodedef.tiledef[3].name = texture_override.texture;
+
+ if (texture_override.hasTarget(OverrideTarget::BACK))
+ nodedef.tiledef[4].name = texture_override.texture;
+
+ if (texture_override.hasTarget(OverrideTarget::FRONT))
+ nodedef.tiledef[5].name = texture_override.texture;
}
}