From 98faeac5a7b382e5d7ce0474bf7d52fc5975a23c Mon Sep 17 00:00:00 2001 From: DS Date: Thu, 20 Aug 2020 22:25:29 +0200 Subject: [PATCH] Load media from subfolders (#9065) --- doc/lua_api.txt | 24 +++++++++++------- .../dirt_with_grass/default_grass.png | Bin 0 -> 829 bytes .../default_grass_side.png | Bin .../textures/dirt_with_grass/info.txt | 3 +++ src/server.cpp | 16 ++++++++---- src/server/mods.cpp | 10 ++++---- src/unittest/test_servermodmanager.cpp | 2 -- 7 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 games/devtest/mods/basenodes/textures/dirt_with_grass/default_grass.png rename games/devtest/mods/basenodes/textures/{ => dirt_with_grass}/default_grass_side.png (100%) create mode 100644 games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 49fbe0d94..9770ae4a9 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -152,7 +152,11 @@ Mod directory structure │   ├── models │   ├── textures │   │   ├── modname_stuff.png - │   │   └── modname_something_else.png + │   │   ├── modname_something_else.png + │   │   ├── subfolder_foo + │   │   │ ├── modname_more_stuff.png + │   │   │ └── another_subfolder + │   │   └── bar_subfolder │   ├── sounds │   ├── media │   ├── locale @@ -221,18 +225,20 @@ registered callbacks. `minetest.settings` can be used to read custom or existing settings at load time, if necessary. (See [`Settings`]) -### `models` - -Models for entities or meshnodes. - -### `textures`, `sounds`, `media` +### `textures`, `sounds`, `media`, `models`, `locale` Media files (textures, sounds, whatever) that will be transferred to the -client and will be available for use by the mod. +client and will be available for use by the mod and translation files for +the clients (see [Translations]). -### `locale` +It is suggested to use the folders for the purpous they are thought for, +eg. put textures into `textures`, translation files into `locale`, +models for entities or meshnodes into `models` et cetera. -Translation files for the clients. (See [Translations]) +These folders and subfolders can contain subfolders. +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. Naming conventions ------------------ diff --git a/games/devtest/mods/basenodes/textures/dirt_with_grass/default_grass.png b/games/devtest/mods/basenodes/textures/dirt_with_grass/default_grass.png new file mode 100644 index 0000000000000000000000000000000000000000..29fde6b26a7689e0091c92f49355ab7072b7c056 GIT binary patch literal 829 zcmV-D1H$}?P)+ajpshR{=5W`0H1vO`a^tn z^HmA((KjzhfEz!)^)S)UHv!<<2ft&20N}#aXNn>Qfc>9duElEayO*wC{B{5P7vm}i zfG>V{Q@MEUoa>pc5p+$F7hLwxwD9=GnM}r65ueH&GYKIICc4=-gI+FmhfF5ibEvhZ5uK&W ziu3!yrfPY*M4Zlm$EDS*d+vqq7kWB$?XncF2BUlR@p5efxZ6R$t%2REYRDb^U zFU#9IcaMWjb$u(que|XX6D`pjj8)sFUP!4%_!3&#=wKU$2@S7$u}D^kVnP+X^OS%5 zAjcZEJ-tZk<+N-Y>DVq(tNX_@F2w0Gep%Mh&~^+rNwfa}tdL}?X}J{Q00000NkvXX Hu0mjfO)-U1 literal 0 HcmV?d00001 diff --git a/games/devtest/mods/basenodes/textures/default_grass_side.png b/games/devtest/mods/basenodes/textures/dirt_with_grass/default_grass_side.png similarity index 100% rename from games/devtest/mods/basenodes/textures/default_grass_side.png rename to games/devtest/mods/basenodes/textures/dirt_with_grass/default_grass_side.png diff --git a/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt b/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt new file mode 100644 index 000000000..8db21ed9c --- /dev/null +++ b/games/devtest/mods/basenodes/textures/dirt_with_grass/info.txt @@ -0,0 +1,3 @@ +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/src/server.cpp b/src/server.cpp index 53ee8c444..ef36aedca 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2494,19 +2494,25 @@ void Server::fillMediaCache() // Collect all media file paths std::vector paths; - m_modmgr->getModsMediaPaths(paths); - fs::GetRecursiveDirs(paths, m_gamespec.path + DIR_DELIM + "textures"); + // The paths are ordered in descending priority fs::GetRecursiveDirs(paths, porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server"); + fs::GetRecursiveDirs(paths, m_gamespec.path + DIR_DELIM + "textures"); + m_modmgr->getModsMediaPaths(paths); // Collect media file information from paths into cache for (const std::string &mediapath : paths) { std::vector dirlist = fs::GetDirListing(mediapath); for (const fs::DirListNode &dln : dirlist) { - if (dln.dir) // Ignore dirs + if (dln.dir) // Ignore dirs (already in paths) continue; + + const std::string &filename = dln.name; + if (m_media.find(filename) != m_media.end()) // Do not override + continue; + std::string filepath = mediapath; - filepath.append(DIR_DELIM).append(dln.name); - addMediaFile(dln.name, filepath); + filepath.append(DIR_DELIM).append(filename); + addMediaFile(filename, filepath); } } diff --git a/src/server/mods.cpp b/src/server/mods.cpp index 6ac530739..cf1467648 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -99,10 +99,10 @@ void ServerModManager::getModNames(std::vector &modlist) const void ServerModManager::getModsMediaPaths(std::vector &paths) const { for (const ModSpec &spec : m_sorted_mods) { - paths.push_back(spec.path + DIR_DELIM + "textures"); - paths.push_back(spec.path + DIR_DELIM + "sounds"); - paths.push_back(spec.path + DIR_DELIM + "media"); - paths.push_back(spec.path + DIR_DELIM + "models"); - paths.push_back(spec.path + DIR_DELIM + "locale"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "textures"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "sounds"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "models"); + fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "locale"); } } diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp index 799936757..e3edb0c32 100644 --- a/src/unittest/test_servermodmanager.cpp +++ b/src/unittest/test_servermodmanager.cpp @@ -169,6 +169,4 @@ void TestServerModManager::testGetModMediaPaths() std::vector result; sm.getModsMediaPaths(result); UASSERTEQ(bool, result.empty(), false); - // We should have 5 folders for each mod (textures, media, locale, model, sounds) - UASSERTEQ(unsigned long, result.size() % 5, 0); }