@webxdc/highscores
Advanced tools
Comparing version 5.2.0 to 5.2.1
{ | ||
"name": "@webxdc/highscores", | ||
"description": "Highscores API for webxdc apps", | ||
"version": "5.2.0", | ||
"version": "5.2.1", | ||
"license": "MIT", | ||
@@ -33,2 +33,6 @@ "author": "adbenitez", | ||
}, | ||
"scripts": { | ||
"fix": "prettier --write .", | ||
"check": "prettier --check ." | ||
}, | ||
"devDependencies": { | ||
@@ -39,7 +43,3 @@ "prettier": "^3.3.3" | ||
"jssha": "^3.3.1" | ||
}, | ||
"scripts": { | ||
"fix": "prettier --write .", | ||
"check": "prettier --check ." | ||
} | ||
} | ||
} |
@@ -27,2 +27,7 @@ //@ts-check | ||
onHighscoresChanged?: (scoreboard?: string) => void; | ||
/** A function that returns the default initial score that is returned by window.highscores.getScore() if there is no highscore yet. | ||
By default the initial score is zero, you need to provide this function if you | ||
are not passing a number to window.highscores.setScore() | ||
*/ | ||
getInitialScore?: (scoreboard?: string) => T; | ||
}; | ||
@@ -29,0 +34,0 @@ |
@@ -7,3 +7,4 @@ import jsSHA from "jssha"; | ||
_compareScores = (score1, score2) => score1 - score2, | ||
_onHighscoresChanged = () => {}; | ||
_onHighscoresChanged = () => {}, | ||
_getInitialScore = () => 0; | ||
const maxserialKey = "_webxdc-scores_.max_serial", | ||
@@ -28,3 +29,3 @@ scoreboardsKey = "_webxdc-scores_.scoreboards"; | ||
const players = scoreboards[scoreboard] || {}; | ||
return players[id] ? players[id].score : 0; | ||
return players[id] ? players[id].score : _getInitialScore(); | ||
}; | ||
@@ -37,2 +38,3 @@ | ||
onHighscoresChanged, | ||
getInitialScore, | ||
} = {}) { | ||
@@ -51,2 +53,6 @@ if (getAnnouncement) { | ||
if (getInitialScore) { | ||
_getInitialScore = getInitialScore; | ||
} | ||
scoreboards = JSON.parse(localStorage.getItem(scoreboardsKey) || "{}"); | ||
@@ -53,0 +59,0 @@ for (const scoreboard of Object.keys(scoreboards)) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11984
237