Skip to content

Commit

Permalink
Merge pull request #13 from metaversecloud-com/master
Browse files Browse the repository at this point in the history
Merge master into deploy
  • Loading branch information
liebeskind committed Sep 22, 2023
2 parents 49fcf89 + 97e50bb commit 6ae25a1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions wiggle/src/rtsdk/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const updateInAppLeaderboard = async ({ leaderboardArray, req }) => {
const score = leaderboardArray[i].data.kills;
const id = leaderboardArray[i].id;
name = leaderboardArray[i].data.name;
sanitizedArray.push({ id, score, name, date });
if (id && score && name && date) sanitizedArray.push({ id, score, name, date });
}
}

Expand All @@ -32,9 +32,19 @@ export const updateHighScores = async ({ req, sanitizedArray }) => {
const { dataObject } = arcadeAsset;
const { highScores } = dataObject;

if (!sanitizedArray.length) return highScores;

// Don't update high score if the lowest high score is higher than the top current score.
if (highScores && highScores[2] && sanitizedArray && sanitizedArray[0].score < highScores[2].score) return highScores;
if (
highScores &&
highScores[2] &&
sanitizedArray &&
sanitizedArray[0] &&
sanitizedArray[0].score < highScores[2].score
)
return highScores;

// This is to compare high score array to current scores array and update high scores if necessary.
let newArray = highScores ? sanitizedArray.concat(highScores) : sanitizedArray;
let sortedArray = newArray.sort((a, b) => {
return b.score - a.score;
Expand Down

0 comments on commit 6ae25a1

Please sign in to comment.