From ead931211c6783975d01928fa4636e42208689a1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 22 Jan 2023 04:24:38 +0900 Subject: [PATCH] =?UTF-8?q?fix(client):=20=E5=AE=9F=E7=B8=BE=E8=A7=A3?= =?UTF-8?q?=E9=99=A4=E3=83=AA=E3=82=AF=E3=82=A8=E3=82=B9=E3=83=88=E3=81=AE?= =?UTF-8?q?=E9=96=93=E9=9A=94=E3=82=92=E3=81=82=E3=81=91=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix #9674 --- packages/frontend/src/scripts/achievements.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/scripts/achievements.ts b/packages/frontend/src/scripts/achievements.ts index 8f484f892..c97358e88 100644 --- a/packages/frontend/src/scripts/achievements.ts +++ b/packages/frontend/src/scripts/achievements.ts @@ -433,16 +433,22 @@ export const ACHIEVEMENT_BADGES = { export const claimedAchievements = ($i && $i.achievements) ? $i.achievements.map(x => x.name) : []; -export function claimAchievement(type: typeof ACHIEVEMENT_TYPES[number]) { +const claimingQueue = new Set(); + +export async function claimAchievement(type: typeof ACHIEVEMENT_TYPES[number]) { if (claimedAchievements.includes(type)) return; - os.api('i/claim-achievement', { name: type }); + claimingQueue.add(type); claimedAchievements.push(type); + await new Promise(resolve => setTimeout(resolve, (claimingQueue.size - 1) * 500)); + window.setTimeout(() => { + claimingQueue.delete(type); + }, 500); + os.api('i/claim-achievement', { name: type }); } if (_DEV_) { - (window as any).unlockAllAchievements = async () => { + (window as any).unlockAllAchievements = () => { for (const t of ACHIEVEMENT_TYPES) { - await new Promise(resolve => setTimeout(resolve, 100)); claimAchievement(t); } };