mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Load media from subfolders (#9065)
This commit is contained in:
parent
9c7340104a
commit
98faeac5a7
7 changed files with 34 additions and 21 deletions
|
@ -2494,19 +2494,25 @@ void Server::fillMediaCache()
|
|||
|
||||
// Collect all media file paths
|
||||
std::vector<std::string> 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<fs::DirListNode> 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -99,10 +99,10 @@ 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) {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,6 +169,4 @@ void TestServerModManager::testGetModMediaPaths()
|
|||
std::vector<std::string> 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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue