2024-09-17 21:44:35 -05:00
|
|
|
import { TankClass, Tier, TreeType } from '@blitzkit/core';
|
|
|
|
|
import lodash from 'lodash-es';
|
|
|
|
|
import { create } from 'zustand';
|
|
|
|
|
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
|
|
|
|
import { ENVIRONMENTS } from '../../app/tools/tankopedia/[id]/components/Lighting';
|
|
|
|
|
import { createContextualSafeStore } from '../../core/zustand/createContextualSafeStore';
|
2024-07-28 13:32:52 -05:00
|
|
|
import { SORT_NAMES, TankopediaDisplay } from './constants';
|
2024-07-09 14:43:33 -05:00
|
|
|
|
|
|
|
|
export type TankopediaSortBy = keyof typeof SORT_NAMES;
|
|
|
|
|
export type TankopediaSortDirection = 'ascending' | 'descending';
|
|
|
|
|
export type TankopediaTestTankDisplay = 'include' | 'exclude' | 'only';
|
|
|
|
|
export interface TankopediaPersistent {
|
|
|
|
|
model: {
|
|
|
|
|
visual: {
|
|
|
|
|
wireframe: boolean;
|
|
|
|
|
opaque: boolean;
|
2024-07-31 14:26:03 -05:00
|
|
|
environment: (typeof ENVIRONMENTS)[number];
|
2024-07-09 14:43:33 -05:00
|
|
|
showGrid: boolean;
|
|
|
|
|
greenPenetration: boolean;
|
|
|
|
|
showEnvironment: boolean;
|
|
|
|
|
showSpacedArmor: boolean;
|
2024-07-29 14:08:52 -05:00
|
|
|
showExternalModules: boolean;
|
2024-07-29 20:46:57 -05:00
|
|
|
showPrimaryArmor: boolean;
|
2024-07-09 14:43:33 -05:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
sort: {
|
|
|
|
|
by: TankopediaSortBy;
|
|
|
|
|
direction: TankopediaSortDirection;
|
|
|
|
|
};
|
|
|
|
|
filters: {
|
|
|
|
|
tiers: Tier[];
|
|
|
|
|
types: TankClass[];
|
|
|
|
|
treeTypes: TreeType[];
|
|
|
|
|
nations: string[];
|
|
|
|
|
test: TankopediaTestTankDisplay;
|
|
|
|
|
page: number;
|
|
|
|
|
};
|
2024-07-28 13:32:52 -05:00
|
|
|
display: TankopediaDisplay;
|
2024-07-09 14:43:33 -05:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 21:44:35 -05:00
|
|
|
export const { Provider, use, useMutation, useStore } =
|
|
|
|
|
createContextualSafeStore(() =>
|
|
|
|
|
create<TankopediaPersistent>()(
|
|
|
|
|
persist(
|
|
|
|
|
subscribeWithSelector<TankopediaPersistent>(() => ({
|
|
|
|
|
model: {
|
|
|
|
|
visual: {
|
|
|
|
|
showSpacedArmor: true,
|
|
|
|
|
showExternalModules: true,
|
|
|
|
|
showPrimaryArmor: true,
|
|
|
|
|
wireframe: false,
|
|
|
|
|
opaque: false,
|
|
|
|
|
environment: ENVIRONMENTS[0],
|
|
|
|
|
showGrid: true,
|
|
|
|
|
greenPenetration: false,
|
|
|
|
|
showEnvironment: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
sort: {
|
|
|
|
|
by: 'meta.none',
|
|
|
|
|
direction: 'descending',
|
|
|
|
|
},
|
|
|
|
|
filters: {
|
|
|
|
|
tiers: [],
|
|
|
|
|
types: [],
|
|
|
|
|
treeTypes: [],
|
|
|
|
|
nations: [],
|
|
|
|
|
test: 'include',
|
|
|
|
|
page: 0,
|
|
|
|
|
},
|
|
|
|
|
display: TankopediaDisplay.Model,
|
|
|
|
|
})),
|
|
|
|
|
{ name: 'tankopedia', merge: (a, b) => lodash.merge(b, a) },
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|