Files
blitzkit/src/core/blitzkrieg/tankDefinitions.ts
T

154 lines
4.0 KiB
TypeScript
Raw Normal View History

2023-08-10 01:46:39 +00:00
import { deburr } from 'lodash';
2024-01-10 17:36:11 -06:00
import { Vector2Tuple } from 'three';
2023-12-14 22:19:01 -06:00
import { TankType, TreeTypeString } from '../../components/Tanks';
import { asset } from './asset';
2023-08-10 01:03:53 +00:00
2023-12-14 22:19:01 -06:00
export type ShellType = 'ap' | 'ap_cr' | 'hc' | 'he';
2023-12-17 20:47:30 -06:00
2024-01-07 19:41:37 -06:00
export const SHELL_NAMES: Record<ShellType, string> = {
ap: 'AP',
ap_cr: 'APCR',
hc: 'HEAT',
he: 'HE',
};
2023-12-17 20:47:30 -06:00
export type TankDefinitions = Record<number, TankDefinition>;
export interface TankDefinition {
id: number;
nation: string;
name: string;
tree_type: TreeTypeString;
tier: Tier;
type: TankType;
testing?: boolean;
turrets: TurretDefinition[];
price: TankDefinitionPrice;
camouflage: { still: number; moving: number; firing: number };
2024-01-16 16:58:00 -06:00
equipment: string;
2023-12-17 20:47:30 -06:00
}
export type TankDefinitionPrice =
| { type: 'credits'; value: number }
| { type: 'gold'; value: number };
export interface TurretDefinition {
id: number;
name: string;
tier: Tier;
guns: GunDefinition[];
}
export type GunDefinition = GunDefinitionBase &
(GunDefinitionRegular | GunDefinitionAutoLoader | GunDefinitionAutoReloader);
2024-01-02 20:17:10 -06:00
interface GunDefinitionBase {
2023-12-17 20:47:30 -06:00
id: number;
name: string;
tier: Tier;
shells: ShellDefinition[];
}
interface GunDefinitionRegular {
type: 'regular';
reload: number;
}
interface GunDefinitionAutoLoader {
type: 'auto_loader';
reload: number;
interClip: number;
count: number;
}
interface GunDefinitionAutoReloader {
type: 'auto_reloader';
reload: number[];
interClip: number;
count: number;
}
2024-01-20 13:43:03 -06:00
export type ShellDefinition = {
2023-12-14 22:19:01 -06:00
id: number;
name: string;
speed: number;
damage: { armor: number; devices: number };
caliber: number;
icon: string;
2024-01-10 17:36:11 -06:00
penetration: number | Vector2Tuple;
2024-01-12 13:57:32 -06:00
type: ShellType;
normalization?: number;
ricochet?: number;
2024-01-20 13:43:03 -06:00
explosionRadius?: number;
};
2023-11-29 12:17:21 -06:00
2023-12-05 17:36:18 -06:00
export const tankDefinitions = fetch(asset('definitions/tanks.json'), {
2023-12-06 10:34:43 -06:00
cache: 'no-cache',
2023-12-14 22:19:01 -06:00
}).then(async (response) => response.json() as Promise<TankDefinitions>);
2023-12-05 17:36:18 -06:00
2023-12-14 22:19:01 -06:00
const entries = new Promise<TankDefinition[]>(async (resolve) => {
2023-12-05 17:36:18 -06:00
resolve(Object.entries(await tankDefinitions).map(([, entry]) => entry));
});
2023-12-14 22:19:01 -06:00
export const tanksDefinitionsArray = new Promise<TankDefinition[]>(
2023-11-29 12:17:21 -06:00
async (resolve) => {
resolve((await entries).map((entry) => entry));
},
);
2023-11-30 12:21:20 -06:00
export const tankNames = new Promise<string[]>(async (resolve) => {
resolve((await entries).map(({ name }) => name));
});
2023-11-30 12:21:20 -06:00
export const tankNamesDiacritics = tankNames.then((tankNames) =>
2023-08-10 01:46:39 +00:00
Promise.all(
tankNames.map(async (tankName, index) => {
2023-12-05 17:36:18 -06:00
const { id } = (await tanksDefinitionsArray)[index];
2023-08-11 17:57:44 +00:00
const name = tankName ?? `Unknown Tank ${id}`;
2023-08-10 01:46:39 +00:00
const diacriticless = deburr(name);
return {
original: name,
diacriticless,
combined: `${name}${diacriticless}`,
2023-08-11 17:57:44 +00:00
id,
2023-08-10 01:46:39 +00:00
};
}),
),
);
2023-05-30 18:42:34 +00:00
2023-12-01 12:36:31 -06:00
export const TANK_ICONS: Record<TankType, string> = {
2023-12-05 19:14:53 -06:00
tank_destroyer: 'https://i.imgur.com/BIHSEH0.png',
light: 'https://i.imgur.com/CSNha5V.png',
medium: 'https://i.imgur.com/wvf3ltm.png',
heavy: 'https://i.imgur.com/ECeqlZa.png',
2023-06-05 18:47:00 +00:00
};
2023-12-01 12:36:31 -06:00
export const TANK_ICONS_PREMIUM: Record<TankType, string> = {
2023-12-05 19:14:53 -06:00
tank_destroyer: 'https://i.imgur.com/TCu3EdR.png',
light: 'https://i.imgur.com/zdkpTRb.png',
medium: 'https://i.imgur.com/3z7eHX6.png',
heavy: 'https://i.imgur.com/P3vbmyA.png',
2023-07-09 00:47:03 +00:00
};
2023-12-01 12:36:31 -06:00
export const TANK_ICONS_COLLECTOR: Record<TankType, string> = {
2023-12-05 19:14:53 -06:00
tank_destroyer: 'https://i.imgur.com/WTjeirB.png',
light: 'https://i.imgur.com/EwhtKkU.png',
medium: 'https://i.imgur.com/u8YDMBh.png',
heavy: 'https://i.imgur.com/8xRf3nc.png',
2023-07-10 18:16:33 +00:00
};
2023-12-04 12:35:27 -06:00
export const TIERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const;
2023-06-19 18:08:34 +00:00
2023-12-04 12:35:27 -06:00
export type Tier = (typeof TIERS)[number];
2023-12-04 11:47:33 -06:00
2023-06-19 18:08:34 +00:00
export const TIER_ROMAN_NUMERALS: Record<Tier, string> = {
2023-06-05 18:47:00 +00:00
1: 'I',
2: 'II',
3: 'III',
4: 'IV',
5: 'V',
6: 'VI',
7: 'VII',
8: 'VIII',
9: 'IX',
10: 'X',
2023-05-30 18:42:34 +00:00
};
2023-12-04 19:10:26 -06:00
2023-12-05 17:36:18 -06:00
export const NATIONS = tanksDefinitionsArray.then((tanks) => {
2023-12-04 19:10:26 -06:00
const nationsObject: Record<string, true> = {};
tanks.forEach(({ nation }) => {
nationsObject[nation] = true;
});
return Object.keys(nationsObject);
});