]> git.lizzy.rs Git - minetest.git/commitdiff
Fix media overriding regression (#12602)
authorLars Müller <34514239+appgurueu@users.noreply.github.com>
Fri, 29 Jul 2022 08:19:36 +0000 (10:19 +0200)
committerGitHub <noreply@github.com>
Fri, 29 Jul 2022 08:19:36 +0000 (10:19 +0200)
src/server/mods.cpp
src/unittest/test_servermodmanager.cpp

index ac4181e4d2ba6af4a93bafb451f09eb9b0949d2c..0e9bf49117de776981951fd5d8754471bf8f7baf 100644 (file)
@@ -94,7 +94,11 @@ void ServerModManager::getModNames(std::vector<std::string> &modlist) const
 
 void ServerModManager::getModsMediaPaths(std::vector<std::string> &paths) const
 {
-       for (const auto &spec : configuration.getMods()) {
+       // Iterate mods in reverse load order: Media loading expects higher priority media files first
+       // and mods loading later should be able to override media of already loaded mods
+       const auto mods = configuration.getMods();
+       for (auto it = mods.crbegin(); it != 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");
index 4c473d8b5c677faa4f72811ee37863c062287c33..91bf5d3a4e04fce3c1d9e33b64407525f6ff4048 100644 (file)
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "server/mods.h"
 #include "settings.h"
 #include "test_config.h"
+#include "util/string.h"
 
 class TestServerModManager : public TestBase
 {
@@ -190,4 +191,11 @@ void TestServerModManager::testGetModMediaPaths()
        std::vector<std::string> result;
        sm.getModsMediaPaths(result);
        UASSERTEQ(bool, result.empty(), false);
+
+       // Test media overriding:
+       // unittests depends on basenodes to override default_dirt.png,
+       // thus the unittests texture path must come first in the returned media paths to take priority
+       auto it = std::find(result.begin(), result.end(), sm.getModSpec("unittests")->path + DIR_DELIM + "textures");
+       UASSERT(it != result.end());
+       UASSERT(std::find(++it, result.end(), sm.getModSpec("basenodes")->path + DIR_DELIM + "textures") != result.end());
 }