import gsap from "gsap"; export const useAchievementsScreen = defineStore("achievementsScreen", { state: () => ({ fadeToBlack: { opacity: 0, active: false, isOutro: false, }, intro: { stage1Opacity: 0, itemOffsets: {} as Record, progressBar: 0, }, outro: { stage1Opacity: 1, stage2Opacity: 1, }, isIntro: true, isOutro: false, }), actions: { animateFadeToBlackIntro() { this.fadeToBlack.active = true; this.fadeToBlack.isOutro = false; gsap .timeline({ onComplete: () => { const app = useAppStore(); app.navigateTo("achievements"); }, }) .fromTo( this.fadeToBlack, { opacity: 0 }, { opacity: 1, duration: 0.4, ease: "none", }, ); }, animateFadeToBlackOutro() { this.fadeToBlack.active = true; this.fadeToBlack.isOutro = true; this.fadeToBlack.opacity = 1; gsap .timeline({ onComplete: () => { this.fadeToBlack.active = false; this.isOutro = false; }, }) .fromTo( this.fadeToBlack, { opacity: 1 }, { opacity: 0, duration: 0.4, ease: "none", }, ); }, animateIntro() { this.isIntro = true; this.isOutro = false; const itemCount = ACHIEVEMENTS.length; for (let i = 0; i < itemCount; i++) { this.intro.itemOffsets[i] = -ACHIEVEMENTS_LINE_HEIGHT; } const tl = gsap.timeline({ onComplete: () => { this.isIntro = false; }, }); tl.fromTo( this.intro, { stage1Opacity: 0 }, { stage1Opacity: 1, duration: 0.5, ease: "none", }, 0.5, ).fromTo( this.intro, { progressBar: 0 }, { progressBar: 1, duration: 1.5, ease: "power2.out", }, 0.25, ); for (let i = 0; i < itemCount; i++) { tl.to( this.intro.itemOffsets, { [i]: 0, duration: 0.4, ease: "power2.out", }, 0.75 + i * 0.05, ); } }, animateOutro() { this.isIntro = false; this.isOutro = true; gsap .timeline() .fromTo( this.outro, { stage1Opacity: 1 }, { stage1Opacity: 0, duration: 0.3, }, ) .fromTo( this.outro, { stage2Opacity: 1 }, { stage2Opacity: 0, duration: 0.3, }, "-=0.15", ) .call(() => { const app = useAppStore(); app.navigateTo(app.previousScreen); this.animateFadeToBlackOutro(); }); }, getItemOffset(index: number): number { return this.intro.itemOffsets[index] ?? 0; }, }, });