Move global language constants to single file

Deduplicate.
This commit is contained in:
Amos 2023-09-15 18:25:31 +02:00
parent 95cd34eb23
commit 0634261c18
5 changed files with 36 additions and 40 deletions

View File

@ -51,6 +51,7 @@
#include "public/bspflags.h" #include "public/bspflags.h"
#include "public/cmodel.h" #include "public/cmodel.h"
#include "public/idebugoverlay.h" #include "public/idebugoverlay.h"
#include "public/localize/ilocalize.h"
#ifndef CLIENT_DLL #ifndef CLIENT_DLL
#include "game/server/detour_impl.h" #include "game/server/detour_impl.h"
#include "game/server/gameinterface.h" #include "game/server/gameinterface.h"
@ -1022,26 +1023,11 @@ void GFX_NVN_Changed_f(IConVar* pConVar, const char* pOldString, float flOldValu
} }
#endif // !DEDICATED #endif // !DEDICATED
static const char* s_LanguageNames[] = {
"english",
"french",
"german",
"italian",
"japanese",
"polish",
"russian",
"spanish",
"schinese",
"tchinese",
"korean"
};
static bool IsValidTextLanguage(const char* pLocaleName) static bool IsValidTextLanguage(const char* pLocaleName)
{ {
for (int i = 0; i < SDK_ARRAYSIZE(s_LanguageNames); ++i) for (int i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); ++i)
{ {
if (strcmp(pLocaleName, s_LanguageNames[i]) == NULL) if (strcmp(pLocaleName, g_LanguageNames[i]) == NULL)
return true; return true;
} }

View File

@ -8,4 +8,8 @@ add_sources( SOURCE_GROUP "Runtime"
"localize.h" "localize.h"
) )
add_sources( SOURCE_GROUP "Public"
"${ENGINE_SOURCE_DIR}/public/localize/ilocalize.h"
)
end_sources() end_sources()

View File

@ -0,0 +1,19 @@
#ifndef LOCALIZE_H
#define LOCALIZE_H
inline const char* const g_LanguageNames[] = {
"english",
"german",
"french",
"italian",
"korean",
"spanish",
"schinese",
"tchinese",
"russian",
"japanese",
"portuguese",
"polish",
};
#endif // LOCALIZE_H

View File

@ -32,6 +32,7 @@
#include "mathlib/sha1.h" #include "mathlib/sha1.h"
#include "filesystem/filesystem.h" #include "filesystem/filesystem.h"
#include "vpc/keyvalues.h" #include "vpc/keyvalues.h"
#include "localize/ilocalize.h"
#include "vpklib/packedstore.h" #include "vpklib/packedstore.h"
static const std::regex s_DirFileRegex{ R"((?:.*\/)?([^_]*_)(.*)(.bsp.pak000_dir).*)" }; static const std::regex s_DirFileRegex{ R"((?:.*\/)?([^_]*_)(.*)(.bsp.pak000_dir).*)" };
@ -794,9 +795,9 @@ VPKPair_t::VPKPair_t(const char* pLocale, const char* pTarget, const char* pLeve
{ {
bool bFoundLocale = false; bool bFoundLocale = false;
for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_LOCALE); i++) for (size_t i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); i++)
{ {
if (V_strcmp(pLocale, DIR_LOCALE[i]) == NULL) if (V_strcmp(pLocale, g_LanguageNames[i]) == NULL)
{ {
bFoundLocale = true; bFoundLocale = true;
} }
@ -804,8 +805,8 @@ VPKPair_t::VPKPair_t(const char* pLocale, const char* pTarget, const char* pLeve
if (!bFoundLocale) if (!bFoundLocale)
{ {
Warning(eDLL_T::FS, "Locale '%s' not supported; using default '%s'\n", pLocale, DIR_LOCALE[0]); Warning(eDLL_T::FS, "Locale '%s' not supported; using default '%s'\n", pLocale, g_LanguageNames[0]);
pLocale = DIR_LOCALE[0]; pLocale = g_LanguageNames[0];
} }
bool bFoundTarget = false; bool bFoundTarget = false;
@ -865,9 +866,9 @@ VPKDir_t::VPKDir_t(const CUtlString& dirFilePath, bool bSanitizeName)
bool bHasLocale = false; bool bHasLocale = false;
for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_LOCALE); i++) for (size_t i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); i++)
{ {
if (sanitizedName.Find(DIR_LOCALE[i]) != -1) if (sanitizedName.Find(g_LanguageNames[i]) != -1)
{ {
bHasLocale = true; bHasLocale = true;
break; break;
@ -877,7 +878,7 @@ VPKDir_t::VPKDir_t(const CUtlString& dirFilePath, bool bSanitizeName)
if (!bHasLocale) // Only sanitize if no locale was provided. if (!bHasLocale) // Only sanitize if no locale was provided.
{ {
CUtlString packDirPrefix; CUtlString packDirPrefix;
packDirPrefix.Append(DIR_LOCALE[0]); packDirPrefix.Append(g_LanguageNames[0]);
for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_TARGET); i++) for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_TARGET); i++)
{ {
@ -954,9 +955,9 @@ CUtlString VPKDir_t::StripLocalePrefix(const CUtlString& directoryPath) const
{ {
CUtlString fileName = directoryPath.UnqualifiedFilename(); CUtlString fileName = directoryPath.UnqualifiedFilename();
for (size_t i = 0; i < SDK_ARRAYSIZE(DIR_LOCALE); i++) for (size_t i = 0; i < SDK_ARRAYSIZE(g_LanguageNames); i++)
{ {
fileName = fileName.Replace(DIR_LOCALE[i], ""); fileName = fileName.Replace(g_LanguageNames[i], "");
} }
return fileName; return fileName;

View File

@ -29,20 +29,6 @@ static const char* const DIR_TARGET[]
"server", "server",
"client" "client"
}; };
static const char* const DIR_LOCALE[]
{
"english",
"french",
"german",
"italian",
"japanese",
"korean",
"polish",
"portuguese",
"russian",
"spanish",
"tchinese"
};
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// KeyValues structure for the VPK manifest file. This struct gets populated by // KeyValues structure for the VPK manifest file. This struct gets populated by