2024-09-06 22:05:06 -05:00
|
|
|
import {
|
|
|
|
|
TANK_CLASSES,
|
2024-10-02 10:21:16 -05:00
|
|
|
fetchGameDefinitions,
|
|
|
|
|
fetchModelDefinitions,
|
|
|
|
|
fetchTankDefinitions,
|
|
|
|
|
fetchTankNames,
|
2024-09-17 21:44:36 -05:00
|
|
|
normalizeBoundingBox,
|
|
|
|
|
resolveDpm,
|
|
|
|
|
unionBoundingBox,
|
2024-09-17 22:13:35 -05:00
|
|
|
type TankDefinition,
|
2024-09-06 22:05:06 -05:00
|
|
|
} from '@blitzkit/core';
|
2024-09-17 22:13:35 -05:00
|
|
|
import { useStore } from '@nanostores/react';
|
2024-10-13 00:26:38 -05:00
|
|
|
import { Callout, Flex, Link, Text, type FlexProps } from '@radix-ui/themes';
|
2024-09-17 22:13:35 -05:00
|
|
|
import fuzzysort from 'fuzzysort';
|
2024-09-14 19:43:14 -05:00
|
|
|
import { times } from 'lodash-es';
|
2024-09-17 22:13:35 -05:00
|
|
|
import { Fragment, memo, useEffect, useMemo, useState } from 'react';
|
|
|
|
|
import { filterTank } from '../../core/blitzkit/filterTank';
|
|
|
|
|
import { resolveReload } from '../../core/blitzkit/resolveReload';
|
|
|
|
|
import { useAdExempt } from '../../hooks/useAdExempt';
|
|
|
|
|
import { $tankFilters } from '../../stores/tankFilters';
|
2024-07-09 14:43:33 -05:00
|
|
|
import {
|
|
|
|
|
SORT_NAMES,
|
|
|
|
|
SORT_UNITS,
|
2024-09-17 22:13:35 -05:00
|
|
|
} from '../../stores/tankopediaPersistent/constants';
|
|
|
|
|
import { $tankopediaSort } from '../../stores/tankopediaSort';
|
2024-10-10 16:25:05 -05:00
|
|
|
import { Ad } from '../Ad';
|
2024-09-17 22:13:35 -05:00
|
|
|
import { ExperimentIcon } from '../ExperimentIcon';
|
|
|
|
|
import { FilterControl } from './components/FilterControl';
|
|
|
|
|
import { NoResults } from './components/NoResults';
|
|
|
|
|
import { SearchBar } from './components/SearchBar';
|
|
|
|
|
import { SkeletonTankCard } from './components/SkeletonTankCard';
|
|
|
|
|
import { TankCard } from './components/TankCard';
|
|
|
|
|
import { TankCardWrapper } from './components/TankCardWrapper';
|
2024-06-18 14:28:20 -05:00
|
|
|
import { treeTypeOrder } from './constants';
|
2024-01-21 11:06:40 -06:00
|
|
|
|
2024-06-25 20:05:41 -05:00
|
|
|
type TankSearchProps = Omit<FlexProps, 'onSelect'> & {
|
2024-01-21 11:06:40 -06:00
|
|
|
compact?: boolean;
|
|
|
|
|
onSelect?: (tank: TankDefinition) => void;
|
2024-06-25 19:24:33 -05:00
|
|
|
onSelectAll?: (tanks: TankDefinition[]) => void;
|
2024-06-25 19:58:29 -05:00
|
|
|
};
|
2024-01-21 11:06:40 -06:00
|
|
|
|
2024-07-09 21:16:20 -05:00
|
|
|
const PREVIEW_COUNT = 25;
|
|
|
|
|
const DEFAULT_LOADED_CARDS = 75;
|
|
|
|
|
|
2024-10-02 10:21:16 -05:00
|
|
|
const gameDefinitions = await fetchGameDefinitions();
|
|
|
|
|
const modelDefinitions = await fetchModelDefinitions();
|
|
|
|
|
const tankDefinitions = await fetchTankDefinitions();
|
|
|
|
|
const tankNames = await fetchTankNames();
|
2024-09-21 12:16:51 -05:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
export const TankSearch = memo<TankSearchProps>(
|
2024-06-25 19:58:29 -05:00
|
|
|
({ compact, onSelect, onSelectAll, ...props }) => {
|
2024-10-02 10:21:16 -05:00
|
|
|
const awaitedTanksDefinitionsArray = Object.values(tankDefinitions.tanks);
|
2024-06-25 20:01:51 -05:00
|
|
|
const exempt = useAdExempt();
|
2024-09-17 22:13:35 -05:00
|
|
|
const tankFilters = useStore($tankFilters);
|
|
|
|
|
const tankopediaSort = useStore($tankopediaSort);
|
|
|
|
|
|
2024-09-17 22:50:34 -05:00
|
|
|
const tanksFiltered = useMemo(() => {
|
2024-09-17 22:13:35 -05:00
|
|
|
if (tankFilters.search === undefined) {
|
2024-06-25 19:24:33 -05:00
|
|
|
const filtered = awaitedTanksDefinitionsArray.filter((tank) =>
|
2024-09-17 22:13:35 -05:00
|
|
|
filterTank(tankFilters, tank),
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
let sorted: TankDefinition[];
|
2024-01-21 11:06:40 -06:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
switch (tankopediaSort.by) {
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'meta.none':
|
|
|
|
|
sorted = filtered
|
2024-06-25 19:58:29 -05:00
|
|
|
.sort((a, b) => b.tier - a.tier)
|
2024-06-25 19:24:33 -05:00
|
|
|
.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-02 10:21:16 -05:00
|
|
|
treeTypeOrder.indexOf(b.type) - treeTypeOrder.indexOf(a.type),
|
2024-06-25 19:24:33 -05:00
|
|
|
)
|
|
|
|
|
.sort(
|
|
|
|
|
(a, b) =>
|
|
|
|
|
TANK_CLASSES.indexOf(b.class) - TANK_CLASSES.indexOf(a.class),
|
|
|
|
|
)
|
|
|
|
|
.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-02 10:21:16 -05:00
|
|
|
gameDefinitions.nations.indexOf(b.nation) -
|
|
|
|
|
gameDefinitions.nations.indexOf(a.nation),
|
2024-06-29 12:14:34 -05:00
|
|
|
)
|
|
|
|
|
.sort((a, b) => a.tier - b.tier);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.health': {
|
|
|
|
|
sorted = filtered.sort((a, b) => {
|
|
|
|
|
const aHealth = a.health + a.turrets.at(-1)!.health;
|
|
|
|
|
const bHealth = b.health + b.turrets.at(-1)!.health;
|
|
|
|
|
|
|
|
|
|
return aHealth - bHealth;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case 'survivability.viewRange':
|
|
|
|
|
sorted = filtered.sort(
|
2024-06-25 19:17:53 -05:00
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.view_range - b.turrets.at(-1)!.view_range,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.camouflageStill':
|
|
|
|
|
sorted = filtered.sort(
|
2024-10-07 18:45:11 -05:00
|
|
|
(a, b) => a.camouflage_still - b.camouflage_still,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.camouflageMoving':
|
|
|
|
|
sorted = filtered.sort(
|
2024-10-07 18:45:11 -05:00
|
|
|
(a, b) => a.camouflage_moving - b.camouflage_moving,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.camouflageShooting':
|
|
|
|
|
sorted = filtered.sort(
|
2024-06-25 19:17:53 -05:00
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.camouflage_still *
|
|
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
|
|
|
|
.camouflage_loss -
|
|
|
|
|
b.camouflage_still *
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
|
|
|
|
.camouflage_loss,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.volume':
|
|
|
|
|
sorted = filtered.sort((a, b) => {
|
2024-10-02 10:21:16 -05:00
|
|
|
const aTankModelDefinition = modelDefinitions.models[a.id];
|
|
|
|
|
const bTankModelDefinition = modelDefinitions.models[b.id];
|
2024-06-25 19:24:33 -05:00
|
|
|
const aTurretModelDefinition =
|
|
|
|
|
aTankModelDefinition.turrets[a.turrets.at(-1)!.id];
|
|
|
|
|
const bTurretModelDefinition =
|
|
|
|
|
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
|
|
|
|
|
const aSize = normalizeBoundingBox(
|
|
|
|
|
unionBoundingBox(
|
2024-10-07 18:45:11 -05:00
|
|
|
aTankModelDefinition.bounding_box,
|
|
|
|
|
aTurretModelDefinition.bounding_box,
|
2024-06-25 19:24:33 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
const bSize = normalizeBoundingBox(
|
|
|
|
|
unionBoundingBox(
|
2024-10-07 18:45:11 -05:00
|
|
|
bTankModelDefinition.bounding_box,
|
|
|
|
|
bTurretModelDefinition.bounding_box,
|
2024-06-25 19:24:33 -05:00
|
|
|
),
|
|
|
|
|
);
|
2024-10-05 23:20:04 -05:00
|
|
|
const aVolume = aSize.x * aSize.y * aSize.z;
|
|
|
|
|
const bVolume = bSize.x * bSize.y * bSize.z;
|
2024-06-25 19:24:33 -05:00
|
|
|
|
|
|
|
|
return aVolume - bVolume;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'survivability.length':
|
|
|
|
|
sorted = filtered.sort((a, b) => {
|
2024-10-05 15:57:34 -05:00
|
|
|
const aTankModelDefinition = modelDefinitions.models[a.id];
|
|
|
|
|
const bTankModelDefinition = modelDefinitions.models[b.id];
|
2024-06-25 19:24:33 -05:00
|
|
|
const aTurretModelDefinition =
|
|
|
|
|
aTankModelDefinition.turrets[a.turrets.at(-1)!.id];
|
|
|
|
|
const bTurretModelDefinition =
|
|
|
|
|
bTankModelDefinition.turrets[b.turrets.at(-1)!.id];
|
|
|
|
|
const aSize = normalizeBoundingBox(
|
|
|
|
|
unionBoundingBox(
|
2024-10-07 18:45:11 -05:00
|
|
|
aTankModelDefinition.bounding_box,
|
|
|
|
|
aTurretModelDefinition.bounding_box,
|
2024-06-25 19:24:33 -05:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
const bSize = normalizeBoundingBox(
|
|
|
|
|
unionBoundingBox(
|
2024-10-07 18:45:11 -05:00
|
|
|
bTankModelDefinition.bounding_box,
|
|
|
|
|
bTurretModelDefinition.bounding_box,
|
2024-06-25 19:24:33 -05:00
|
|
|
),
|
|
|
|
|
);
|
2024-10-05 23:20:04 -05:00
|
|
|
const aLength = Math.max(aSize.x, aSize.y, aSize.z);
|
|
|
|
|
const bLength = Math.max(bSize.x, bSize.y, bSize.z);
|
2024-06-25 19:24:33 -05:00
|
|
|
|
|
|
|
|
return aLength - bLength;
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'fire.dpm':
|
|
|
|
|
sorted = filtered.sort(
|
2024-06-25 19:17:53 -05:00
|
|
|
(a, b) =>
|
2024-06-25 19:24:33 -05:00
|
|
|
resolveDpm(
|
|
|
|
|
a.turrets.at(-1)!.guns.at(-1)!,
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
|
2024-06-25 19:24:33 -05:00
|
|
|
) -
|
|
|
|
|
resolveDpm(
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!,
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0],
|
2024-06-25 19:24:33 -05:00
|
|
|
),
|
2024-06-25 19:17:53 -05:00
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-29 13:29:43 -05:00
|
|
|
case 'fire.dpmPremium':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
(a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
|
2024-06-29 13:29:43 -05:00
|
|
|
? resolveDpm(
|
|
|
|
|
a.turrets.at(-1)!.guns.at(-1)!,
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
2024-10-05 15:57:34 -05:00
|
|
|
.shells[1],
|
2024-06-29 13:29:43 -05:00
|
|
|
)
|
|
|
|
|
: 0) -
|
2024-10-07 18:45:11 -05:00
|
|
|
(b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
|
2024-06-29 13:29:43 -05:00
|
|
|
? resolveDpm(
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!,
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
2024-10-05 15:57:34 -05:00
|
|
|
.shells[1],
|
2024-06-29 13:29:43 -05:00
|
|
|
)
|
|
|
|
|
: 0),
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.reload':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
|
|
|
|
resolveReload(a.turrets.at(-1)!.guns.at(-1)!) -
|
|
|
|
|
resolveReload(b.turrets.at(-1)!.guns.at(-1)!),
|
2024-06-25 19:17:53 -05:00
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'fire.caliber':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.caliber -
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.caliber,
|
2024-06-25 19:17:53 -05:00
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
2024-04-01 19:12:59 -05:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.standardPenetration':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.penetration.near -
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.penetration.near,
|
2024-06-25 19:17:53 -05:00
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'fire.premiumPenetration':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
(a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
|
2024-10-05 15:57:34 -05:00
|
|
|
?.penetration.near ?? 0) -
|
2024-10-07 18:45:11 -05:00
|
|
|
(b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[1]
|
2024-10-05 15:57:34 -05:00
|
|
|
?.penetration.near ?? 0),
|
2024-06-25 19:17:53 -05:00
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.damage':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
|
|
|
|
.armor_damage -
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
|
|
|
|
.armor_damage,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.shellVelocity':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.velocity -
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.shells[0]
|
2024-10-05 15:57:34 -05:00
|
|
|
.velocity,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.aimTime':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.aim_time -
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.aim_time,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.dispersionStill':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
|
|
|
|
.dispersion_base -
|
|
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
|
|
|
|
.dispersion_base,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.dispersionMoving':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.tracks.at(-1)!.dispersion_move -
|
|
|
|
|
b.tracks.at(-1)!.dispersion_move,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.gunDepression':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-05 15:57:34 -05:00
|
|
|
modelDefinitions.models[a.id].turrets[a.turrets.at(-1)!.id]
|
2024-10-07 18:45:11 -05:00
|
|
|
.guns[a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
|
2024-10-05 15:57:34 -05:00
|
|
|
.pitch.max +
|
2024-10-07 18:45:11 -05:00
|
|
|
(modelDefinitions.models[a.id].initial_turret_rotation?.pitch ??
|
2024-10-05 15:57:34 -05:00
|
|
|
0) -
|
|
|
|
|
modelDefinitions.models[b.id].turrets[b.turrets.at(-1)!.id]
|
2024-10-07 18:45:11 -05:00
|
|
|
.guns[b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
|
2024-10-05 15:57:34 -05:00
|
|
|
.pitch.max -
|
2024-10-07 18:45:11 -05:00
|
|
|
(modelDefinitions.models[b.id].initial_turret_rotation?.pitch ??
|
2024-10-05 15:57:34 -05:00
|
|
|
0),
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'fire.gunElevation':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-05 15:57:34 -05:00
|
|
|
modelDefinitions.models[b.id].turrets[b.turrets.at(-1)!.id]
|
2024-10-07 18:45:11 -05:00
|
|
|
.guns[b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
|
2024-10-05 15:57:34 -05:00
|
|
|
.pitch.min +
|
2024-10-07 18:45:11 -05:00
|
|
|
(modelDefinitions.models[b.id].initial_turret_rotation?.pitch ??
|
2024-10-05 15:57:34 -05:00
|
|
|
0) -
|
|
|
|
|
modelDefinitions.models[a.id].turrets[a.turrets.at(-1)!.id]
|
2024-10-07 18:45:11 -05:00
|
|
|
.guns[a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.id]
|
2024-10-05 15:57:34 -05:00
|
|
|
.pitch.min -
|
2024-10-07 18:45:11 -05:00
|
|
|
(modelDefinitions.models[a.id].initial_turret_rotation?.pitch ??
|
2024-10-05 15:57:34 -05:00
|
|
|
0),
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.forwardsSpeed':
|
2024-10-07 18:45:11 -05:00
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) => a.speed_forwards - b.speed_forwards,
|
|
|
|
|
);
|
2024-06-25 19:24:33 -05:00
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.backwardsSpeed':
|
|
|
|
|
sorted = filtered.sort(
|
2024-10-07 18:45:11 -05:00
|
|
|
(a, b) => a.speed_backwards - b.speed_backwards,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.power':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) => a.engines.at(-1)!.power - b.engines.at(-1)!.power,
|
|
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.powerToWeight':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
|
|
|
|
a.engines.at(-1)!.power /
|
|
|
|
|
(a.weight +
|
|
|
|
|
a.engines.at(-1)!.weight +
|
|
|
|
|
a.tracks.at(-1)!.weight +
|
|
|
|
|
a.turrets.at(-1)!.weight +
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base
|
|
|
|
|
.weight) -
|
2024-06-25 19:24:33 -05:00
|
|
|
b.engines.at(-1)!.power /
|
|
|
|
|
(b.weight +
|
|
|
|
|
b.engines.at(-1)!.weight +
|
|
|
|
|
b.tracks.at(-1)!.weight +
|
|
|
|
|
b.turrets.at(-1)!.weight +
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight),
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.weight':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
|
|
|
|
a.weight +
|
|
|
|
|
a.engines.at(-1)!.weight +
|
|
|
|
|
a.tracks.at(-1)!.weight +
|
|
|
|
|
a.turrets.at(-1)!.weight +
|
2024-10-07 18:45:11 -05:00
|
|
|
a.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight -
|
2024-06-25 19:17:53 -05:00
|
|
|
(b.weight +
|
|
|
|
|
b.engines.at(-1)!.weight +
|
|
|
|
|
b.tracks.at(-1)!.weight +
|
|
|
|
|
b.turrets.at(-1)!.weight +
|
2024-10-07 18:45:11 -05:00
|
|
|
b.turrets.at(-1)!.guns.at(-1)!.gun_type!.value.base.weight),
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
2024-06-25 19:17:53 -05:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
case 'maneuverability.traverseSpeed':
|
|
|
|
|
sorted = filtered.sort(
|
|
|
|
|
(a, b) =>
|
2024-10-07 18:45:11 -05:00
|
|
|
a.tracks.at(-1)!.traverse_speed -
|
|
|
|
|
b.tracks.at(-1)!.traverse_speed,
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
return tankopediaSort.direction === 'ascending'
|
|
|
|
|
? sorted
|
|
|
|
|
: sorted.reverse();
|
2024-06-25 19:24:33 -05:00
|
|
|
} else {
|
2024-10-02 10:21:16 -05:00
|
|
|
const searchedRaw = fuzzysort.go(tankFilters.search, tankNames, {
|
2024-08-13 19:44:35 -05:00
|
|
|
keys: ['searchableName', 'searchableNameDeburr', 'camouflages'],
|
2024-06-25 19:24:33 -05:00
|
|
|
});
|
|
|
|
|
const searchedTanks = searchedRaw.map(
|
2024-10-05 15:57:34 -05:00
|
|
|
(result) => tankDefinitions.tanks[result.obj.id],
|
2024-06-25 19:24:33 -05:00
|
|
|
);
|
|
|
|
|
return searchedTanks;
|
2024-06-25 19:17:53 -05:00
|
|
|
}
|
2024-09-17 22:13:35 -05:00
|
|
|
}, [tankFilters, tankopediaSort]);
|
2024-07-09 21:16:20 -05:00
|
|
|
const [loadedRows, setLoadedRows] = useState(DEFAULT_LOADED_CARDS);
|
|
|
|
|
const tanks = tanksFiltered.slice(0, loadedRows);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setLoadedRows(DEFAULT_LOADED_CARDS);
|
2024-09-17 22:13:35 -05:00
|
|
|
}, [tankFilters, tankopediaSort]);
|
2024-02-09 16:01:06 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
return (
|
2024-06-25 19:58:29 -05:00
|
|
|
<Flex direction="column" gap="4" flexGrow="1" {...props}>
|
2024-06-28 20:17:47 -05:00
|
|
|
<SearchBar topResult={tanks?.[0]} onSelect={onSelect} />
|
2024-05-23 13:46:33 -05:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
{!tankFilters.search && !tankFilters.searching && (
|
2024-06-25 19:24:33 -05:00
|
|
|
<FilterControl compact={compact} />
|
|
|
|
|
)}
|
2024-04-06 22:00:40 -05:00
|
|
|
|
2024-07-27 13:33:45 -05:00
|
|
|
<Flex mt="2" gap="1" align="center" justify="center" direction="column">
|
2024-07-22 20:24:32 -05:00
|
|
|
<Flex gap="2">
|
|
|
|
|
<Text color="gray">
|
2024-09-21 12:16:51 -05:00
|
|
|
{tanksFiltered.length} tank
|
|
|
|
|
{tanksFiltered.length === 1 ? '' : 's'}
|
2024-07-22 20:24:32 -05:00
|
|
|
</Text>
|
2024-01-21 11:06:40 -06:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
{onSelectAll && (
|
|
|
|
|
<Link
|
|
|
|
|
underline="always"
|
|
|
|
|
href="#"
|
2024-07-12 19:24:12 -05:00
|
|
|
onClick={() => onSelectAll(tanksFiltered)}
|
2024-06-25 19:24:33 -05:00
|
|
|
>
|
2024-07-22 20:24:32 -05:00
|
|
|
Select all
|
2024-06-25 19:24:33 -05:00
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
2024-07-22 20:24:32 -05:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
{tankopediaSort.by !== 'meta.none' && (
|
2024-07-22 20:24:32 -05:00
|
|
|
<Text color="gray">
|
2024-09-17 22:13:35 -05:00
|
|
|
Sorting by {SORT_NAMES[tankopediaSort.by]}
|
|
|
|
|
{SORT_UNITS[tankopediaSort.by] === undefined
|
2024-07-22 20:24:32 -05:00
|
|
|
? ''
|
2024-09-17 22:13:35 -05:00
|
|
|
: ` (${SORT_UNITS[tankopediaSort.by]})`}
|
|
|
|
|
, {tankopediaSort.direction}
|
2024-07-22 20:24:32 -05:00
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
2024-04-06 17:28:45 -05:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
{tankFilters.testing === 'only' && (
|
2024-06-25 19:24:33 -05:00
|
|
|
<Flex justify="center" mt="4">
|
|
|
|
|
<Callout.Root color="amber">
|
|
|
|
|
<Callout.Icon>
|
|
|
|
|
<ExperimentIcon style={{ width: '1em', height: '1em' }} />
|
|
|
|
|
</Callout.Icon>
|
|
|
|
|
<Callout.Text>
|
2024-08-19 13:56:04 -05:00
|
|
|
Tanks in testing are subject to change and may not represent the
|
|
|
|
|
final product.
|
2024-06-25 19:24:33 -05:00
|
|
|
</Callout.Text>
|
|
|
|
|
</Callout.Root>
|
|
|
|
|
</Flex>
|
|
|
|
|
)}
|
2024-06-25 19:17:53 -05:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
{!tankFilters.searching && (
|
2024-06-25 19:24:33 -05:00
|
|
|
<>
|
|
|
|
|
{tanks.length > 0 && (
|
|
|
|
|
<TankCardWrapper>
|
2024-10-12 21:42:38 -05:00
|
|
|
{tanks.map((tank, index) => {
|
|
|
|
|
const hasAd = (index + 16) % 32 === 0;
|
2024-10-13 20:59:01 -05:00
|
|
|
const adId = Math.floor(index / 32);
|
2024-07-22 20:32:10 -05:00
|
|
|
|
2024-10-12 21:42:38 -05:00
|
|
|
return (
|
|
|
|
|
<Fragment key={tank.id}>
|
|
|
|
|
<TankCard onSelect={onSelect} tank={tank} />
|
|
|
|
|
|
|
|
|
|
{!exempt &&
|
|
|
|
|
!compact &&
|
|
|
|
|
hasAd &&
|
|
|
|
|
index !== tanks.length - 1 && (
|
2024-10-13 00:26:38 -05:00
|
|
|
<Flex gridColumn="1 / -1">
|
2024-10-12 21:42:38 -05:00
|
|
|
<Ad
|
2024-10-13 00:26:38 -05:00
|
|
|
commonHeight={250}
|
2024-10-13 20:59:01 -05:00
|
|
|
id={`tankopedia-search-${adId}`}
|
2024-10-12 21:42:38 -05:00
|
|
|
/>
|
2024-10-13 00:26:38 -05:00
|
|
|
</Flex>
|
2024-10-12 21:42:38 -05:00
|
|
|
)}
|
|
|
|
|
</Fragment>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2024-07-09 21:16:20 -05:00
|
|
|
|
|
|
|
|
{times(
|
|
|
|
|
Math.min(PREVIEW_COUNT, tanksFiltered.length - loadedRows),
|
|
|
|
|
(index) => {
|
|
|
|
|
return (
|
|
|
|
|
<SkeletonTankCard
|
|
|
|
|
key={index}
|
|
|
|
|
onIntersection={() => {
|
|
|
|
|
setLoadedRows((state) =>
|
|
|
|
|
Math.min(state + 2, tanksFiltered.length),
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
)}
|
2024-06-25 19:24:33 -05:00
|
|
|
</TankCardWrapper>
|
|
|
|
|
)}
|
2024-06-25 19:17:53 -05:00
|
|
|
|
2024-06-25 19:24:33 -05:00
|
|
|
{tanks.length === 0 && <NoResults type="search" />}
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2024-06-25 19:17:53 -05:00
|
|
|
|
2024-09-17 22:13:35 -05:00
|
|
|
{tankFilters.searching && (
|
2024-06-25 19:24:33 -05:00
|
|
|
<TankCardWrapper>
|
|
|
|
|
{times(Math.round(10 + 10 * Math.random()), (index) => (
|
|
|
|
|
<SkeletonTankCard key={index} />
|
|
|
|
|
))}
|
|
|
|
|
</TankCardWrapper>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|