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
fix-osga-rotate-wildly
Evil Eye 10 months ago
commit 82c92a9a6c

@ -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

@ -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
{
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(

@ -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);

Loading…
Cancel
Save