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

+34 -10
View File
@@ -312,8 +312,6 @@ namespace ZL
triggerZones.push_back(std::move(tz));
}
// Resize the parallel playerInside vector in state to match
state.triggerZonePlayerInside.assign(triggerZones.size(), false);
std::cout << "[TRIGGER] Loaded " << triggerZones.size() << " trigger zone(s) from " << jsonPath << std::endl;
}
@@ -388,11 +386,9 @@ namespace ZL
const float dist = (playerPos - tz.position).norm();
if (!tz.playerInside && dist <= tz.radius) {
tz.playerInside = true;
state.triggerZonePlayerInside[i] = true;
scriptEngine.callTriggerEnterCallback(tz.id);
} else if (tz.playerInside && dist > tz.radius + tz.hysteresis) {
tz.playerInside = false;
state.triggerZonePlayerInside[i] = false;
scriptEngine.callTriggerExitCallback(tz.id);
}
}
@@ -1833,7 +1829,7 @@ namespace ZL
// ---- Save / Load ----
void Location::saveFullState(nlohmann::json& out) const
void Location::save(nlohmann::json& out) const
{
// Location-level state
nlohmann::json locState;
@@ -1878,9 +1874,23 @@ namespace ZL
nlohmann::json scriptState;
scriptEngine.saveScriptGlobals(scriptState);
out["scriptGlobals"] = std::move(scriptState);
// Trigger zone runtime state (by id)
nlohmann::json tzState = nlohmann::json::object();
for (const auto& tz : triggerZones) {
tzState[tz.id] = { {"enabled", tz.enabled}, {"playerInside", tz.playerInside} };
}
out["triggerZoneState"] = std::move(tzState);
// Teleport zone runtime state (by id)
nlohmann::json tpState = nlohmann::json::object();
for (const auto& tp : teleportZones) {
tpState[tp.id] = tp.active;
}
out["teleportZoneState"] = std::move(tpState);
}
void Location::loadFullState(const nlohmann::json& in)
void Location::load(const nlohmann::json& in)
{
// Location-level state
if (in.contains("locationState")) {
@@ -1894,10 +1904,24 @@ namespace ZL
navigation = &navigationMaps[state.activeNavigationIndex];
}
// Re-sync triggerZones[i].playerInside from state
for (int i = 0; i < static_cast<int>(triggerZones.size()); ++i) {
if (i < static_cast<int>(state.triggerZonePlayerInside.size())) {
triggerZones[i].playerInside = state.triggerZonePlayerInside[i];
// Restore trigger zone runtime state (by id)
if (in.contains("triggerZoneState") && in["triggerZoneState"].is_object()) {
const auto& tzs = in["triggerZoneState"];
for (auto& tz : triggerZones) {
if (tzs.contains(tz.id)) {
tz.enabled = tzs[tz.id].value("enabled", tz.enabled);
tz.playerInside = tzs[tz.id].value("playerInside", tz.playerInside);
}
}
}
// Restore teleport zone runtime state (by id)
if (in.contains("teleportZoneState") && in["teleportZoneState"].is_object()) {
const auto& tps = in["teleportZoneState"];
for (auto& tp : teleportZones) {
if (tps.contains(tp.id)) {
tp.active = tps[tp.id].get<bool>();
}
}
}