mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-16 06:06:11 +01:00
ranks
This commit is contained in:
1 parent
eb0c35d6c6
commit
ae2839cb83
14 files changed
+452
-281
No files matched your search
@@ -0,0 +1,74 @@
|
||||
import { useMemo } from "react";
|
||||
import { api } from "../api/dynamic";
|
||||
import { Tankopedia, TankopediaRelativeAgainst } from "../stores/tankopedia";
|
||||
import { createTankState } from "../tankopedia/createTankState";
|
||||
import { computeCharacteristics } from "./useCharacteristics";
|
||||
import { DuelModule, useDuel } from "./useDuel";
|
||||
|
||||
const tankDefinitions = await api.tanks();
|
||||
|
||||
const candidateStates = new Map(
|
||||
Object.values(tankDefinitions.tanks).map((candidate) => {
|
||||
const state = createTankState(candidate);
|
||||
const turret = candidate.turrets.find((t) => t.id === state.turret)!;
|
||||
const gun = turret.guns.find((g) => g.id === state.gun)!;
|
||||
|
||||
return [
|
||||
candidate.id,
|
||||
{
|
||||
state,
|
||||
shells: gun.shells.map((shell) => shell.id),
|
||||
},
|
||||
];
|
||||
}),
|
||||
);
|
||||
|
||||
export function useComparisonCharacteristics() {
|
||||
const environment = Tankopedia.use((state) => state.environment);
|
||||
|
||||
const tank = useDuel("protagonist", DuelModule.Tank);
|
||||
const gun = useDuel("protagonist", DuelModule.Gun);
|
||||
const shell = useDuel("protagonist", DuelModule.Shell);
|
||||
const protagonistShellIndex = gun.shells.findIndex((s) => s.id === shell.id);
|
||||
|
||||
const relativeAgainst = Tankopedia.use((state) => state.relative_against);
|
||||
|
||||
const candidates = useMemo(() => {
|
||||
return Object.values(tankDefinitions.tanks).filter((candidate) => {
|
||||
switch (relativeAgainst) {
|
||||
case TankopediaRelativeAgainst.ClassAndTier:
|
||||
return candidate.tier === tank.tier && candidate.class === tank.class;
|
||||
|
||||
case TankopediaRelativeAgainst.Tier:
|
||||
return candidate.tier === tank.tier;
|
||||
|
||||
case TankopediaRelativeAgainst.All:
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}, [tank, relativeAgainst]);
|
||||
|
||||
const characteristics = useMemo(() => {
|
||||
return candidates.flatMap((candidate) => {
|
||||
const { state: candidateState, shells } = candidateStates.get(
|
||||
candidate.id,
|
||||
)!;
|
||||
const maxStateShellIndex = shells.length - 1;
|
||||
const stateShellIndex = Math.min(
|
||||
maxStateShellIndex,
|
||||
protagonistShellIndex,
|
||||
);
|
||||
|
||||
const state = { ...candidateState, shell: shells[stateShellIndex] };
|
||||
|
||||
return [
|
||||
computeCharacteristics(
|
||||
{ protagonist: state, antagonist: state },
|
||||
environment,
|
||||
),
|
||||
];
|
||||
});
|
||||
}, [candidates, environment, protagonistShellIndex]);
|
||||
|
||||
return characteristics;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
calculateRankings,
|
||||
type CharacteristicRank,
|
||||
} from "../tankopedia/calculateRankings";
|
||||
import type {
|
||||
CharacteristicName,
|
||||
ComputedCharacteristics,
|
||||
} from "../types/characteristics";
|
||||
import { useComparisonCharacteristics } from "./useComparisonCharacteristics";
|
||||
|
||||
export function useRankings(
|
||||
characteristics: ComputedCharacteristics,
|
||||
): Map<CharacteristicName, CharacteristicRank> {
|
||||
const comparisonCharacteristics = useComparisonCharacteristics();
|
||||
|
||||
return useMemo(
|
||||
() => calculateRankings(characteristics, comparisonCharacteristics),
|
||||
[characteristics, comparisonCharacteristics],
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user