feat: track dlcs

This commit is contained in:
2026-06-18 20:40:58 -03:00
parent 60effa5dac
commit f922570c7a
+15 -3
View File
@@ -4,17 +4,18 @@ import { persist } from 'zustand/middleware';
export interface InventoryState {
unlockedCharacters: string[];
unlockedCustomizations: string[];
unlockedDLCs: string[];
items: Record<string, number>;
offerings: Record<string, number>;
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<InventoryState>()(
(set) => ({
unlockedCharacters: [],
unlockedCustomizations: [],
unlockedDLCs: [],
items: {},
offerings: {},
unlockAllDLCs: false,
@@ -39,6 +41,11 @@ export const useInventoryStore = create<InventoryState>()(
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<InventoryState>()(
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<InventoryState>()(
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<InventoryState>()(
clearAll: () => set({
unlockedCharacters: [],
unlockedCustomizations: [],
unlockedDLCs: [],
items: {},
offerings: {},
unlockAllDLCs: false
@@ -122,6 +133,7 @@ export const useInventoryStore = create<InventoryState>()(
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,