Working on save-load system and UI

This commit is contained in:
Vladislav Khorev committed 2026-06-20 21:41:07 +03:00
1 parent 901142385d
commit d7db0faea3
29 files changed
+708 -180

No files matched your search

+42
View File
@@ -220,4 +220,46 @@ std::vector<const QuestState*> QuestJournal::getVisibleQuests() const {
return result;
}
void QuestJournal::save(nlohmann::json& out) const {
json arr = json::array();
for (const auto& id : questOrder) {
const auto& qs = quests.at(id);
json qj;
qj["id"] = id;
qj["status"] = static_cast<int>(qs.status);
qj["activeObjectiveIndex"] = qs.activeObjectiveIndex;
json objArr = json::array();
for (const auto& obj : qs.definition.objectives) {
objArr.push_back({ {"id", obj.id}, {"completed", obj.completed}, {"visible", obj.visible} });
}
qj["objectives"] = std::move(objArr);
arr.push_back(std::move(qj));
}
out["quests"] = std::move(arr);
}
void QuestJournal::load(const nlohmann::json& in) {
if (!in.contains("quests") || !in["quests"].is_array()) return;
for (const auto& qj : in["quests"]) {
const std::string id = qj.value("id", "");
auto it = quests.find(id);
if (it == quests.end()) continue;
auto& qs = it->second;
qs.status = static_cast<QuestStatus>(qj.value("status", 0));
qs.activeObjectiveIndex = qj.value("activeObjectiveIndex", 0);
if (qj.contains("objectives") && qj["objectives"].is_array()) {
for (const auto& oj : qj["objectives"]) {
const std::string objId = oj.value("id", "");
for (auto& obj : qs.definition.objectives) {
if (obj.id == objId) {
obj.completed = oj.value("completed", obj.completed);
obj.visible = oj.value("visible", obj.visible);
break;
}
}
}
}
}
}
} // namespace ZL::Quest
+6 -1
View File
@@ -1,6 +1,8 @@
#pragma once
#include "quest/QuestTypes.h"
#include "ISaveable.h"
#include "external/nlohmann/json.hpp"
#include <string>
#include <unordered_map>
#include <vector>
@@ -8,10 +10,13 @@
namespace ZL::Quest {
class QuestJournal {
class QuestJournal : public ZL::ISaveable {
public:
bool loadFromFile(const std::string& path, const std::string& zipFile = "");
void save(nlohmann::json& out) const override;
void load(const nlohmann::json& in) override;
// Event callbacks — set by the owner (MenuManager) to receive notifications.
std::function<void(const std::string& questId)> onQuestUnlocked;
std::function<void(const std::string& questId)> onQuestCompleted;