This commit is contained in:
Ted John 2016-10-14 00:01:34 +01:00
parent 00c47b8a04
commit f519bc6cad
3 changed files with 16 additions and 10 deletions

View File

@ -194,7 +194,7 @@ public:
bool TryRecordHighscore(const utf8 * scenarioFileName, money32 companyValue, const utf8 * name) override
{
const scenario_index_entry * scenario = GetByFilename(scenarioFileName);
scenario_index_entry * scenario = GetByFilename(scenarioFileName);
if (scenario != nullptr)
{
// Check if record company value has been broken or the highscore is the same but no name is registered
@ -205,20 +205,21 @@ public:
if (highscore == nullptr)
{
highscore = InsertHighscore();
scenario->highscore->timestamp = platform_get_datetime_now_utc();
highscore->timestamp = platform_get_datetime_now_utc();
scenario->highscore = highscore;
}
else
{
if (highscore->name != nullptr)
{
scenario->highscore->timestamp = platform_get_datetime_now_utc();
highscore->timestamp = platform_get_datetime_now_utc();
}
SafeFree(highscore->fileName);
SafeFree(highscore->name);
}
scenario->highscore->fileName = String::Duplicate(Path::GetFileName(scenario->path));
scenario->highscore->name = String::Duplicate(name);
scenario->highscore->company_value = companyValue;
highscore->fileName = String::Duplicate(Path::GetFileName(scenario->path));
highscore->name = String::Duplicate(name);
highscore->company_value = companyValue;
SaveHighscores();
return true;
}
@ -499,7 +500,7 @@ private:
for (size_t i = 0; i < _highscores.size(); i++)
{
scenario_highscore_entry * highscore = _highscores[i];
scenario_index_entry * scenerio = GetByPath(highscore->fileName);
scenario_index_entry * scenerio = GetByFilename(highscore->fileName);
if (scenerio != nullptr)
{
scenerio->highscore = highscore;

View File

@ -177,8 +177,13 @@ namespace String
utf8 * Duplicate(const utf8 * src)
{
size_t srcSize = SizeOf(src);
return Memory::DuplicateArray(src, srcSize + 1);
utf8 * result = nullptr;
if (src != nullptr)
{
size_t srcSize = SizeOf(src);
result = Memory::DuplicateArray(src, srcSize + 1);
}
return result;
}
utf8 * DiscardUse(utf8 * * ptr, utf8 * replacement)

View File

@ -353,7 +353,7 @@ void scenario_success()
*/
void scenario_success_submit_name(const char *name)
{
if (scenario_repository_try_record_highscore(_scenarioFileName, gScenarioCompanyValueRecord, NULL))
if (scenario_repository_try_record_highscore(_scenarioFileName, gScenarioCompanyValueRecord, name))
{
safe_strcpy(gScenarioCompletedBy, name, 32);
}