2024-02-22 16:41:42 -06:00
|
|
|
import {
|
2024-09-14 18:32:36 -05:00
|
|
|
type EngineDefinition,
|
|
|
|
|
type GunDefinition,
|
|
|
|
|
type ProvisionDefinitions,
|
|
|
|
|
type ShellDefinition,
|
|
|
|
|
type TankDefinition,
|
|
|
|
|
type TrackDefinition,
|
|
|
|
|
type TurretDefinition,
|
2024-09-06 23:17:53 -05:00
|
|
|
} from '@blitzkit/core';
|
|
|
|
|
import { create } from 'zustand';
|
|
|
|
|
import { subscribeWithSelector } from 'zustand/middleware';
|
|
|
|
|
import { tankToDuelMember } from '../../core/blitzkit/tankToDuelMember';
|
2024-09-14 18:32:36 -05:00
|
|
|
import { createContextualSafeStore } from '../../core/zustand/createContextualSafeStore';
|
2024-02-22 16:41:42 -06:00
|
|
|
|
|
|
|
|
type EquipmentMatrixItem = -1 | 0 | 1;
|
|
|
|
|
type EquipmentMatrixRow = [
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
EquipmentMatrixItem,
|
|
|
|
|
];
|
|
|
|
|
export type EquipmentMatrix = [
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
EquipmentMatrixRow,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export interface DuelMember {
|
|
|
|
|
tank: TankDefinition;
|
|
|
|
|
engine: EngineDefinition;
|
|
|
|
|
turret: TurretDefinition;
|
|
|
|
|
gun: GunDefinition;
|
|
|
|
|
shell: ShellDefinition;
|
|
|
|
|
track: TrackDefinition;
|
2024-04-04 13:51:07 -05:00
|
|
|
equipmentMatrix: EquipmentMatrix;
|
2024-02-22 16:41:42 -06:00
|
|
|
pitch: number;
|
|
|
|
|
yaw: number;
|
|
|
|
|
consumables: number[];
|
|
|
|
|
crewMastery: number;
|
|
|
|
|
provisions: number[];
|
|
|
|
|
camouflage: boolean;
|
|
|
|
|
cooldownBooster: number;
|
|
|
|
|
}
|
2024-01-22 18:04:13 -06:00
|
|
|
|
|
|
|
|
export interface Duel {
|
2024-07-09 20:35:36 -05:00
|
|
|
protagonist: DuelMember;
|
|
|
|
|
antagonist: DuelMember;
|
2024-01-22 18:04:13 -06:00
|
|
|
}
|
|
|
|
|
|
2024-09-14 18:32:36 -05:00
|
|
|
export const { Provider, use, useMutation, useStore } =
|
|
|
|
|
createContextualSafeStore(
|
|
|
|
|
({
|
|
|
|
|
tank,
|
|
|
|
|
provisionDefinitions,
|
|
|
|
|
}: {
|
|
|
|
|
tank: TankDefinition;
|
|
|
|
|
provisionDefinitions: ProvisionDefinitions;
|
|
|
|
|
}) => {
|
|
|
|
|
const protagonist = tankToDuelMember(tank, provisionDefinitions);
|
2024-07-09 20:35:36 -05:00
|
|
|
|
2024-09-14 18:32:36 -05:00
|
|
|
return create<Duel>()(
|
|
|
|
|
subscribeWithSelector<Duel>(() => ({
|
|
|
|
|
protagonist,
|
|
|
|
|
antagonist: protagonist,
|
|
|
|
|
})),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|