From 4427361c703269bc36d3c1b57135d10be0a4b748 Mon Sep 17 00:00:00 2001 From: danil179 <32551661+danil179@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:35:56 +0300 Subject: [PATCH 1/2] Fix compilation --- lib/framework/crc.cpp | 2 +- lib/framework/geometry.h | 1 + lib/framework/wzglobal.h | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/framework/crc.cpp b/lib/framework/crc.cpp index b4d184baad7..de1faabdd93 100644 --- a/lib/framework/crc.cpp +++ b/lib/framework/crc.cpp @@ -182,7 +182,7 @@ void Sha256::fromString(std::string const &s) } } -void to_json(nlohmann::json& j, const Sha256& k) +inline void to_json(nlohmann::json& j, const Sha256& k) { if (k.isZero()) { diff --git a/lib/framework/geometry.h b/lib/framework/geometry.h index d3c88b906b1..11a235336b2 100644 --- a/lib/framework/geometry.h +++ b/lib/framework/geometry.h @@ -22,6 +22,7 @@ #include "frame.h" #include "vector.h" +#include #include /** diff --git a/lib/framework/wzglobal.h b/lib/framework/wzglobal.h index 3e26f256c28..417f0607db4 100644 --- a/lib/framework/wzglobal.h +++ b/lib/framework/wzglobal.h @@ -553,6 +553,7 @@ # undef NOMINMAX # define NOMINMAX 1 // disable the min / max macros # include +# include # if defined(WZ_CC_MSVC) From e12e2fdaf449d0b688ac8db349f6f82fe1f66a96 Mon Sep 17 00:00:00 2001 From: danil179 <32551661+danil179@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:47:12 +0300 Subject: [PATCH 2/2] Saving the saving mechanism --- src/loadsave.cpp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/loadsave.cpp b/src/loadsave.cpp index 8546fe93e20..ffb0980d6a7 100644 --- a/src/loadsave.cpp +++ b/src/loadsave.cpp @@ -730,7 +730,8 @@ static WzString suggestSaveName(const char *saveGamePath) WzString saveName = WzString(saveNamePartial).trimmed(); int similarSaveGames = 0; - WZ_PHYSFS_enumerateFolders(saveGamePath, [&saveName, &similarSaveGames](const char *dirName) { + std::vector suffixArr; + WZ_PHYSFS_enumerateFolders(saveGamePath, [&saveName, &similarSaveGames, &suffixArr](const char *dirName) { std::string dirNameStr = WzString(dirName).toStdString(); std::string saveNameStr = saveName.toStdString(); size_t pos = dirNameStr.find(saveNameStr); @@ -751,23 +752,29 @@ static WzString suggestSaveName(const char *saveGamePath) size_t lastSpace = restOfSaveName.find_last_of(" "); if (lastSpace != std::string::npos) { - if (isdigit(restOfSaveName[lastSpace + 1])) - { - std::string tempStr = restOfSaveName.substr(0, lastSpace); - if (tempStr.compare(saveNameStr) == 0) - { - ++similarSaveGames; - return true; - } + // Get the suffix number + int converted = atoi(restOfSaveName.substr(lastSpace).c_str()); + if (converted != 0) { + // Suffix is a number + suffixArr.push_back(converted); } } return true; }); - if (similarSaveGames > 0) { - saveName += " " + WzString::number(similarSaveGames + 1); + // Sorting the suffix numbers and determining missing saves + int curSaveNum = 2; + std::sort(suffixArr.begin(), suffixArr.end()); + bool foundStart = false; + for (auto it = suffixArr.begin(); it < suffixArr.end(); it++) + { + if (*it == 2) foundStart = true; + if (!foundStart && *it != 2) continue; + if (*it == curSaveNum) curSaveNum+=1; + } + saveName += " " + WzString::number(curSaveNum); } return saveName;