Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Parse the new custom helpers #1472

Merged
merged 1 commit into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 9 additions & 25 deletions native/app/store/Definitions.ts
Original file line number Diff line number Diff line change
@@ -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<string, SingleItemDefinition>;
// SocketEntries: unknown(),
// SocketIndexes: unknown(),

export let itemsDefinition: ItemsDefinition = {};
export let BucketTypeHashArray: number[];
Expand All @@ -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[];
Expand Down Expand Up @@ -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[]) {
Expand Down
3 changes: 0 additions & 3 deletions native/app/store/DefinitionsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 };
}

Expand Down
23 changes: 19 additions & 4 deletions native/app/store/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down Expand Up @@ -67,6 +67,21 @@ export const itemSchema = object({

export type SingleItemDefinition = Output<typeof itemSchema>;

const SocketCategorySchema = array(record(string(), object({ h: number(), i: number() })));
export type SocketCategoryItem = Output<typeof SocketCategorySchema>;

const SocketEntrySchema = array(
array(
object({
p: optional(number()),
r: optional(number()),
s: optional(number()),
st: optional(number()),
}),
),
);
export type SocketEntryItem = Output<typeof SocketEntrySchema>;

export const ItemResponseSchema = object({
helpers: object(
{
Expand All @@ -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()),
Expand Down