Skip to content

Commit

Permalink
Allow overwriting media files of dependencies (#10752)
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Feb 23, 2021
1 parent 2968108 commit 4abe4b8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -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
------------------

Expand Down
Binary file modified games/devtest/mods/basenodes/textures/default_dirt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

7 changes: 7 additions & 0 deletions 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.
1 change: 1 addition & 0 deletions games/devtest/mods/unittests/mod.conf
@@ -1,2 +1,3 @@
name = unittests
description = Adds automated unit tests for the engine
depends = basenodes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion src/server/mods.cpp
Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions src/server/mods.h
Expand Up @@ -42,5 +42,13 @@ class ServerModManager : public ModConfiguration
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;
};

0 comments on commit 4abe4b8

Please sign in to comment.