feat(achievements): remove secret achievements and add new ones. also play sound only when notification comes up instead of instantly
This commit is contained in:
@@ -13,43 +13,34 @@ export const ACHIEVEMENTS = [
|
||||
// contact
|
||||
{ id: "contact_visit", secret: false },
|
||||
{ id: "contact_git_visit", secret: false },
|
||||
{ id: "contact_linkedin_visit", secret: false },
|
||||
// settings
|
||||
{ id: "settings_color_change", secret: false },
|
||||
{ id: "settings_visit_all", secret: false },
|
||||
// snake
|
||||
{ id: "snake_score_25", secret: false },
|
||||
// 2048
|
||||
{ id: "2048_score_512", secret: false },
|
||||
// taptap
|
||||
{ id: "taptap_score_20", secret: false },
|
||||
// secrets
|
||||
{ id: "settings_color_try_all", secret: true },
|
||||
{ id: "settings_visit_all", secret: true },
|
||||
{ id: "contact_36_notifications", secret: true },
|
||||
// meta
|
||||
{ id: "all_achievements", secret: false },
|
||||
] as const;
|
||||
|
||||
export type Achievement = (typeof ACHIEVEMENTS)[number]["id"];
|
||||
|
||||
export const useAchievementsStore = defineStore("achievements", () => {
|
||||
const app = useAppStore();
|
||||
|
||||
const storage = useLocalStorage(
|
||||
STORAGE_ID,
|
||||
{
|
||||
unlocked: [] as Achievement[],
|
||||
advancement: {
|
||||
colors: [app.color.hex],
|
||||
visitedSettings: [] as string[],
|
||||
},
|
||||
},
|
||||
{ mergeDefaults: true },
|
||||
);
|
||||
|
||||
if (!storage.value.advancement.colors.includes(app.color.hex)) {
|
||||
storage.value.advancement.colors.push(app.color.hex);
|
||||
}
|
||||
|
||||
const confetti = useConfetti();
|
||||
|
||||
const unlock = (name: Achievement) => {
|
||||
if (storage.value.unlocked.includes(name)) {
|
||||
return false;
|
||||
@@ -57,13 +48,14 @@ export const useAchievementsStore = defineStore("achievements", () => {
|
||||
|
||||
storage.value.unlocked.push(name);
|
||||
|
||||
const { assets } = useAssets();
|
||||
assets.audio.messageReceived.play(0.5);
|
||||
|
||||
if (storage.value.unlocked.length === ACHIEVEMENTS.length) {
|
||||
confetti.spawn();
|
||||
} else {
|
||||
confetti.spawn(50, 175);
|
||||
if (name !== "all_achievements") {
|
||||
const othersCount = ACHIEVEMENTS.length - 1;
|
||||
const unlockedOthers = storage.value.unlocked.filter(
|
||||
(id) => id !== "all_achievements" && validIds.has(id as Achievement),
|
||||
).length;
|
||||
if (unlockedOthers === othersCount) {
|
||||
unlock("all_achievements");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -73,18 +65,20 @@ export const useAchievementsStore = defineStore("achievements", () => {
|
||||
storage.value = {
|
||||
unlocked: [],
|
||||
advancement: {
|
||||
colors: [app.color.hex],
|
||||
visitedSettings: [],
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const validIds = new Set(ACHIEVEMENTS.map((a) => a.id));
|
||||
const unlocked = computed(() =>
|
||||
storage.value.unlocked.filter((id) => validIds.has(id as Achievement)),
|
||||
);
|
||||
|
||||
return {
|
||||
unlocked: computed(() => storage.value.unlocked),
|
||||
unlocked,
|
||||
advancement: computed(() => storage.value.advancement),
|
||||
allObtained: computed(
|
||||
() => storage.value.unlocked.length === ACHIEVEMENTS.length,
|
||||
),
|
||||
allObtained: computed(() => unlocked.value.length === ACHIEVEMENTS.length),
|
||||
unlock,
|
||||
reset,
|
||||
isUnlocked: computed(
|
||||
|
||||
@@ -86,10 +86,6 @@ export const useContactStore = defineStore("contact", {
|
||||
{ notificationsYOffset: 0, duration: 0.075 },
|
||||
);
|
||||
|
||||
if (this.notifications.length === 36) {
|
||||
const achievements = useAchievementsStore();
|
||||
achievements.unlock("contact_36_notifications");
|
||||
}
|
||||
},
|
||||
|
||||
animateOutro() {
|
||||
|
||||
Reference in New Issue
Block a user