Remove Locale (#808)

* Remove Locale (finally)
This commit is contained in:
David Markowitz 2022-11-27 16:56:55 -08:00 committed by GitHub
parent 3222e78815
commit 56da3f8543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 5 additions and 120 deletions

View File

@ -92,9 +92,6 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Create a /res directory # Create a /res directory
make_directory(${CMAKE_BINARY_DIR}/res) make_directory(${CMAKE_BINARY_DIR}/res)
# Create a /locale directory
make_directory(${CMAKE_BINARY_DIR}/locale)
# Create a /logs directory # Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs) make_directory(${CMAKE_BINARY_DIR}/logs)

View File

@ -8,7 +8,6 @@ class InstanceManager;
class dpWorld; class dpWorld;
class dChatFilter; class dChatFilter;
class dConfig; class dConfig;
class dLocale;
class RakPeerInterface; class RakPeerInterface;
class AssetManager; class AssetManager;
struct SystemAddress; struct SystemAddress;
@ -20,7 +19,6 @@ namespace Game {
extern dpWorld* physicsWorld; extern dpWorld* physicsWorld;
extern dChatFilter* chatFilter; extern dChatFilter* chatFilter;
extern dConfig* config; extern dConfig* config;
extern dLocale* locale;
extern std::mt19937 randomEngine; extern std::mt19937 randomEngine;
extern RakPeerInterface* chatServer; extern RakPeerInterface* chatServer;
extern AssetManager* assetManager; extern AssetManager* assetManager;

View File

@ -13,7 +13,6 @@
#include "Mail.h" #include "Mail.h"
#include "MissionComponent.h" #include "MissionComponent.h"
#include "RacingTaskParam.h" #include "RacingTaskParam.h"
#include "dLocale.h"
#include "dLogger.h" #include "dLogger.h"
#include "dServer.h" #include "dServer.h"
#include "dZoneManager.h" #include "dZoneManager.h"
@ -335,13 +334,10 @@ void Mission::Complete(const bool yieldRewards) {
for (const auto& email : missionEmails) { for (const auto& email : missionEmails) {
const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_"; const auto missionEmailBase = "MissionEmail_" + std::to_string(email.ID) + "_";
const auto senderLocale = missionEmailBase + "senderName"; if (email.messageType == 1) {
const auto announceLocale = missionEmailBase + "announceText"; const auto subject = "%[" + missionEmailBase + "subjectText]";
const auto body = "%[" + missionEmailBase + "bodyText]";
if (email.messageType == 1 && Game::locale->HasPhrase(senderLocale)) { const auto sender = "%[" + missionEmailBase + "senderName]";
const auto subject = dLocale::GetTemplate(missionEmailBase + "subjectText");
const auto body = dLocale::GetTemplate(missionEmailBase + "bodyText");
const auto sender = dLocale::GetTemplate(senderLocale);
Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1); Mail::SendMail(LWOOBJID_EMPTY, sender, GetAssociate(), subject, body, email.attachmentLOT, 1);
} }

View File

@ -1,5 +1,4 @@
set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp" set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
"dLocale.cpp"
"GameConfig.cpp" "GameConfig.cpp"
"GUID.cpp" "GUID.cpp"
"Loot.cpp" "Loot.cpp"

View File

@ -1,82 +0,0 @@
#include "dLocale.h"
#include <clocale>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include "tinyxml2.h"
#include "Game.h"
#include "dConfig.h"
#include "BinaryPathFinder.h"
dLocale::dLocale() {
if (Game::config->GetValue("locale_enabled") != "1") {
return;
}
std::ifstream file(BinaryPathFinder::GetBinaryDir() / m_LocalePath);
if (!file.good()) {
return;
}
std::stringstream data;
data << file.rdbuf();
if (data.str().empty()) {
return;
}
auto* doc = new tinyxml2::XMLDocument();
if (doc == nullptr) {
return;
}
if (doc->Parse(data.str().c_str(), data.str().size()) != 0) {
return;
}
std::hash<std::string> hash;
auto* localization = doc->FirstChildElement("localization");
auto* phrases = localization->FirstChildElement("phrases");
auto* phrase = phrases->FirstChildElement("phrase");
while (phrase != nullptr) {
// Add the phrase hash to the vector
m_Phrases.push_back(hash(phrase->Attribute("id")));
phrase = phrase->NextSiblingElement("phrase");
}
file.close();
delete doc;
}
dLocale::~dLocale() = default;
std::string dLocale::GetTemplate(const std::string& phraseID) {
return "%[" + phraseID + "]";
}
bool dLocale::HasPhrase(const std::string& phraseID) {
if (Game::config->GetValue("locale_enabled") != "1") {
return true;
}
// Compute the hash and see if it's in the vector
std::hash<std::string> hash;
std::size_t hashValue = hash(phraseID);
return std::find(m_Phrases.begin(), m_Phrases.end(), hashValue) != m_Phrases.end();
}
/*std::string dLocale::GetPhrase(const std::string& phraseID) {
if (m_Phrases.find(phraseID) == m_Phrases.end()) {
return "";
}
return m_Phrases[phraseID];
}*/

View File

@ -1,19 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include <cstdint>
class dLocale {
public:
dLocale();
~dLocale();
static std::string GetTemplate(const std::string& phraseID);
bool HasPhrase(const std::string& phraseID);
//std::string GetPhrase(const std::string& phraseID);
private:
std::string m_LocalePath = "./locale/locale.xml";
std::string m_Locale = "en_US"; // TODO: add to config
std::vector<std::size_t> m_Phrases;
};

View File

@ -48,7 +48,6 @@
#include "GameMessageHandler.h" #include "GameMessageHandler.h"
#include "GameMessages.h" #include "GameMessages.h"
#include "Mail.h" #include "Mail.h"
#include "dLocale.h"
#include "TeamManager.h" #include "TeamManager.h"
#include "SkillComponent.h" #include "SkillComponent.h"
#include "DestroyableComponent.h" #include "DestroyableComponent.h"
@ -68,7 +67,6 @@ namespace Game {
dpWorld* physicsWorld; dpWorld* physicsWorld;
dChatFilter* chatFilter; dChatFilter* chatFilter;
dConfig* config; dConfig* config;
dLocale* locale;
std::mt19937 randomEngine; std::mt19937 randomEngine;
AssetManager* assetManager; AssetManager* assetManager;
@ -223,7 +221,6 @@ int main(int argc, char** argv) {
//Set up other things: //Set up other things:
Game::randomEngine = std::mt19937(time(0)); Game::randomEngine = std::mt19937(time(0));
Game::locale = new dLocale();
//Run it until server gets a kill message from Master: //Run it until server gets a kill message from Master:
auto lastTime = std::chrono::high_resolution_clock::now(); auto lastTime = std::chrono::high_resolution_clock::now();

2
docker/start_server.sh Executable file → Normal file
View File

@ -7,7 +7,7 @@ function symlink_client_files() {
ln -s /client/client/res/chatplus_en_us.txt /app/res/chatplus_en_us.txt ln -s /client/client/res/chatplus_en_us.txt /app/res/chatplus_en_us.txt
ln -s /client/client/res/names/ /app/res/names ln -s /client/client/res/names/ /app/res/names
ln -s /client/client/res/CDServer.sqlite /app/res/CDServer.sqlite ln -s /client/client/res/CDServer.sqlite /app/res/CDServer.sqlite
ln -s /client/client/locale/locale.xml /app/locale/locale.xml
# need to create this file so the server knows the client is unpacked (see `dCommon/dClient/AssetManager.cpp`) # need to create this file so the server knows the client is unpacked (see `dCommon/dClient/AssetManager.cpp`)
touch /app/res/cdclient.fdb touch /app/res/cdclient.fdb
# need to iterate over entries in maps due to maps already being a directory with navmeshes/ in it # need to iterate over entries in maps due to maps already being a directory with navmeshes/ in it

View File

@ -7,7 +7,6 @@ namespace Game {
dpWorld* physicsWorld; dpWorld* physicsWorld;
dChatFilter* chatFilter; dChatFilter* chatFilter;
dConfig* config; dConfig* config;
dLocale* locale;
std::mt19937 randomEngine; std::mt19937 randomEngine;
RakPeerInterface* chatServer; RakPeerInterface* chatServer;
AssetManager* assetManager; AssetManager* assetManager;