2023-12-03 19:45:43 -06:00
|
|
|
import { produce } from 'immer';
|
2024-02-07 15:16:48 -06:00
|
|
|
import { merge } from 'lodash';
|
2024-02-02 16:08:41 -06:00
|
|
|
import { Vector3Tuple } from 'three';
|
2023-12-03 19:45:43 -06:00
|
|
|
import { create } from 'zustand';
|
2024-01-21 10:34:52 -06:00
|
|
|
import { persist, subscribeWithSelector } from 'zustand/middleware';
|
2024-02-06 15:35:48 -06:00
|
|
|
import { ENVIRONMENTS } from '../app/tools/tankopedia/[id]/components/Lighting';
|
2024-01-27 17:36:29 -06:00
|
|
|
import { TankType, TreeType } from '../components/Tanks';
|
2024-02-22 16:41:42 -06:00
|
|
|
import { Tier } from '../core/blitzkrieg/tankDefinitions';
|
2023-12-03 19:45:43 -06:00
|
|
|
|
2024-02-10 00:04:43 -06:00
|
|
|
export type TankopediaSortBy = keyof typeof SORT_NAMES;
|
2023-12-03 19:45:43 -06:00
|
|
|
export type TankopediaSortDirection = 'ascending' | 'descending';
|
2023-12-06 10:34:43 -06:00
|
|
|
export type TankopediaTestTankDisplay = 'include' | 'exclude' | 'only';
|
2024-01-06 18:17:04 -06:00
|
|
|
export type TankopediaMode = 'model' | 'armor';
|
2024-02-22 16:41:42 -06:00
|
|
|
|
2024-02-27 17:39:01 -06:00
|
|
|
export interface TankopediaPersistent {
|
2024-01-22 16:54:07 -06:00
|
|
|
model: {
|
|
|
|
|
visual: {
|
2024-02-18 16:56:52 -06:00
|
|
|
wireframe: boolean;
|
2024-02-27 17:44:18 -06:00
|
|
|
opaque: boolean;
|
2024-02-06 15:35:48 -06:00
|
|
|
environment: (typeof ENVIRONMENTS)[number];
|
2024-01-22 16:54:07 -06:00
|
|
|
controlsEnabled: boolean;
|
|
|
|
|
showGrid: boolean;
|
|
|
|
|
greenPenetration: boolean;
|
2024-02-01 12:28:56 -06:00
|
|
|
showEnvironment: boolean;
|
2024-01-22 16:54:07 -06:00
|
|
|
};
|
|
|
|
|
};
|
2023-12-04 11:47:33 -06:00
|
|
|
sort: {
|
|
|
|
|
by: TankopediaSortBy;
|
|
|
|
|
direction: TankopediaSortDirection;
|
|
|
|
|
};
|
|
|
|
|
filters: {
|
|
|
|
|
tiers: Tier[];
|
2023-12-04 12:35:27 -06:00
|
|
|
types: TankType[];
|
2024-01-27 17:36:29 -06:00
|
|
|
treeTypes: TreeType[];
|
2023-12-04 19:10:26 -06:00
|
|
|
nations: string[];
|
2023-12-06 10:34:43 -06:00
|
|
|
test: TankopediaTestTankDisplay;
|
2024-01-21 10:34:52 -06:00
|
|
|
page: number;
|
2023-12-04 11:47:33 -06:00
|
|
|
};
|
2024-02-22 16:41:42 -06:00
|
|
|
mode: TankopediaMode;
|
2024-01-21 10:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface TankopediaTemporary {
|
2024-02-02 16:08:41 -06:00
|
|
|
shot?: Shot;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 17:57:20 -06:00
|
|
|
export interface Shot {
|
2024-02-02 16:08:41 -06:00
|
|
|
point: Vector3Tuple;
|
|
|
|
|
surfaceNormal: Vector3Tuple;
|
|
|
|
|
shellNormal: Vector3Tuple;
|
|
|
|
|
thicknesses: ArmorPiercingLayer[];
|
|
|
|
|
type: 'ricochet' | 'penetration' | 'block';
|
2024-02-02 16:59:59 -06:00
|
|
|
angle: number;
|
2024-02-06 17:57:20 -06:00
|
|
|
ricochet?: {
|
|
|
|
|
distance: number;
|
|
|
|
|
point: Vector3Tuple;
|
|
|
|
|
penetration: boolean;
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-02-02 16:08:41 -06:00
|
|
|
|
2024-02-03 12:16:33 -06:00
|
|
|
export type ArmorPiercingLayer =
|
|
|
|
|
| {
|
|
|
|
|
distance: number;
|
|
|
|
|
nominal: number;
|
|
|
|
|
angled: number;
|
|
|
|
|
ricochet: boolean;
|
|
|
|
|
type: 'core' | 'spaced' | 'external';
|
|
|
|
|
}
|
|
|
|
|
| {
|
|
|
|
|
type: 'gap';
|
|
|
|
|
gap: number;
|
|
|
|
|
};
|
2023-12-03 19:45:43 -06:00
|
|
|
|
2024-02-10 00:04:43 -06:00
|
|
|
export const SORT_NAMES = {
|
|
|
|
|
'meta.tier': 'tier',
|
|
|
|
|
'meta.name': 'name',
|
|
|
|
|
'survivability.health': 'health',
|
|
|
|
|
'survivability.viewRange': 'view range',
|
|
|
|
|
'survivability.camouflageStill': 'camouflage still',
|
|
|
|
|
'survivability.camouflageMoving': 'camouflage moving',
|
|
|
|
|
'survivability.camouflageShooting': 'camouflage shooting',
|
|
|
|
|
'survivability.size': 'size',
|
|
|
|
|
'fire.dpm': 'DPM',
|
|
|
|
|
'fire.reload': 'reload',
|
|
|
|
|
'fire.caliber': 'caliber',
|
|
|
|
|
'fire.standardPenetration': 'standard penetration',
|
|
|
|
|
'fire.premiumPenetration': 'premium penetration',
|
|
|
|
|
'fire.damage': 'damage',
|
|
|
|
|
'fire.shellVelocity': 'shell velocity',
|
|
|
|
|
'fire.aimTime': 'aim time',
|
|
|
|
|
'fire.dispersionStill': 'dispersion still',
|
|
|
|
|
'fire.dispersionMoving': 'dispersion moving',
|
|
|
|
|
'fire.gunDepression': 'gun depression',
|
|
|
|
|
'fire.gunElevation': 'gun elevation',
|
|
|
|
|
'maneuverability.forwardsSpeed': 'forwards speed',
|
|
|
|
|
'maneuverability.backwardsSpeed': 'backwards speed',
|
|
|
|
|
'maneuverability.power': 'power',
|
|
|
|
|
'maneuverability.powerToWeight': 'power to weight',
|
|
|
|
|
'maneuverability.weight': 'weight',
|
|
|
|
|
'maneuverability.traverseSpeed': 'traverse speed',
|
|
|
|
|
} as const;
|
|
|
|
|
|
2024-01-21 10:34:52 -06:00
|
|
|
export const useTankopediaPersistent = create<TankopediaPersistent>()(
|
|
|
|
|
persist(
|
|
|
|
|
subscribeWithSelector<TankopediaPersistent>(() => ({
|
2024-01-22 16:54:07 -06:00
|
|
|
model: {
|
|
|
|
|
visual: {
|
2024-02-18 16:56:52 -06:00
|
|
|
wireframe: false,
|
2024-02-27 17:44:18 -06:00
|
|
|
opaque: false,
|
2024-02-17 10:52:21 -06:00
|
|
|
environment: ENVIRONMENTS[0],
|
2024-01-22 16:54:07 -06:00
|
|
|
controlsEnabled: true,
|
|
|
|
|
showGrid: true,
|
|
|
|
|
greenPenetration: false,
|
2024-02-01 12:28:56 -06:00
|
|
|
showEnvironment: false,
|
2024-01-22 16:54:07 -06:00
|
|
|
},
|
|
|
|
|
},
|
2024-01-21 10:34:52 -06:00
|
|
|
sort: {
|
2024-02-09 16:01:06 -06:00
|
|
|
by: 'meta.tier',
|
2024-01-21 10:34:52 -06:00
|
|
|
direction: 'descending',
|
|
|
|
|
},
|
|
|
|
|
filters: {
|
|
|
|
|
tiers: [],
|
|
|
|
|
types: [],
|
|
|
|
|
treeTypes: [],
|
|
|
|
|
nations: [],
|
|
|
|
|
test: 'include',
|
|
|
|
|
page: 0,
|
|
|
|
|
},
|
2024-02-28 14:59:19 -06:00
|
|
|
mode: 'model',
|
2024-01-21 10:34:52 -06:00
|
|
|
})),
|
2024-02-27 17:56:01 -06:00
|
|
|
{ name: 'tankopedia', merge: (a, b) => merge(b, a) },
|
2024-01-21 10:34:52 -06:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const useTankopediaTemporary = create<TankopediaTemporary>()(
|
2024-02-22 16:41:42 -06:00
|
|
|
subscribeWithSelector<TankopediaTemporary>(() => ({})),
|
2024-01-13 13:44:27 -06:00
|
|
|
);
|
2023-12-03 19:45:43 -06:00
|
|
|
|
2024-01-21 10:34:52 -06:00
|
|
|
export default function mutateTankopediaPersistent(
|
|
|
|
|
recipe: (draft: TankopediaPersistent) => void,
|
|
|
|
|
) {
|
|
|
|
|
useTankopediaPersistent.setState(produce(recipe));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function mutateTankopediaTemporary(
|
|
|
|
|
recipe: (draft: TankopediaTemporary) => void,
|
|
|
|
|
) {
|
|
|
|
|
useTankopediaTemporary.setState(produce(recipe));
|
2023-12-03 19:45:43 -06:00
|
|
|
}
|