summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2021-02-23 19:39:15 +0100
committerGitHub <noreply@github.com>2021-02-23 19:39:15 +0100
commit4abe4b87b5902bff229505b83b9bddb9a8f759cd (patch)
tree7c90751b6c17fdc380a9c1f28db9cdbccd8978bb
parent29681085b9762e8cf0e953014ca0e8d2890713ef (diff)
downloadminetest-4abe4b87b5902bff229505b83b9bddb9a8f759cd.tar.gz
minetest-4abe4b87b5902bff229505b83b9bddb9a8f759cd.tar.bz2
minetest-4abe4b87b5902bff229505b83b9bddb9a8f759cd.zip
Allow overwriting media files of dependencies (#10752)
-rw-r--r--doc/lua_api.txt3
-rw-r--r--games/devtest/mods/basenodes/textures/default_dirt.pngbin790 -> 7303 bytes
-rw-r--r--games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt3
-rw-r--r--games/devtest/mods/basenodes/textures/info.txt7
-rw-r--r--games/devtest/mods/unittests/mod.conf1
-rw-r--r--games/devtest/mods/unittests/textures/default_dirt.pngbin0 -> 790 bytes
-rw-r--r--src/server/mods.cpp3
-rw-r--r--src/server/mods.h8
8 files changed, 21 insertions, 4 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index a9c3bcdd9..d3165b9fd 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -256,6 +256,9 @@ Subfolders with names starting with `_` or `.` are ignored.
If a subfolder contains a media file with the same name as a media file
in one of its parents, the parent's file is used.
+Although it is discouraged, a mod can overwrite a media file of any mod that it
+depends on by supplying a file with an equal name.
+
Naming conventions
------------------
diff --git a/games/devtest/mods/basenodes/textures/default_dirt.png b/games/devtest/mods/basenodes/textures/default_dirt.png
index 58670305d..aa75bffb6 100644
--- a/games/devtest/mods/basenodes/textures/default_dirt.png
+++ b/games/devtest/mods/basenodes/textures/default_dirt.png
Binary files differ
diff --git a/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt b/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt
deleted file mode 100644
index 8db21ed9c..000000000
--- a/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-This is for testing loading textures from subfolders.
-If it works correctly, the default_grass_side.png file in this folder is used but
-default_grass.png is not overwritten by the file in this folder.
diff --git a/games/devtest/mods/basenodes/textures/info.txt b/games/devtest/mods/basenodes/textures/info.txt
new file mode 100644
index 000000000..2d4ef7efa
--- /dev/null
+++ b/games/devtest/mods/basenodes/textures/info.txt
@@ -0,0 +1,7 @@
+
+The dirt_with_grass folder is for testing loading textures from subfolders.
+If it works correctly, the default_grass_side.png file in the folder is used but
+default_grass.png is not overwritten by the file in the folder.
+
+default_dirt.png should be overwritten by the default_dirt.png in the unittests
+mod which depends on basenodes.
diff --git a/games/devtest/mods/unittests/mod.conf b/games/devtest/mods/unittests/mod.conf
index 0d5e3c959..fa94e01a6 100644
--- a/games/devtest/mods/unittests/mod.conf
+++ b/games/devtest/mods/unittests/mod.conf
@@ -1,2 +1,3 @@
name = unittests
description = Adds automated unit tests for the engine
+depends = basenodes
diff --git a/games/devtest/mods/unittests/textures/default_dirt.png b/games/devtest/mods/unittests/textures/default_dirt.png
new file mode 100644
index 000000000..58670305d
--- /dev/null
+++ b/games/devtest/mods/unittests/textures/default_dirt.png
Binary files differ
diff --git a/src/server/mods.cpp b/src/server/mods.cpp
index cf1467648..83fa12da9 100644
--- a/src/server/mods.cpp
+++ b/src/server/mods.cpp
@@ -98,7 +98,8 @@ void ServerModManager::getModNames(std::vector<std::string> &modlist) const
void ServerModManager::getModsMediaPaths(std::vector<std::string> &paths) const
{
- for (const ModSpec &spec : m_sorted_mods) {
+ for (auto it = m_sorted_mods.crbegin(); it != m_sorted_mods.crend(); it++) {
+ const ModSpec &spec = *it;
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "textures");
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "sounds");
fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media");
diff --git a/src/server/mods.h b/src/server/mods.h
index 54774bd86..8954bbf72 100644
--- a/src/server/mods.h
+++ b/src/server/mods.h
@@ -42,5 +42,13 @@ public:
void loadMods(ServerScripting *script);
const ModSpec *getModSpec(const std::string &modname) const;
void getModNames(std::vector<std::string> &modlist) const;
+ /**
+ * Recursively gets all paths of mod folders that can contain media files.
+ *
+ * Result is ordered in descending priority, ie. files from an earlier path
+ * should not be replaced by files from a latter one.
+ *
+ * @param paths result vector
+ */
void getModsMediaPaths(std::vector<std::string> &paths) const;
};