feat: sort

This commit is contained in:
tresabhi committed 2024-11-25 14:11:53 -06:00
1 parent 62d4ec07f0
commit bae1e944b7
5 files changed
+50 -32

No files matched your search

+1
View File
@@ -43,5 +43,6 @@ export * from './uniqueGuns';
export * from './unwrapBlitzkitResponse';
export * from './votes';
// export * from './withCORSProxy';
export * from './metaSortTank';
export * from './romanize';
export * from './youtubers';
@@ -0,0 +1,28 @@
import { TANK_CLASSES } from '../blitz/constants';
import { GameDefinitions, TankDefinition, TankType } from '../protos';
const treeTypeOrder = [
TankType.RESEARCHABLE,
TankType.PREMIUM,
TankType.COLLECTOR,
];
export function metaSortTank(
tanks: TankDefinition[],
gameDefinitions: GameDefinitions,
) {
return tanks
.sort((a, b) => b.tier - a.tier)
.sort(
(a, b) => treeTypeOrder.indexOf(b.type) - treeTypeOrder.indexOf(a.type),
)
.sort(
(a, b) => TANK_CLASSES.indexOf(b.class) - TANK_CLASSES.indexOf(a.class),
)
.sort(
(a, b) =>
gameDefinitions.nations.indexOf(b.nation) -
gameDefinitions.nations.indexOf(a.nation),
)
.sort((a, b) => a.tier - b.tier);
}