2023-12-03 19:45:43 -06:00
|
|
|
import { produce } from 'immer';
|
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-01-07 13:13:27 -06:00
|
|
|
import {
|
2024-01-28 19:06:38 -06:00
|
|
|
EngineDefinition,
|
2024-01-07 13:13:27 -06:00
|
|
|
GunDefinition,
|
2024-01-10 14:25:48 -06:00
|
|
|
ShellDefinition,
|
2024-01-07 13:13:27 -06:00
|
|
|
TankDefinition,
|
|
|
|
|
Tier,
|
|
|
|
|
TurretDefinition,
|
|
|
|
|
} from '../core/blitzkrieg/tankDefinitions';
|
2023-12-03 19:45:43 -06:00
|
|
|
|
2023-12-04 10:25:54 -06:00
|
|
|
export type TankopediaSortBy = 'tier' | 'name';
|
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-01-15 15:02:04 -06:00
|
|
|
export interface DuelMember {
|
|
|
|
|
tank: TankDefinition;
|
2024-01-28 19:06:38 -06:00
|
|
|
engine: EngineDefinition;
|
2024-01-15 15:02:04 -06:00
|
|
|
turret: TurretDefinition;
|
|
|
|
|
gun: GunDefinition;
|
|
|
|
|
shell: ShellDefinition;
|
|
|
|
|
}
|
2024-01-21 10:34:52 -06:00
|
|
|
interface TankopediaPersistent {
|
2024-01-22 16:54:07 -06:00
|
|
|
model: {
|
|
|
|
|
equipment: {
|
|
|
|
|
enhancedArmor: boolean;
|
|
|
|
|
calibratedShells: boolean;
|
|
|
|
|
};
|
|
|
|
|
visual: {
|
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-01-21 10:34:52 -06:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 12:20:34 -06:00
|
|
|
export type EquipmentMatrix = (-1 | 0 | 1)[][];
|
2024-01-21 22:11:01 -06:00
|
|
|
|
2024-01-21 10:34:52 -06:00
|
|
|
interface TankopediaTemporary {
|
2024-01-04 13:06:40 -06:00
|
|
|
model: {
|
2024-01-21 22:11:01 -06:00
|
|
|
pose: {
|
2024-01-13 18:24:04 -06:00
|
|
|
yaw: number;
|
|
|
|
|
pitch: number;
|
2024-01-13 16:48:20 -06:00
|
|
|
};
|
2024-01-04 13:06:40 -06:00
|
|
|
};
|
2024-01-21 22:11:01 -06:00
|
|
|
equipmentMatrix: EquipmentMatrix;
|
2024-01-06 18:17:04 -06:00
|
|
|
mode: TankopediaMode;
|
2024-01-25 11:50:43 -06:00
|
|
|
consumables: number[];
|
2024-01-25 13:10:20 -06:00
|
|
|
provisions: number[];
|
2024-01-25 12:45:13 -06:00
|
|
|
camouflage: boolean;
|
2024-02-02 16:08:41 -06:00
|
|
|
shot?: Shot;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-02 16:59:59 -06:00
|
|
|
export type 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-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-01-21 10:34:52 -06:00
|
|
|
export const useTankopediaPersistent = create<TankopediaPersistent>()(
|
|
|
|
|
persist(
|
|
|
|
|
subscribeWithSelector<TankopediaPersistent>(() => ({
|
2024-01-22 16:54:07 -06:00
|
|
|
model: {
|
|
|
|
|
equipment: {
|
|
|
|
|
enhancedArmor: false,
|
|
|
|
|
calibratedShells: false,
|
|
|
|
|
},
|
|
|
|
|
visual: {
|
2024-02-06 15:35:48 -06:00
|
|
|
environment: 'warehouse',
|
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: {
|
|
|
|
|
by: 'tier',
|
|
|
|
|
direction: 'descending',
|
|
|
|
|
},
|
|
|
|
|
filters: {
|
|
|
|
|
tiers: [],
|
|
|
|
|
types: [],
|
|
|
|
|
treeTypes: [],
|
|
|
|
|
nations: [],
|
|
|
|
|
test: 'include',
|
|
|
|
|
page: 0,
|
|
|
|
|
},
|
|
|
|
|
})),
|
|
|
|
|
{ name: 'tankopedia' },
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const useTankopediaTemporary = create<TankopediaTemporary>()(
|
|
|
|
|
subscribeWithSelector<TankopediaTemporary>(() => ({
|
2024-01-13 13:44:27 -06:00
|
|
|
model: {
|
2024-01-21 22:11:01 -06:00
|
|
|
pose: {
|
2024-01-13 18:24:04 -06:00
|
|
|
yaw: 0,
|
|
|
|
|
pitch: 0,
|
2024-01-13 16:48:20 -06:00
|
|
|
},
|
2024-01-13 13:44:27 -06:00
|
|
|
},
|
2024-01-16 17:47:41 -06:00
|
|
|
equipmentMatrix: [
|
2024-01-25 12:20:34 -06:00
|
|
|
[0, 0, 0],
|
|
|
|
|
[0, 0, 0],
|
|
|
|
|
[0, 0, 0],
|
2024-01-16 17:47:41 -06:00
|
|
|
],
|
2024-01-13 13:44:27 -06:00
|
|
|
mode: 'model',
|
2024-01-25 11:50:43 -06:00
|
|
|
consumables: [],
|
2024-01-25 13:10:20 -06:00
|
|
|
provisions: [],
|
2024-01-25 12:45:13 -06:00
|
|
|
camouflage: false,
|
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
|
|
|
}
|