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
make_directory(${CMAKE_BINARY_DIR}/res)
# Create a /locale directory
make_directory(${CMAKE_BINARY_DIR}/locale)
# Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs)

View File

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

View File

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

View File

@ -1,5 +1,4 @@
set(DGAME_DUTILITIES_SOURCES "BrickDatabase.cpp"
"dLocale.cpp"
"GameConfig.cpp"
"GUID.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 "GameMessages.h"
#include "Mail.h"
#include "dLocale.h"
#include "TeamManager.h"
#include "SkillComponent.h"
#include "DestroyableComponent.h"
@ -68,7 +67,6 @@ namespace Game {
dpWorld* physicsWorld;
dChatFilter* chatFilter;
dConfig* config;
dLocale* locale;
std::mt19937 randomEngine;
AssetManager* assetManager;
@ -223,7 +221,6 @@ int main(int argc, char** argv) {
//Set up other things:
Game::randomEngine = std::mt19937(time(0));
Game::locale = new dLocale();
//Run it until server gets a kill message from Master:
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/names/ /app/res/names
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`)
touch /app/res/cdclient.fdb
# 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;
dChatFilter* chatFilter;
dConfig* config;
dLocale* locale;
std::mt19937 randomEngine;
RakPeerInterface* chatServer;
AssetManager* assetManager;