mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 06:29:56 +00:00
Some refactoring
This commit is contained in:
parent
db686b25c2
commit
6f6b5ba04b
6 changed files with 36 additions and 17 deletions
|
@ -1,6 +1,5 @@
|
|||
#include "fontloader.hpp"
|
||||
|
||||
#include <filesystem>
|
||||
#include <stdexcept>
|
||||
#include <string_view>
|
||||
#include <array>
|
||||
|
@ -199,10 +198,10 @@ namespace Gui
|
|||
|
||||
void FontLoader::loadBitmapFonts(bool exportToFile)
|
||||
{
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||
for (const auto& path : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||
{
|
||||
if (Misc::getFileExtension(name) == "fnt")
|
||||
loadBitmapFont(name, exportToFile);
|
||||
if (Misc::getFileExtension(path) == "fnt")
|
||||
loadBitmapFont(path, exportToFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,11 +217,10 @@ namespace Gui
|
|||
std::string oldDataPath = dataManager->getDataPath("");
|
||||
dataManager->setResourcePath("fonts");
|
||||
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||
for (const auto& path : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||
{
|
||||
std::filesystem::path path = name;
|
||||
if (Misc::getFileExtension(name) == "omwfont")
|
||||
MyGUI::ResourceManager::getInstance().load(path.filename().string());
|
||||
if (Misc::getFileExtension(path) == "omwfont")
|
||||
MyGUI::ResourceManager::getInstance().load(std::string(Misc::getFileName(path)));
|
||||
}
|
||||
|
||||
dataManager->setResourcePath(oldDataPath);
|
||||
|
@ -344,7 +342,7 @@ namespace Gui
|
|||
MyGUI::xml::Document xmlDocument;
|
||||
MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont");
|
||||
|
||||
const std::string baseName = Misc::StringUtils::lowerCase(std::filesystem::path(mVFS->getAbsoluteFileName(fileName)).stem().string());
|
||||
std::string baseName(Misc::stemFile(fileName));
|
||||
root->addAttribute("name", getInternalFontName(baseName));
|
||||
|
||||
MyGUI::xml::ElementPtr defaultHeight = root->createChild("Property");
|
||||
|
|
|
@ -14,6 +14,28 @@ namespace Misc
|
|||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
inline std::string_view getFileName(std::string_view path)
|
||||
{
|
||||
if (auto namePos = path.find_last_of("/\\"); namePos != std::string::npos)
|
||||
{
|
||||
path.remove_prefix(namePos + 1);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
inline std::string_view stemFile(std::string_view path)
|
||||
{
|
||||
path = getFileName(path);
|
||||
|
||||
if (auto extPos = path.find_last_of("."); extPos != std::string::npos)
|
||||
{
|
||||
path.remove_suffix(path.size() - extPos);
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -22,10 +22,9 @@ MyGUI::IDataStream *DataManager::getData(const std::string &name) const
|
|||
{
|
||||
// Note: MyGUI is supposed to read/free input steam itself,
|
||||
// so copy data from VFS stream to the string stream and pass it to MyGUI.
|
||||
Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "\\" + name);
|
||||
Files::IStreamPtr streamPtr = mVfs->get(mResourcePath + "/" + name);
|
||||
std::istream* fileStream = streamPtr.get();
|
||||
std::unique_ptr<std::stringstream> dataStream;
|
||||
dataStream.reset(new std::stringstream);
|
||||
auto dataStream = std::make_unique<std::stringstream>();
|
||||
*dataStream << fileStream->rdbuf();
|
||||
return new MyGUI::DataStream(dataStream.release());
|
||||
}
|
||||
|
@ -37,7 +36,7 @@ void DataManager::freeData(MyGUI::IDataStream *data)
|
|||
|
||||
bool DataManager::isDataExist(const std::string &name) const
|
||||
{
|
||||
return mVfs->exists(mResourcePath + "\\" + name);
|
||||
return mVfs->exists(mResourcePath + "/" + name);
|
||||
}
|
||||
|
||||
void DataManager::setVfs(const VFS::Manager* vfs)
|
||||
|
@ -61,7 +60,7 @@ const std::string &DataManager::getDataPath(const std::string &name) const
|
|||
if (!isDataExist(name))
|
||||
return result;
|
||||
|
||||
result = mResourcePath + "\\" + name;
|
||||
result = mResourcePath + "/" + name;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ static bool collectStatFrameRate = false;
|
|||
static bool collectStatUpdate = false;
|
||||
static bool collectStatEngine = false;
|
||||
|
||||
inline static std::string sFontName = "Fonts\\DejaVuLGCSansMono.ttf";
|
||||
static std::string sFontName = "Fonts/DejaVuLGCSansMono.ttf";
|
||||
|
||||
static void setupStatCollection()
|
||||
{
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
add_subdirectory(shaders)
|
||||
add_subdirectory(data)
|
||||
add_subdirectory(lua_api)
|
||||
|
||||
copy_resource_file("launcher/images/openmw.png" "${OPENMW_RESOURCES_ROOT}" "resources/openmw.png")
|
||||
|
|
|
@ -162,5 +162,3 @@ set(BUILTIN_DATA_FILES
|
|||
foreach (f ${BUILTIN_DATA_FILES})
|
||||
copy_resource_file("${CMAKE_CURRENT_SOURCE_DIR}/${f}" "${OPENMW_RESOURCES_ROOT}" "resources/vfs/${f}")
|
||||
endforeach (f)
|
||||
|
||||
copy_resource_file("../launcher/images/openmw.png" "${OPENMW_RESOURCES_ROOT}" "resources/openmw.png")
|
||||
|
|
Loading…
Reference in a new issue