Working on translations

This commit is contained in:
Vladislav Khorev committed 2026-07-07 11:24:21 +03:00
1 parent 9d8ca865c7
commit e2d9105b02
18 files changed
+271 -88

No files matched your search

+17 -19
View File
@@ -1,6 +1,7 @@
#include "quest/QuestJournal.h"
#include "external/nlohmann/json.hpp"
#include "utils/Utils.h"
#include "Localization.h"
#include <algorithm>
#include <iostream>
@@ -26,26 +27,9 @@ static QuestStatus parseQuestStatus(const std::string& value) {
}
bool QuestJournal::loadFromFile(const std::string& path, const std::string& zipFile) {
quests.clear();
questOrder.clear();
std::string content;
try {
if (zipFile.empty()) {
content = ZL::readTextFile(path);
}
else {
auto data = ZL::readFileFromZIP(path, zipFile);
content.assign(data.begin(), data.end());
}
}
catch (const std::exception& e) {
std::cerr << "[quest] Failed to read " << path << ": " << e.what() << std::endl;
return false;
}
const std::string content = ZL::readLocalizedConfigFile(path, zipFile);
if (content.empty()) {
std::cerr << "[quest] Empty quest file: " << path << std::endl;
std::cerr << "[quest] Failed to read " << path << std::endl;
return false;
}
@@ -63,6 +47,12 @@ bool QuestJournal::loadFromFile(const std::string& path, const std::string& zipF
return false;
}
// Only clear existing definitions/state once the new file is confirmed
// valid, so a failed reload (e.g. a broken localized file) doesn't wipe
// the currently loaded quest journal.
quests.clear();
questOrder.clear();
for (const auto& item : root["quests"]) {
QuestDefinition def;
def.id = item.value("id", "");
@@ -101,6 +91,14 @@ bool QuestJournal::loadFromFile(const std::string& path, const std::string& zipF
return true;
}
bool QuestJournal::reloadDefinitionsPreservingState(const std::string& path, const std::string& zipFile) {
json snapshot;
save(snapshot);
if (!loadFromFile(path, zipFile)) return false;
load(snapshot);
return true;
}
bool QuestJournal::setStatus(const std::string& questId, QuestStatus status) {
QuestState* quest = findQuest(questId);
if (!quest) return false;
+5
View File
@@ -14,6 +14,11 @@ class QuestJournal : public ZL::ISaveable {
public:
bool loadFromFile(const std::string& path, const std::string& zipFile = "");
// Reloads quest definitions (e.g. after a language switch) while
// preserving current progress: snapshots status/objective state, reloads
// definitions from path, then re-applies the snapshot.
bool reloadDefinitionsPreservingState(const std::string& path, const std::string& zipFile = "");
void save(nlohmann::json& out) const override;
void load(const nlohmann::json& in) override;