Skip to content

Commit

Permalink
Fix media overriding regression (minetest#12602)
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Jul 29, 2022
1 parent 6611d7e commit 99c8295
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/server/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions src/unittest/test_servermodmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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());
}

0 comments on commit 99c8295

Please sign in to comment.