diff --git a/projects/common/src/player/impl/scoresaber-player.ts b/projects/common/src/player/impl/scoresaber-player.ts index 936b79d..067486d 100644 --- a/projects/common/src/player/impl/scoresaber-player.ts +++ b/projects/common/src/player/impl/scoresaber-player.ts @@ -5,7 +5,7 @@ import ScoreSaberPlayerToken from "../../types/token/scoresaber/score-saber-play import { formatDateMinimal, getDaysAgoDate, getMidnightAlignedDate } from "../../utils/time-utils"; import { getPageFromRank } from "../../utils/utils"; import { Config } from "../../config"; -import { getValueFromHistory } from "website/src/common/player-utils"; +import { getValueFromHistory } from "../../utils/player-utils"; /** * A ScoreSaber player. diff --git a/projects/common/src/utils/player-utils.ts b/projects/common/src/utils/player-utils.ts index 1b31d73..af60564 100644 --- a/projects/common/src/utils/player-utils.ts +++ b/projects/common/src/utils/player-utils.ts @@ -17,6 +17,31 @@ export function getPlayerHistoryToday(player: ScoreSaberPlayer) { return player.statisticHistory[formatDateMinimal(today)] || {}; } +/** + * Gets a value from an {@link PlayerHistory} + * based on the field + * + * @param history the history to get the value from + * @param field the field to get + */ +export function getValueFromHistory(history: PlayerHistory, field: string): number | undefined { + const keys = field.split("."); + /* eslint-disable @typescript-eslint/no-explicit-any */ + let value: any = history; + + // Navigate through the keys safely + for (const key of keys) { + if (value && key in value) { + value = value[key]; + } else { + return undefined; // Return null if the key doesn't exist + } + } + + // Ensure we return a number or null + return typeof value === "number" ? value : undefined; +} + /** * Sorts the player history based on date, * so the most recent date is first diff --git a/projects/website/src/common/player-utils.ts b/projects/website/src/common/player-utils.ts deleted file mode 100644 index a1bbac1..0000000 --- a/projects/website/src/common/player-utils.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { PlayerHistory } from "@ssr/common/player/player-history"; - -/** - * Gets a value from an {@link PlayerHistory} - * based on the field - * - * @param history the history to get the value from - * @param field the field to get - */ -export function getValueFromHistory(history: PlayerHistory, field: string): number | undefined { - const keys = field.split("."); - /* eslint-disable @typescript-eslint/no-explicit-any */ - let value: any = history; - - // Navigate through the keys safely - for (const key of keys) { - if (value && key in value) { - value = value[key]; - } else { - return undefined; // Return null if the key doesn't exist - } - } - - // Ensure we return a number or null - return typeof value === "number" ? value : undefined; -} diff --git a/projects/website/src/components/player/chart/generic-player-chart.tsx b/projects/website/src/components/player/chart/generic-player-chart.tsx index 1f2a838..35acccd 100644 --- a/projects/website/src/components/player/chart/generic-player-chart.tsx +++ b/projects/website/src/components/player/chart/generic-player-chart.tsx @@ -2,9 +2,9 @@ import React from "react"; import GenericChart, { DatasetConfig } from "@/components/chart/generic-chart"; -import { getValueFromHistory } from "@/common/player-utils"; import ScoreSaberPlayer from "@ssr/common/player/impl/scoresaber-player"; import { parseDate } from "@ssr/common/utils/time-utils"; +import { getValueFromHistory } from "@ssr/common/utils/player-utils"; type Props = { /**