mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-02 03:00:32 -04:00
moved rankHelpers to utils
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { computeRank as computeRankUtil, computeRankCap } from '@metafam/utils';
|
||||
|
||||
import { PlayerRank_Enum } from './autogen/hasura-sdk';
|
||||
|
||||
export const RANKS = [
|
||||
@@ -6,27 +8,18 @@ export const RANKS = [
|
||||
PlayerRank_Enum.Gold,
|
||||
PlayerRank_Enum.Silver,
|
||||
PlayerRank_Enum.Bronze,
|
||||
]
|
||||
];
|
||||
|
||||
export const PLAYERS_PER_RANK = [7, 7, 7, 14, 21];
|
||||
|
||||
// A summation of PLAYERS_PER_RANK.
|
||||
// This is the first index for which players will NOT be ranked, e.g.
|
||||
// the 56th player will be Bronze, and the 57th player will not be ranked.
|
||||
export const RANKED_CAP: number = PLAYERS_PER_RANK.reduce((sum, rankCount) => {
|
||||
return sum + rankCount;
|
||||
}, 0);
|
||||
export const RANKED_CAP = computeRankCap(PLAYERS_PER_RANK);
|
||||
|
||||
// Computes the rank for the given index. This would be the index corresponding
|
||||
// to all players ordered by total_xp DESC.
|
||||
export function computeRank(totalRankIndex: number): PlayerRank_Enum | null {
|
||||
if (totalRankIndex >= RANKED_CAP) return null;
|
||||
let indexSum = 0;
|
||||
for (let i = 0; i < PLAYERS_PER_RANK.length; i++) {
|
||||
indexSum += PLAYERS_PER_RANK[i];
|
||||
if (totalRankIndex < indexSum) {
|
||||
return RANKS[i];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return computeRankUtil(
|
||||
totalRankIndex,
|
||||
PLAYERS_PER_RANK,
|
||||
RANKS,
|
||||
) as PlayerRank_Enum | null;
|
||||
}
|
||||
|
||||
@@ -4,3 +4,4 @@ export * as did from './did';
|
||||
export * as DiscordUtil from './discordHelpers';
|
||||
export * as numbers from './numbers';
|
||||
export * from './promiseHelpers';
|
||||
export * from './rankHelpers';
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// A summation of usersPerRank
|
||||
// This is the first index for which users will NOT be ranked
|
||||
const computeRankCap = (usersPerRank: Array<number>) =>
|
||||
export const computeRankCap = (usersPerRank: Array<number>) =>
|
||||
usersPerRank.reduce((sum, rankCount) => {
|
||||
return sum + rankCount;
|
||||
}, 0);
|
||||
|
||||
// Computes the rank for the given index. This would be the index corresponding
|
||||
// to all players ordered by total_xp DESC.
|
||||
// to all users ordered by total_xp DESC.
|
||||
export function computeRank(
|
||||
rankIndex: number,
|
||||
usersPerRank: Array<number>,
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
Wrap,
|
||||
WrapItem,
|
||||
} from '@metafam/ds';
|
||||
import { computeRank } from '@metafam/utils';
|
||||
import { MetaLink } from 'components/Link';
|
||||
import { PlayerContacts } from 'components/Player/PlayerContacts';
|
||||
import { PlayerTileMemberships } from 'components/Player/PlayerTileMemberships';
|
||||
@@ -29,7 +30,6 @@ import {
|
||||
getPlayerImage,
|
||||
getPlayerName,
|
||||
} from 'utils/playerHelpers';
|
||||
import { computeRank } from 'utils/rankHelpers';
|
||||
|
||||
const PATRON_RANKS = [
|
||||
PlayerRank_Enum.Diamond,
|
||||
|
||||
Reference in New Issue
Block a user