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: only when the level rises while the page shows the game (the user sets Finished or completes * it here). Opening a finished game and a reload play 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) => { if (before?.appid !== game.appid) return null; const level = celebrationLevel(game); if (level <= before.level) return null; return level === 2 ? 'big' : 'small'; };