summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvil Eye <malusluminis@hotmail.com>2024-02-24 10:31:13 +0000
committerEvil Eye <malusluminis@hotmail.com>2024-02-24 10:31:13 +0000
commit82c92a9a6c9bfec67d35d24cb6879e72467810ee (patch)
treec1c28f6419d405a15759df65baa01f0ba934e561
parent6d35b626cf5f3efac7748d9a5b697f12a780176b (diff)
parent3fbd97ffc876cf776779db3e3b4cde6984b1cacb (diff)
Merge branch 'bookart-is-textures-too' into 'master'
Consider bookart a valid prefix for regular textures and vice versa Closes #7535 See merge request OpenMW/openmw!3342
-rw-r--r--CHANGELOG.md1
-rw-r--r--components/misc/resourcehelpers.cpp40
-rw-r--r--components/misc/resourcehelpers.hpp3
3 files changed, 30 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8b9b90ae75..ea44cab4b1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -104,6 +104,7 @@
Bug #7475: Equipping a constant effect item doesn't update the magic menu
Bug #7502: Data directories dialog (0.48.0) forces adding subdirectory instead of intended directory
Bug #7505: Distant terrain does not support sample size greater than cell size
+ Bug #7535: Bookart paths for textures in OpenMW vs vanilla Morrowind
Bug #7553: Faction reaction loading is incorrect
Bug #7557: Terrain::ChunkManager::createChunk is called twice for the same position, lod on initial loading
Bug #7573: Drain Fatigue can't bring fatigue below zero by default
diff --git a/components/misc/resourcehelpers.cpp b/components/misc/resourcehelpers.cpp
index aa0e0dec7d..ab6aa7907c 100644
--- a/components/misc/resourcehelpers.cpp
+++ b/components/misc/resourcehelpers.cpp
@@ -47,7 +47,7 @@ bool Misc::ResourceHelpers::changeExtensionToDds(std::string& path)
}
std::string Misc::ResourceHelpers::correctResourcePath(
- std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs)
+ std::span<const std::string_view> topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs)
{
/* Bethesda at some point converted all their BSA
* textures from tga to dds for increased load speed, but all
@@ -66,16 +66,30 @@ std::string Misc::ResourceHelpers::correctResourcePath(
correctedPath.erase(0, 1);
// Handle top level directory
- if (!correctedPath.starts_with(topLevelDirectory) || correctedPath.size() <= topLevelDirectory.size()
- || correctedPath[topLevelDirectory.size()] != '\\')
+ bool needsPrefix = true;
+ for (std::string_view potentialTopLevelDirectory : topLevelDirectories)
{
- std::string topLevelPrefix = std::string{ topLevelDirectory } + '\\';
- size_t topLevelPos = correctedPath.find('\\' + topLevelPrefix);
- if (topLevelPos == std::string::npos)
- correctedPath = topLevelPrefix + correctedPath;
+ if (correctedPath.starts_with(potentialTopLevelDirectory)
+ && correctedPath.size() > potentialTopLevelDirectory.size()
+ && correctedPath[potentialTopLevelDirectory.size()] == '\\')
+ {
+ needsPrefix = false;
+ break;
+ }
else
- correctedPath.erase(0, topLevelPos + 1);
+ {
+ std::string topLevelPrefix = std::string{ potentialTopLevelDirectory } + '\\';
+ size_t topLevelPos = correctedPath.find('\\' + topLevelPrefix);
+ if (topLevelPos != std::string::npos)
+ {
+ correctedPath.erase(0, topLevelPos + 1);
+ needsPrefix = false;
+ break;
+ }
+ }
}
+ if (needsPrefix)
+ correctedPath = std::string{ topLevelDirectories.front() } + '\\' + correctedPath;
std::string origExt = correctedPath;
@@ -90,7 +104,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(
return origExt;
// fall back to a resource in the top level directory if it exists
- std::string fallback{ topLevelDirectory };
+ std::string fallback{ topLevelDirectories.front() };
fallback += '\\';
fallback += getBasename(correctedPath);
if (vfs->exists(fallback))
@@ -98,7 +112,7 @@ std::string Misc::ResourceHelpers::correctResourcePath(
if (changedToDds)
{
- fallback = topLevelDirectory;
+ fallback = topLevelDirectories.front();
fallback += '\\';
fallback += getBasename(origExt);
if (vfs->exists(fallback))
@@ -110,17 +124,17 @@ std::string Misc::ResourceHelpers::correctResourcePath(
std::string Misc::ResourceHelpers::correctTexturePath(std::string_view resPath, const VFS::Manager* vfs)
{
- return correctResourcePath("textures", resPath, vfs);
+ return correctResourcePath({ { "textures", "bookart" } }, resPath, vfs);
}
std::string Misc::ResourceHelpers::correctIconPath(std::string_view resPath, const VFS::Manager* vfs)
{
- return correctResourcePath("icons", resPath, vfs);
+ return correctResourcePath({ { "icons" } }, resPath, vfs);
}
std::string Misc::ResourceHelpers::correctBookartPath(std::string_view resPath, const VFS::Manager* vfs)
{
- return correctResourcePath("bookart", resPath, vfs);
+ return correctResourcePath({ { "bookart", "textures" } }, resPath, vfs);
}
std::string Misc::ResourceHelpers::correctBookartPath(
diff --git a/components/misc/resourcehelpers.hpp b/components/misc/resourcehelpers.hpp
index f2b576813b..e79dae0887 100644
--- a/components/misc/resourcehelpers.hpp
+++ b/components/misc/resourcehelpers.hpp
@@ -1,6 +1,7 @@
#ifndef MISC_RESOURCEHELPERS_H
#define MISC_RESOURCEHELPERS_H
+#include <span>
#include <string>
#include <string_view>
@@ -23,7 +24,7 @@ namespace Misc
{
bool changeExtensionToDds(std::string& path);
std::string correctResourcePath(
- std::string_view topLevelDirectory, std::string_view resPath, const VFS::Manager* vfs);
+ std::span<const std::string_view> topLevelDirectories, std::string_view resPath, const VFS::Manager* vfs);
std::string correctTexturePath(std::string_view resPath, const VFS::Manager* vfs);
std::string correctIconPath(std::string_view resPath, const VFS::Manager* vfs);
std::string correctBookartPath(std::string_view resPath, const VFS::Manager* vfs);