mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: integrated tank definitions
This commit is contained in:
1 parent
adb0bb2e69
commit
2aefe3f9e3
26 files changed
+475
-273
No files matched your search
@@ -0,0 +1,138 @@
|
||||
import { deburr } from 'lodash';
|
||||
import { TankType, TreeTypeString } from '../../components/Tanks';
|
||||
import { asset } from './asset';
|
||||
|
||||
export type ShellType = 'ap' | 'ap_cr' | 'hc' | 'he';
|
||||
export interface ShellDefinition {
|
||||
id: number;
|
||||
name: string;
|
||||
speed: number;
|
||||
damage: { armor: number; devices: number };
|
||||
caliber: number;
|
||||
normalization: number;
|
||||
ricochet: number;
|
||||
type: ShellType;
|
||||
icon: string;
|
||||
}
|
||||
export type GunDefinition = {
|
||||
id: number;
|
||||
name: string;
|
||||
tier: Tier;
|
||||
pitch: [number, number];
|
||||
shells: ShellDefinition[];
|
||||
} & (
|
||||
| {
|
||||
type: 'regular';
|
||||
reload: number;
|
||||
}
|
||||
| {
|
||||
type: 'auto_loader';
|
||||
reload: number;
|
||||
interClip: number;
|
||||
count: number;
|
||||
}
|
||||
| {
|
||||
type: 'auto_reloader';
|
||||
reload: number[];
|
||||
interClip: number;
|
||||
count: number;
|
||||
}
|
||||
);
|
||||
export interface TurretDefinition {
|
||||
id: number;
|
||||
name: string;
|
||||
tier: Tier;
|
||||
yaw: [number, number];
|
||||
guns: GunDefinition[];
|
||||
}
|
||||
export interface TankDefinition {
|
||||
id: number;
|
||||
nation: string;
|
||||
name: string;
|
||||
tree_type: TreeTypeString;
|
||||
tier: Tier;
|
||||
type: TankType;
|
||||
testing?: boolean;
|
||||
turrets: TurretDefinition[];
|
||||
}
|
||||
export type TankDefinitions = Record<number, TankDefinition>;
|
||||
|
||||
export const tankDefinitions = fetch(asset('definitions/tanks.json'), {
|
||||
cache: 'no-cache',
|
||||
}).then(async (response) => response.json() as Promise<TankDefinitions>);
|
||||
|
||||
const entries = new Promise<TankDefinition[]>(async (resolve) => {
|
||||
resolve(Object.entries(await tankDefinitions).map(([, entry]) => entry));
|
||||
});
|
||||
export const tanksDefinitionsArray = new Promise<TankDefinition[]>(
|
||||
async (resolve) => {
|
||||
resolve((await entries).map((entry) => entry));
|
||||
},
|
||||
);
|
||||
export const tankNames = new Promise<string[]>(async (resolve) => {
|
||||
resolve((await entries).map(({ name }) => name));
|
||||
});
|
||||
export const tankNamesDiacritics = tankNames.then((tankNames) =>
|
||||
Promise.all(
|
||||
tankNames.map(async (tankName, index) => {
|
||||
const { id } = (await tanksDefinitionsArray)[index];
|
||||
const name = tankName ?? `Unknown Tank ${id}`;
|
||||
const diacriticless = deburr(name);
|
||||
|
||||
return {
|
||||
original: name,
|
||||
diacriticless,
|
||||
combined: `${name}${diacriticless}`,
|
||||
id,
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
export const TANK_ICONS: Record<TankType, string> = {
|
||||
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',
|
||||
};
|
||||
|
||||
export const TANK_ICONS_PREMIUM: Record<TankType, string> = {
|
||||
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',
|
||||
};
|
||||
|
||||
export const TANK_ICONS_COLLECTOR: Record<TankType, string> = {
|
||||
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',
|
||||
};
|
||||
|
||||
export const TIERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as const;
|
||||
|
||||
export type Tier = (typeof TIERS)[number];
|
||||
|
||||
export const TIER_ROMAN_NUMERALS: Record<Tier, string> = {
|
||||
1: 'I',
|
||||
2: 'II',
|
||||
3: 'III',
|
||||
4: 'IV',
|
||||
5: 'V',
|
||||
6: 'VI',
|
||||
7: 'VII',
|
||||
8: 'VIII',
|
||||
9: 'IX',
|
||||
10: 'X',
|
||||
};
|
||||
|
||||
export const NATIONS = tanksDefinitionsArray.then((tanks) => {
|
||||
const nationsObject: Record<string, true> = {};
|
||||
|
||||
tanks.forEach(({ nation }) => {
|
||||
nationsObject[nation] = true;
|
||||
});
|
||||
|
||||
return Object.keys(nationsObject);
|
||||
});
|
||||
Reference in new issue
Block a user