From: Holger Schemel Date: Sat, 1 May 2021 15:27:46 +0000 (+0200) Subject: added function to load and merge local and server scores X-Git-Tag: 4.3.0.0~168 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=d29d345324b2af238f39e1ee3b71d38b2eee9b4e;p=rocksndiamonds.git added function to load and merge local and server scores --- diff --git a/src/files.c b/src/files.c index eb47c4ef..1adbfd74 100644 --- a/src/files.c +++ b/src/files.c @@ -8438,6 +8438,7 @@ static void setScoreInfoToDefaultsExt(struct ScoreInfo *scores) scores->num_entries = 0; scores->last_added = -1; + scores->last_added_local = -1; } static void setScoreInfoToDefaults(void) @@ -9052,8 +9053,6 @@ void LoadServerScore(int nr) DownloadServerScoreToCache(nr); LoadServerScoreFromCache(nr); - - MergeServerScore(); } static char *get_file_base64(char *filename) @@ -9196,6 +9195,20 @@ void SaveServerScore(int nr) UploadScoreToServer(nr); } +void LoadLocalAndServerScore(int nr) +{ + int last_added_local = scores.last_added_local; + + LoadScore(nr); + + // restore last added local score entry (before merging server scores) + scores.last_added = scores.last_added_local = last_added_local; + + LoadServerScore(nr); + + MergeServerScore(); +} + // ============================================================================ // setup file functions diff --git a/src/files.h b/src/files.h index 803762db..bd2207a9 100644 --- a/src/files.h +++ b/src/files.h @@ -65,6 +65,8 @@ void SaveScore(int); void LoadServerScore(int); void SaveServerScore(int); +void LoadLocalAndServerScore(int); + void LoadUserNames(void); void LoadSetupFromFilename(char *); diff --git a/src/game.c b/src/game.c index f783c164..79ee535e 100644 --- a/src/game.c +++ b/src/game.c @@ -5133,6 +5133,9 @@ void NewHighScore(int level_nr) SaveScoreTape(level_nr); SaveServerScore(level_nr); } + + // store last added local score entry (before merging server scores) + scores.last_added_local = scores.last_added; } } diff --git a/src/main.h b/src/main.h index 2d4e61d6..fe1106db 100644 --- a/src/main.h +++ b/src/main.h @@ -3056,6 +3056,7 @@ struct ScoreInfo int num_entries; int last_added; + int last_added_local; struct ScoreEntry entry[MAX_SCORE_ENTRIES]; }; diff --git a/src/screens.c b/src/screens.c index 843458f9..2e9d67d2 100644 --- a/src/screens.c +++ b/src/screens.c @@ -5046,10 +5046,7 @@ void DrawHallOfFame(int level_nr) SetDrawDeactivationMask(REDRAW_NONE); SetDrawBackgroundMask(REDRAW_FIELD); - if (scores.last_added < 0) - LoadScore(level_nr); - - LoadServerScore(level_nr); + LoadLocalAndServerScore(level_nr); if (scores.last_added >= 0) SetAnimStatus(GAME_MODE_PSEUDO_SCORESNEW);