diff --git a/native/app/store/Definitions.ts b/native/app/store/Definitions.ts index 71f14e078..c3f5a2497 100644 --- a/native/app/store/Definitions.ts +++ b/native/app/store/Definitions.ts @@ -1,9 +1,7 @@ import type { DestinyItem, Guardian, ProfileData } from "@/app/bungie/Types.ts"; -import type { SingleItemDefinition } from "@/app/store/Types.ts"; +import type { SingleItemDefinition, SocketCategoryItem, SocketEntryItem } from "@/app/store/Types.ts"; export type ItemsDefinition = Record; -// SocketEntries: unknown(), -// SocketIndexes: unknown(), export let itemsDefinition: ItemsDefinition = {}; export let BucketTypeHashArray: number[]; @@ -20,9 +18,9 @@ export let PlugCategoryHash: number[]; export let PlugCategoryIdentifier: string[]; export let ReusablePlugSetHash: number[]; export let SingleInitialItemHash: number[]; -export let SocketCategories: string[]; // These strings are JSON objects +export let SocketCategories: SocketCategoryItem[]; // These strings are JSON objects export let SocketCategoryHash: number[]; -export let SocketEntries: string[]; +export let SocketEntries: SocketEntryItem[]; export let SocketIndexes: number[][]; export let SocketTypeHash: number[]; export let StackUniqueLabel: string[]; @@ -101,34 +99,20 @@ export function setSingleInitialItemHash(singleInitialItemHashDefinition: number SingleInitialItemHash = singleInitialItemHashDefinition; } -export function setSocketCategories(socketCategoriesDefinition: string[]) { - const si: JSON[][] = []; - for (const socketCategory of socketCategoriesDefinition) { - si.push(JSON.parse(socketCategory) as JSON[]); - } - - SocketCategories = socketCategoriesDefinition; +export function setSocketCategories(socketCategoriesDefinition: unknown) { + SocketCategories = socketCategoriesDefinition as SocketCategoryItem[]; } export function setSocketCategoryHash(socketCategoryHashDefinition: number[]) { SocketCategoryHash = socketCategoryHashDefinition; } -export function setSocketEntries(socketEntriesDefinition: string[]) { - const si: JSON[][] = []; - for (const socketEntry of socketEntriesDefinition) { - si.push(JSON.parse(socketEntry) as JSON[]); - } - - SocketEntries = socketEntriesDefinition; +export function setSocketEntries(socketEntriesDefinition: unknown) { + SocketEntries = socketEntriesDefinition as SocketEntryItem[]; } -export function setSocketIndexes(socketIndexesDefinition: string[]) { - const si: number[][] = []; - for (const socketIndex of socketIndexesDefinition) { - si.push(JSON.parse(socketIndex) as number[]); - } - SocketIndexes = si; +export function setSocketIndexes(socketIndexesDefinition: unknown) { + SocketIndexes = socketIndexesDefinition as number[][]; } export function setSocketTypeHash(socketTypeHashDefinition: number[]) { diff --git a/native/app/store/DefinitionsSlice.ts b/native/app/store/DefinitionsSlice.ts index 4fdd03744..9c0431f6f 100644 --- a/native/app/store/DefinitionsSlice.ts +++ b/native/app/store/DefinitionsSlice.ts @@ -125,7 +125,6 @@ async function downloadAndStoreItemDefinition(set: DefinitionsSliceSetter): Prom } function parseAndSet(itemDefinition: ItemResponse) { - const p1 = performance.now(); setItemDefinition(itemDefinition.items as ItemsDefinition); setBucketTypeHashArray(itemDefinition.helpers.BucketTypeHash); setDamageTypeHashes(itemDefinition.helpers.DamageTypeHashes); @@ -154,8 +153,6 @@ function parseAndSet(itemDefinition: ItemResponse) { setTraitIds(itemDefinition.helpers.TraitIds); setUiItemDisplayStyle(itemDefinition.helpers.UiItemDisplayStyle); setUiPlugLabel(itemDefinition.helpers.UiPlugLabel); - const p2 = performance.now(); - console.log("parseAndSet", p2 - p1); return { definitionsReady: true }; } diff --git a/native/app/store/Types.ts b/native/app/store/Types.ts index 35c9e3c1b..1ffaad06d 100644 --- a/native/app/store/Types.ts +++ b/native/app/store/Types.ts @@ -8,7 +8,7 @@ export const DatabaseStore = { databaseName: "ggDataBase.db", }; -const MINI_ITEM_DEFINITION_VERSION = 2; +const MINI_ITEM_DEFINITION_VERSION = 3; export const itemSchema = object({ a: optional(number()), @@ -67,6 +67,21 @@ export const itemSchema = object({ export type SingleItemDefinition = Output; +const SocketCategorySchema = array(record(string(), object({ h: number(), i: number() }))); +export type SocketCategoryItem = Output; + +const SocketEntrySchema = array( + array( + object({ + p: optional(number()), + r: optional(number()), + s: optional(number()), + st: optional(number()), + }), + ), +); +export type SocketEntryItem = Output; + export const ItemResponseSchema = object({ helpers: object( { @@ -84,10 +99,10 @@ export const ItemResponseSchema = object({ PlugCategoryIdentifier: array(string()), ReusablePlugSetHash: array(number()), SingleInitialItemHash: array(number()), - SocketCategories: array(string()), + SocketCategories: unknown(), SocketCategoryHash: array(number()), - SocketEntries: array(string()), - SocketIndexes: array(string()), + SocketEntries: unknown(), + SocketIndexes: unknown(), SocketTypeHash: array(number()), StackUniqueLabel: array(string()), StatGroupHash: array(number()),