diff --git a/store/useInventoryStore.ts b/store/useInventoryStore.ts index d27ae06..9ab615e 100644 --- a/store/useInventoryStore.ts +++ b/store/useInventoryStore.ts @@ -4,17 +4,18 @@ import { persist } from 'zustand/middleware'; export interface InventoryState { unlockedCharacters: string[]; unlockedCustomizations: string[]; + unlockedDLCs: string[]; items: Record; offerings: Record; unlockAllDLCs: boolean; - toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings') => void; + toggleItem: (id: string, category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; setItemQuantity: (id: string, qty: number) => void; setOfferingQuantity: (id: string, qty: number) => void; setUnlockAllDLCs: (val: boolean) => void; - unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings', allIds: string[], qty?: number) => void; - clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings') => void; + unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs', allIds: string[], qty?: number) => void; + clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void; clearAll: () => void; importProfile: (profile: any) => void; } @@ -24,6 +25,7 @@ export const useInventoryStore = create()( (set) => ({ unlockedCharacters: [], unlockedCustomizations: [], + unlockedDLCs: [], items: {}, offerings: {}, unlockAllDLCs: false, @@ -39,6 +41,11 @@ export const useInventoryStore = create()( return { unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] }; + } else if (category === 'dlcs') { + const arr = state.unlockedDLCs; + return { + unlockedDLCs: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id] + }; } else if (category === 'items') { const current = state.items[id] || 0; const newItems = { ...state.items }; @@ -87,6 +94,8 @@ export const useInventoryStore = create()( return { unlockedCharacters: allIds }; } else if (category === 'customizations') { return { unlockedCustomizations: allIds }; + } else if (category === 'dlcs') { + return { unlockedDLCs: allIds }; } else if (category === 'items') { const newItems = { ...state.items }; allIds.forEach(id => { @@ -105,6 +114,7 @@ export const useInventoryStore = create()( clearCategory: (category) => set((state) => { if (category === 'characters') return { unlockedCharacters: [] }; if (category === 'customizations') return { unlockedCustomizations: [] }; + if (category === 'dlcs') return { unlockedDLCs: [] }; if (category === 'items') return { items: {} }; return { offerings: {} }; }), @@ -112,6 +122,7 @@ export const useInventoryStore = create()( clearAll: () => set({ unlockedCharacters: [], unlockedCustomizations: [], + unlockedDLCs: [], items: {}, offerings: {}, unlockAllDLCs: false @@ -122,6 +133,7 @@ export const useInventoryStore = create()( return { unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters, unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations, + unlockedDLCs: Array.isArray(profile.unlockedDLCs) ? profile.unlockedDLCs : state.unlockedDLCs, items: (profile.items && typeof profile.items === 'object') ? profile.items : state.items, offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings, unlockAllDLCs: typeof profile.unlockAllDLCs === 'boolean' ? profile.unlockAllDLCs : state.unlockAllDLCs,