feat: track dlcs
This commit is contained in:
@@ -4,17 +4,18 @@ import { persist } from 'zustand/middleware';
|
|||||||
export interface InventoryState {
|
export interface InventoryState {
|
||||||
unlockedCharacters: string[];
|
unlockedCharacters: string[];
|
||||||
unlockedCustomizations: string[];
|
unlockedCustomizations: string[];
|
||||||
|
unlockedDLCs: string[];
|
||||||
items: Record<string, number>;
|
items: Record<string, number>;
|
||||||
offerings: Record<string, number>;
|
offerings: Record<string, number>;
|
||||||
unlockAllDLCs: boolean;
|
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;
|
setItemQuantity: (id: string, qty: number) => void;
|
||||||
setOfferingQuantity: (id: string, qty: number) => void;
|
setOfferingQuantity: (id: string, qty: number) => void;
|
||||||
setUnlockAllDLCs: (val: boolean) => void;
|
setUnlockAllDLCs: (val: boolean) => void;
|
||||||
|
|
||||||
unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings', allIds: string[], qty?: number) => void;
|
unlockAllInCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs', allIds: string[], qty?: number) => void;
|
||||||
clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings') => void;
|
clearCategory: (category: 'characters' | 'customizations' | 'items' | 'offerings' | 'dlcs') => void;
|
||||||
clearAll: () => void;
|
clearAll: () => void;
|
||||||
importProfile: (profile: any) => void;
|
importProfile: (profile: any) => void;
|
||||||
}
|
}
|
||||||
@@ -24,6 +25,7 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
(set) => ({
|
(set) => ({
|
||||||
unlockedCharacters: [],
|
unlockedCharacters: [],
|
||||||
unlockedCustomizations: [],
|
unlockedCustomizations: [],
|
||||||
|
unlockedDLCs: [],
|
||||||
items: {},
|
items: {},
|
||||||
offerings: {},
|
offerings: {},
|
||||||
unlockAllDLCs: false,
|
unlockAllDLCs: false,
|
||||||
@@ -39,6 +41,11 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
return {
|
return {
|
||||||
unlockedCustomizations: arr.includes(id) ? arr.filter(i => i !== id) : [...arr, id]
|
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') {
|
} else if (category === 'items') {
|
||||||
const current = state.items[id] || 0;
|
const current = state.items[id] || 0;
|
||||||
const newItems = { ...state.items };
|
const newItems = { ...state.items };
|
||||||
@@ -87,6 +94,8 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
return { unlockedCharacters: allIds };
|
return { unlockedCharacters: allIds };
|
||||||
} else if (category === 'customizations') {
|
} else if (category === 'customizations') {
|
||||||
return { unlockedCustomizations: allIds };
|
return { unlockedCustomizations: allIds };
|
||||||
|
} else if (category === 'dlcs') {
|
||||||
|
return { unlockedDLCs: allIds };
|
||||||
} else if (category === 'items') {
|
} else if (category === 'items') {
|
||||||
const newItems = { ...state.items };
|
const newItems = { ...state.items };
|
||||||
allIds.forEach(id => {
|
allIds.forEach(id => {
|
||||||
@@ -105,6 +114,7 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
clearCategory: (category) => set((state) => {
|
clearCategory: (category) => set((state) => {
|
||||||
if (category === 'characters') return { unlockedCharacters: [] };
|
if (category === 'characters') return { unlockedCharacters: [] };
|
||||||
if (category === 'customizations') return { unlockedCustomizations: [] };
|
if (category === 'customizations') return { unlockedCustomizations: [] };
|
||||||
|
if (category === 'dlcs') return { unlockedDLCs: [] };
|
||||||
if (category === 'items') return { items: {} };
|
if (category === 'items') return { items: {} };
|
||||||
return { offerings: {} };
|
return { offerings: {} };
|
||||||
}),
|
}),
|
||||||
@@ -112,6 +122,7 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
clearAll: () => set({
|
clearAll: () => set({
|
||||||
unlockedCharacters: [],
|
unlockedCharacters: [],
|
||||||
unlockedCustomizations: [],
|
unlockedCustomizations: [],
|
||||||
|
unlockedDLCs: [],
|
||||||
items: {},
|
items: {},
|
||||||
offerings: {},
|
offerings: {},
|
||||||
unlockAllDLCs: false
|
unlockAllDLCs: false
|
||||||
@@ -122,6 +133,7 @@ export const useInventoryStore = create<InventoryState>()(
|
|||||||
return {
|
return {
|
||||||
unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters,
|
unlockedCharacters: Array.isArray(profile.unlockedCharacters) ? profile.unlockedCharacters : state.unlockedCharacters,
|
||||||
unlockedCustomizations: Array.isArray(profile.unlockedCustomizations) ? profile.unlockedCustomizations : state.unlockedCustomizations,
|
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,
|
items: (profile.items && typeof profile.items === 'object') ? profile.items : state.items,
|
||||||
offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings,
|
offerings: (profile.offerings && typeof profile.offerings === 'object') ? profile.offerings : state.offerings,
|
||||||
unlockAllDLCs: typeof profile.unlockAllDLCs === 'boolean' ? profile.unlockAllDLCs : state.unlockAllDLCs,
|
unlockAllDLCs: typeof profile.unlockAllDLCs === 'boolean' ? profile.unlockAllDLCs : state.unlockAllDLCs,
|
||||||
|
|||||||
Reference in New Issue
Block a user