git repos / blockattack-game

commit 9f711750

Poul Sander · 2024-05-12 12:35
9f711750d1aead8d5cda23707d398d88fd67e51e patch · browse files
parent 1e8825101547651b05542c1f065a55d8813a8d98

Remove Cereal from puzzle save handler

Changed files

M source/code/puzzlehandler.cpp before
diff --git a/source/code/puzzlehandler.cpp b/source/code/puzzlehandler.cpp index e748fd4..90a2fff 100644 --- a/source/code/puzzlehandler.cpp +++ b/source/code/puzzlehandler.cpp
@@ -22,15 +22,16 @@ http://blockattack.net
*/
#include "puzzlehandler.hpp"
+#include "nlohmann/json.hpp"
#include <vector>
#include <iostream>
+#include <sstream>
#include "stats.h"
#include <physfs.h> //Abstract file system. To use containers
-#include "cereal/cereal.hpp"
-#include "cereal/types/vector.hpp"
-#include "cereal/archives/json.hpp"
#include "sago/SagoMisc.hpp"
+using json = nlohmann::json;
+
const int maxNrOfPuzzleStages = 50; //Maximum number of puzzle stages
static std::string puzzleSavePath;
@@ -68,16 +69,12 @@ void PuzzleSetName(const std::string& name) {
void LoadClearData() {
std::string readFileContent = sago::GetFileContent(puzzleSavePath.c_str());
if (readFileContent.length() > 0) {
- std::stringstream ss(readFileContent);
- {
- try {
- cereal::JSONInputArchive archive(ss);
- archive(cereal::make_nvp("cleared", puzzleCleared));
- }
- catch (cereal::Exception& e) {
- std::cerr << "Failed to read \"" << puzzleSavePath << "\". File will be regenerated. Reason: " << e.what() << "\n";
- puzzleCleared.clear();
- }
+ json j = json::parse(readFileContent);
+ try {
+ j.at("cleared").get_to(puzzleCleared);
+ } catch (json::exception& e) {
+ std::cerr << "Failed to read \"" << puzzleSavePath << "\". File will be regenerated. Reason: " << e.what() << "\n";
+ puzzleCleared.clear();
}
}
else {
@@ -87,12 +84,9 @@ void LoadClearData() {
}
void SaveClearData() {
- std::stringstream ss;
- {
- cereal::JSONOutputArchive archive(ss);
- archive(cereal::make_nvp("cleared", puzzleCleared));
- }
- sago::WriteFileContent(puzzleSavePath.c_str(), ss.str());
+ json j = json{ { "cleared", puzzleCleared } };
+ std::string s = j.dump(4);
+ sago::WriteFileContent(puzzleSavePath.c_str(), s);
}
void PuzzleSetClear(int Level) {