1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-15 00:05:02 +02:00

Better handling of encoding detection for maps and campaigns

Now VCMI will use either preferred language or install language to load
maps and campaigns that are part of "core" mod, or, in other words -
placed in Maps directory of H3 data (like most of manually downloaded
maps and campaigns are)

If game data is in English, then game can safely use encoding of player-
selected language (such as Chinese) to load maps. After all, both GBK
and all Win-125X encoding are superset of ASCII, so English map will
always load up correctly.

Maps that are part of a mod still use mod language as before - it is up
to mod maker to correctly set up mod language.
This commit is contained in:
Ivan Savenko
2024-10-30 11:54:35 +00:00
parent 3a45e6dae1
commit 22f517686d
7 changed files with 43 additions and 19 deletions

View File

@ -19,7 +19,6 @@
#include "../modding/CModHandler.h"
#include "../modding/ModScope.h"
#include "../modding/CModInfo.h"
#include "../texts/Languages.h"
#include "../VCMI_Lib.h"
#include "CMap.h"
@ -34,8 +33,7 @@ VCMI_LIB_NAMESPACE_BEGIN
std::unique_ptr<CMap> CMapService::loadMap(const ResourcePath & name, IGameCallback * cb) const
{
std::string modName = VLC->modh->findResourceOrigin(name);
std::string language = VLC->modh->getModLanguage(modName);
std::string encoding = Languages::getLanguageOptions(language).encoding;
std::string encoding = VLC->modh->findResourceEncoding(name);
auto stream = getStreamFromFS(name);
return getMapLoader(stream, name.getName(), modName, encoding)->loadMap(cb);
@ -44,8 +42,7 @@ std::unique_ptr<CMap> CMapService::loadMap(const ResourcePath & name, IGameCallb
std::unique_ptr<CMapHeader> CMapService::loadMapHeader(const ResourcePath & name) const
{
std::string modName = VLC->modh->findResourceOrigin(name);
std::string language = VLC->modh->getModLanguage(modName);
std::string encoding = Languages::getLanguageOptions(language).encoding;
std::string encoding = VLC->modh->findResourceEncoding(name);
auto stream = getStreamFromFS(name);
return getMapLoader(stream, name.getName(), modName, encoding)->loadMapHeader();