mirror of https://github.com/stella-emu/stella.git
added high score clearing for invalid data
fixed high score error messages
This commit is contained in:
parent
68d54e3cf5
commit
e90cb925b0
|
@ -573,7 +573,7 @@ void HighScoresManager::saveHighScores(ScoresData& data) const
|
||||||
json hsData = json::object();
|
json hsData = json::object();
|
||||||
|
|
||||||
// Add header so that if the high score format changes in the future,
|
// Add header so that if the high score format changes in the future,
|
||||||
// we'll know right away, without having to parse the rest of the file
|
// we'll know right away, without having to parse the rest of the data
|
||||||
hsData[VERSION] = HIGHSCORE_HEADER;
|
hsData[VERSION] = HIGHSCORE_HEADER;
|
||||||
hsData[MD5] = data.md5;
|
hsData[MD5] = data.md5;
|
||||||
hsData[VARIATION] = data.variation;
|
hsData[VARIATION] = data.variation;
|
||||||
|
@ -608,16 +608,10 @@ void HighScoresManager::saveHighScores(ScoresData& data) const
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void HighScoresManager::loadHighScores(ScoresData& data)
|
void HighScoresManager::loadHighScores(ScoresData& data)
|
||||||
{
|
{
|
||||||
for(uInt32 r = 0; r < NUM_RANKS; ++r)
|
|
||||||
{
|
|
||||||
data.scores[r].score = 0;
|
|
||||||
data.scores[r].special = 0;
|
|
||||||
data.scores[r].name = "";
|
|
||||||
data.scores[r].date = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
ostringstream buf;
|
ostringstream buf;
|
||||||
|
|
||||||
|
clearHighScores(data);
|
||||||
|
|
||||||
bool invalid = false;
|
bool invalid = false;
|
||||||
try {
|
try {
|
||||||
Variant serializedHighscore;
|
Variant serializedHighscore;
|
||||||
|
@ -631,10 +625,9 @@ void HighScoresManager::loadHighScores(ScoresData& data)
|
||||||
const json hsData = hsObject.at(DATA);
|
const json hsData = hsObject.at(DATA);
|
||||||
|
|
||||||
// First test if we have a valid header
|
// First test if we have a valid header
|
||||||
// If so, do a complete high data load
|
// If so, do a complete high score data load
|
||||||
if(!hsData.contains(VERSION) || hsData.at(VERSION) != HIGHSCORE_HEADER)
|
if(!hsData.contains(VERSION) || hsData.at(VERSION) != HIGHSCORE_HEADER)
|
||||||
buf << "Error: Incompatible high scores file for variation "
|
buf << "Error: Incompatible high scores data for variation " << data.variation << ".";
|
||||||
<< data.variation << ".";
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(!load(hsData, data)
|
if(!load(hsData, data)
|
||||||
|
@ -651,9 +644,11 @@ void HighScoresManager::loadHighScores(ScoresData& data)
|
||||||
}
|
}
|
||||||
catch(...) { invalid = true; }
|
catch(...) { invalid = true; }
|
||||||
|
|
||||||
if (invalid)
|
if(invalid)
|
||||||
buf << "Error: Invalid data in high scores file for variation " << data.variation << ".";
|
{
|
||||||
|
clearHighScores(data);
|
||||||
|
buf << "Error: Invalid high scores data for variation " << data.variation << ".";
|
||||||
|
}
|
||||||
myOSystem.frameBuffer().showTextMessage(buf.str());
|
myOSystem.frameBuffer().showTextMessage(buf.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,6 +683,18 @@ bool HighScoresManager::load(const json& hsData, ScoresData& data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
void HighScoresManager::clearHighScores(ScoresData& data)
|
||||||
|
{
|
||||||
|
for(uInt32 r = 0; r < NUM_RANKS; ++r)
|
||||||
|
{
|
||||||
|
data.scores[r].score = 0;
|
||||||
|
data.scores[r].special = 0;
|
||||||
|
data.scores[r].name = "";
|
||||||
|
data.scores[r].date = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
const string HighScoresManager::VARIATIONS_COUNT = "variations_count";
|
const string HighScoresManager::VARIATIONS_COUNT = "variations_count";
|
||||||
const string HighScoresManager::VARIATIONS_ADDRESS = "variations_address";
|
const string HighScoresManager::VARIATIONS_ADDRESS = "variations_address";
|
||||||
|
|
|
@ -243,6 +243,8 @@ class HighScoresManager
|
||||||
*/
|
*/
|
||||||
bool load(const json& hsData, HSM::ScoresData& scores);
|
bool load(const json& hsData, HSM::ScoresData& scores);
|
||||||
|
|
||||||
|
void clearHighScores(HSM::ScoresData& data);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Reference to the osystem object
|
// Reference to the osystem object
|
||||||
OSystem& myOSystem;
|
OSystem& myOSystem;
|
||||||
|
|
Loading…
Reference in New Issue