Public Access
feat(game): play confetti for finished games
This commit is contained in:
1 parent
09e1f767d8
commit
a5458b3f86
9 files changed
+260
-9
No files matched your search
@@ -0,0 +1,29 @@
|
||||
const FINISHED = ['FINISHED', 'COMPLETED'];
|
||||
|
||||
/**
|
||||
* Every achievement unlocked. Only while the stats are visible: Core can still send the old unlock count after they turn private.
|
||||
*/
|
||||
export const allAchievementsUnlocked = (game) => game.hasAchievements && game.statsVisible
|
||||
&& game.achievementsTotal > 0 && game.achievementsUnlocked >= game.achievementsTotal;
|
||||
|
||||
/**
|
||||
* 0: not finished, 1: finished, 2: finished and every achievement unlocked.
|
||||
*/
|
||||
export const celebrationLevel = (game) => {
|
||||
if (!FINISHED.includes(game.status)) return 0;
|
||||
return allAchievementsUnlocked(game) ? 2 : 1;
|
||||
};
|
||||
|
||||
/**
|
||||
* The confetti to play when the page shows this game: on opening a finished game, and when the level rises on the
|
||||
* same page (e.g. the user sets FINISHED). A reload of the same game plays nothing.
|
||||
*
|
||||
* @param before {appid, level} of the game shown before, null on opening the page
|
||||
* @returns 'small', 'big' or null
|
||||
*/
|
||||
export const celebrationFor = (before, game) => {
|
||||
const level = celebrationLevel(game);
|
||||
const from = before?.appid === game.appid ? before.level : 0;
|
||||
if (level <= from) return null;
|
||||
return level === 2 ? 'big' : 'small';
|
||||
};
|
||||
Reference in new issue
Block a user