diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp index c7d1479..84c96aa 100644 --- a/source/code/highscore.cpp +++ b/source/code/highscore.cpp @@ -23,26 +23,21 @@ https://blockattack.net #include "highscore.h" #include "os.hpp" -#include "cereal/cereal.hpp" -#include "cereal/types/vector.hpp" -#include "cereal/archives/json.hpp" #include "sago/SagoMisc.hpp" #include #include "common.h" #include +#include "nlohmann/json.hpp" -namespace cereal { +using json = nlohmann::json; -template -void save(Archive& archive, record const& m) { - archive( cereal::make_nvp("Name", m.name), cereal::make_nvp("Score", m.score) ); -} - -template -void load(Archive& archive, record& m) { - archive( cereal::make_nvp("Name", m.name), cereal::make_nvp("Score", m.score) ); +void to_json(json& j, const record& p) { + j = json{ {"Name", p.name}, {"Score", p.score}}; } +void from_json(const json& j, record& p) { + p.name = j.at("Name").get(); + p.score = j.at("Score").get(); } /* @@ -59,21 +54,17 @@ Highscore::Highscore(const std::string& type, double speed) : filename(type+".js } std::string readFileContent = sago::GetFileContent(filename.c_str()); if (readFileContent.length() > 0) { + json j = json::parse(readFileContent); try { - std::stringstream ss(readFileContent); - { - cereal::JSONInputArchive archive(ss); - archive(cereal::make_nvp("highscore", table)); - } - } - catch (cereal::Exception& e) { + j.at("highscore").get_to(table); + } catch (json::exception& e) { std::cerr << "Failed to read highscore " << filename << " due to formatting errors. Resetting the file. Reason: " << e.what() << "\n"; table.clear(); } } if (table.size() < top) { - for (int i = 0; i