Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve #3011 -- Fixing the suggested save names #3398

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/framework/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions lib/framework/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "frame.h"
#include "vector.h"
#include <algorithm>
#include <limits>

/**
Expand Down
1 change: 1 addition & 0 deletions lib/framework/wzglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@
# undef NOMINMAX
# define NOMINMAX 1 // disable the min / max macros
# include <windows.h>
# include <algorithm>

# if defined(WZ_CC_MSVC)

Expand Down
29 changes: 18 additions & 11 deletions src/loadsave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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);
Expand All @@ -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;
Expand Down
Loading