Skip to content

Commit 5cdbc29

Browse files
committed
Minor corrections to puzzle loading
1 parent 83b9551 commit 5cdbc29

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

source/code/puzzlehandler.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Source information and contacts persons can be found at
2828
#include <sstream>
2929
#include "stats.h"
3030
#include <physfs.h> //Abstract file system. To use containers
31+
#include <fmt/core.h>
3132
#include "sago/SagoMisc.hpp"
3233

3334
using json = nlohmann::json;
@@ -71,7 +72,7 @@ void PuzzleSetName(const std::string& name) {
7172

7273
void LoadClearData() {
7374
std::string readFileContent = sago::GetFileContent(puzzleSavePath.c_str());
74-
if (readFileContent.length() > 0) {
75+
if (readFileContent.length()) {
7576
json j = json::parse(readFileContent);
7677
try {
7778
j.at("cleared").get_to(puzzleCleared);
@@ -88,7 +89,7 @@ void LoadClearData() {
8889

8990
void SaveClearData() {
9091
json j = json{ { "cleared", puzzleCleared } };
91-
std::string s = j.dump(4);
92+
const std::string s = j.dump(4);
9293
sago::WriteFileContent(puzzleSavePath.c_str(), s);
9394
}
9495

@@ -102,11 +103,12 @@ void PuzzleSetClear(int Level) {
102103

103104
/*Loads all the puzzle levels*/
104105
int LoadPuzzleStages( ) {
105-
if (!PHYSFS_exists(((std::string)("puzzles/"+puzzleName)).c_str())) {
106-
std::cerr << "Warning: File not in blockattack.data: " << ("puzzles/"+puzzleName) << "\n";
106+
const std::string filename = fmt::format("puzzles/{}",puzzleName);
107+
if (!PHYSFS_exists(filename.c_str())) {
108+
std::cerr << "Warning: File not in blockattack.data: " << filename << "\n";
107109
return -1; //file doesn't exist
108110
}
109-
std::string fileContent = sago::GetFileContent(((std::string)("puzzles/"+puzzleName)).c_str());
111+
const std::string fileContent = sago::GetFileContent(filename.c_str());
110112
std::stringstream inFile(fileContent);
111113

112114
inFile >> nrOfPuzzles;
@@ -128,7 +130,7 @@ int LoadPuzzleStages( ) {
128130
}
129131

130132
int SavePuzzleStages() {
131-
if (puzzleName.length() == 0) {
133+
if (puzzleName.empty()) {
132134
std::cerr << "Error: No puzzle name set. Cannot save.\n";
133135
return -1;
134136
}

0 commit comments

Comments
 (0)