feat(DB/Module): introduce module_string table (#19475)
This commit is contained in:
@@ -8544,6 +8544,98 @@ void ObjectMgr::LoadGameObjectForQuests()
|
||||
LOG_INFO("server.loading", " ");
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadModuleStrings()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
_moduleStringStore.clear(); // for reload case
|
||||
QueryResult result = WorldDatabase.Query("SELECT module, id, string FROM module_string");
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 module strings. DB table `module_string` is empty.");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return false;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string module = fields[0].Get<std::string>();
|
||||
uint32 id = fields[1].Get<uint32>();
|
||||
|
||||
std::pair<std::string, uint32> pairKey = std::make_pair(module, id);
|
||||
ModuleString& data = _moduleStringStore[pairKey];
|
||||
|
||||
AddLocaleString(fields[2].Get<std::string>(), LOCALE_enUS, data.Content);
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} Module Strings in {} ms", _moduleStringStore.size(), GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadModuleStringsLocale()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = WorldDatabase.Query("SELECT module, id, locale, string FROM module_string_locale");
|
||||
if (!result)
|
||||
{
|
||||
LOG_WARN("server.loading", ">> Loaded 0 module strings locale. DB table `module_string_locale` is empty.");
|
||||
LOG_INFO("server.loading", " ");
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32 localeCount = 0;
|
||||
do
|
||||
{
|
||||
Field* fields = result->Fetch();
|
||||
|
||||
std::string module = fields[0].Get<std::string>();
|
||||
uint32 id = fields[1].Get<uint32>();
|
||||
|
||||
std::pair<std::string, uint32> pairKey = std::make_pair(module, id);
|
||||
ModuleString& data = _moduleStringStore[pairKey];
|
||||
|
||||
ModuleStringContainer::iterator ms = _moduleStringStore.find(pairKey);
|
||||
if (ms == _moduleStringStore.end())
|
||||
{
|
||||
LOG_ERROR("sql.sql", "ModuleString (Module: {} Id: {}) found in table `module_string_locale` but does not exist in `module_string`. Skipped!", module, id);
|
||||
continue;
|
||||
}
|
||||
|
||||
LocaleConstant locale = GetLocaleByName(fields[2].Get<std::string>());
|
||||
if (locale == LOCALE_enUS)
|
||||
continue;
|
||||
|
||||
AddLocaleString(fields[3].Get<std::string>(), locale, data.Content);
|
||||
localeCount++;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded {} Module Strings Locales in {} ms", localeCount, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", " ");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string const* ObjectMgr::GetModuleString(std::string module, uint32 id, LocaleConstant locale) const
|
||||
{
|
||||
ModuleString const* ms = GetModuleString(module, id);
|
||||
if (ms->Content.size())
|
||||
{
|
||||
if (ms->Content.size() > size_t(locale) && !ms->Content[locale].empty())
|
||||
return &ms->Content[locale];
|
||||
|
||||
return &ms->Content[DEFAULT_LOCALE];
|
||||
}
|
||||
|
||||
LOG_ERROR("sql.sql", "Module string module {} id {} not found in DB.", module, id);
|
||||
|
||||
return (std::string*)"error";
|
||||
}
|
||||
|
||||
bool ObjectMgr::LoadAcoreStrings()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
@@ -493,6 +493,11 @@ typedef std::unordered_map<uint32/*(mapid, spawnMode) pair*/, CellObjectGuidsMap
|
||||
// Acore Trainer Reference start range
|
||||
#define ACORE_TRAINER_START_REF 200000
|
||||
|
||||
struct ModuleString
|
||||
{
|
||||
std::vector<std::string> Content;
|
||||
};
|
||||
|
||||
struct AcoreString
|
||||
{
|
||||
std::vector<std::string> Content;
|
||||
@@ -511,6 +516,7 @@ typedef std::unordered_map<uint32, QuestOfferRewardLocale> QuestOfferRewardLocal
|
||||
typedef std::unordered_map<uint32, QuestRequestItemsLocale> QuestRequestItemsLocaleContainer;
|
||||
typedef std::unordered_map<uint32, NpcTextLocale> NpcTextLocaleContainer;
|
||||
typedef std::unordered_map<uint32, PageTextLocale> PageTextLocaleContainer;
|
||||
typedef std::map<std::pair<std::string, uint32>, ModuleString> ModuleStringContainer;
|
||||
typedef std::unordered_map<int32, AcoreString> AcoreStringContainer;
|
||||
typedef std::unordered_map<uint32, GossipMenuItemsLocale> GossipMenuItemsLocaleContainer;
|
||||
typedef std::unordered_map<uint32, PointOfInterestLocale> PointOfInterestLocaleContainer;
|
||||
@@ -1012,6 +1018,8 @@ public:
|
||||
void ValidateSpellScripts();
|
||||
void InitializeSpellInfoPrecomputedData();
|
||||
|
||||
bool LoadModuleStrings();
|
||||
bool LoadModuleStringsLocale();
|
||||
bool LoadAcoreStrings();
|
||||
void LoadBroadcastTexts();
|
||||
void LoadBroadcastTextLocales();
|
||||
@@ -1310,6 +1318,17 @@ public:
|
||||
GameObjectData& NewGOData(ObjectGuid::LowType guid) { return _gameObjectDataStore[guid]; }
|
||||
void DeleteGOData(ObjectGuid::LowType guid);
|
||||
|
||||
[[nodiscard]] ModuleString const* GetModuleString(std::string module, uint32 id) const
|
||||
{
|
||||
std::pair<std::string, uint32> pairKey = std::make_pair(module, id);
|
||||
ModuleStringContainer::const_iterator itr = _moduleStringStore.find(pairKey);
|
||||
if (itr == _moduleStringStore.end())
|
||||
return nullptr;
|
||||
|
||||
return &itr->second;
|
||||
}
|
||||
[[nodiscard]] std::string const* GetModuleString(std::string module, uint32 id, LocaleConstant locale) const;
|
||||
|
||||
[[nodiscard]] AcoreString const* GetAcoreString(uint32 entry) const
|
||||
{
|
||||
AcoreStringContainer::const_iterator itr = _acoreStringStore.find(entry);
|
||||
@@ -1598,6 +1617,7 @@ private:
|
||||
QuestRequestItemsLocaleContainer _questRequestItemsLocaleStore;
|
||||
NpcTextLocaleContainer _npcTextLocaleStore;
|
||||
PageTextLocaleContainer _pageTextLocaleStore;
|
||||
ModuleStringContainer _moduleStringStore;
|
||||
AcoreStringContainer _acoreStringStore;
|
||||
GossipMenuItemsLocaleContainer _gossipMenuItemsLocaleStore;
|
||||
PointOfInterestLocaleContainer _pointOfInterestLocaleStore;
|
||||
|
||||
Reference in New Issue
Block a user