Created
July 30, 2018 11:30
-
-
Save Winfidonarleyan/1ae3bfc1f40ae1e5ab8392c32866bf0c to your computer and use it in GitHub Desktop.
Full localisation on load trinity string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool ObjectMgr::LoadTrinityStrings(const char* table, int32 min_value, int32 max_value) | |
{ | |
uint32 oldMSTime = getMSTime(); | |
int32 start_value = min_value; | |
int32 end_value = max_value; | |
// some string can have negative indexes range | |
if (start_value < 0) | |
{ | |
if (end_value >= start_value) | |
{ | |
sLog->outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); | |
return false; | |
} | |
// real range (max+1, min+1) exaple: (-10, -1000) -> -999...-10+1 | |
std::swap(start_value, end_value); | |
++start_value; | |
++end_value; | |
} | |
else | |
{ | |
if (start_value >= end_value) | |
{ | |
sLog->outErrorDb("Table '%s' attempt loaded with invalid range (%d - %d), strings not loaded.", table, min_value, max_value); | |
return false; | |
} | |
} | |
// cleanup affected map part for reloading case | |
for (TrinityStringLocaleContainer::iterator itr = _trinityStringLocaleStore.begin(); itr != _trinityStringLocaleStore.end();) | |
{ | |
if (itr->first >= start_value && itr->first < end_value) | |
_trinityStringLocaleStore.erase(itr++); | |
else | |
++itr; | |
} | |
QueryResult result = KargatumDatabase.PQuery("SELECT entry, content_default, content_loc1, content_loc2, content_loc3, content_loc4, content_loc5, content_loc6, content_loc7, content_loc8 FROM %s", table); | |
if (!result) | |
{ | |
if (min_value == MIN_TRINITY_STRING_ID) // error only in case internal strings | |
sLog->outErrorDb(">> Loaded 0 trinity strings. DB table `%s` is empty. Cannot continue.", table); | |
else | |
sLog->outString(">> Loaded 0 string templates. DB table `%s` is empty.", table); | |
sLog->outString(); | |
return false; | |
} | |
uint32 count = 0; | |
do | |
{ | |
Field* fields = result->Fetch(); | |
int32 entry = fields[0].GetInt32(); | |
if (entry == 0) | |
{ | |
sLog->outErrorDb("Table `%s` contain reserved entry 0, ignored.", table); | |
continue; | |
} | |
else if (entry < start_value || entry >= end_value) | |
{ | |
sLog->outErrorDb("Table `%s` contain entry %i out of allowed range (%d - %d), ignored.", table, entry, min_value, max_value); | |
continue; | |
} | |
TrinityStringLocale& data = _trinityStringLocaleStore[entry]; | |
if (!data.Content.empty()) | |
{ | |
sLog->outErrorDb("Table `%s` contain data for already loaded entry %i (from another table?), ignored.", table, entry); | |
continue; | |
} | |
data.Content.resize(1); | |
++count; | |
for (uint8 i = 0; i < TOTAL_LOCALES; ++i) | |
AddLocaleString(fields[i + 1].GetString(), LocaleConstant(i), data.Content); | |
} | |
while (result->NextRow()); | |
if (min_value == MIN_TRINITY_STRING_ID) | |
sLog->outString(">> Loaded %u Trinity strings from table %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); | |
else | |
sLog->outString(">> Loaded %u string templates from %s in %u ms", count, table, GetMSTimeDiffToNow(oldMSTime)); | |
sLog->outString(); | |
return true; | |
} | |
const char *ObjectMgr::GetTrinityString(int32 entry, LocaleConstant locale_idx) const | |
{ | |
if (TrinityStringLocale const* msl = GetTrinityStringLocale(entry)) | |
{ | |
if (msl->Content.size() > size_t(locale_idx) && !msl->Content[locale_idx].empty()) | |
return msl->Content[locale_idx].c_str(); | |
return msl->Content[DEFAULT_LOCALE].c_str(); | |
} | |
if (entry > 0) | |
sLog->outErrorDb("Entry %i not found in `trinity_string` table.", entry); | |
else | |
sLog->outErrorDb("Trinity string entry %i not found in DB.", entry); | |
return "<error>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment