From a846e7ed7a7a0646fc1fb3f0934d83ea01d297c1 Mon Sep 17 00:00:00 2001 From: zk Date: Wed, 17 Jun 2026 22:18:16 +0100 Subject: [PATCH] fix: i do it to myself (#1682) --- .../sessions/SessionRaiseBreakdown.tsx | 46 +++---------------- .../tables/game-core-cells/ScoreCoreCells.tsx | 6 ++- typescript/common/src/types/documents.ts | 6 +++ .../framework/sessions/sessions.ts | 1 + 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/typescript/client/src/components/sessions/SessionRaiseBreakdown.tsx b/typescript/client/src/components/sessions/SessionRaiseBreakdown.tsx index be89cd914..11cde6d99 100644 --- a/typescript/client/src/components/sessions/SessionRaiseBreakdown.tsx +++ b/typescript/client/src/components/sessions/SessionRaiseBreakdown.tsx @@ -18,9 +18,7 @@ import { APIFetchV1 } from "#util/api"; import { ChangeOpacity } from "#util/color-opacity"; import { CreateChartMap, CreateScoreIDMap, CreateSongMap } from "#util/data"; import { Reverse, UppercaseFirst } from "#util/misc"; -import deepmerge from "deepmerge"; -import { cloneDeep } from "lodash"; -import React, { useContext, useEffect, useMemo, useState } from "react"; +import { useContext, useEffect, useMemo, useState } from "react"; import { useQuery } from "react-query"; import { type ChartDocument, @@ -315,7 +313,6 @@ function ElementStatTable({ songMap, fullSize, game, - gameConfig, metric: metric, scores, setScores, @@ -334,7 +331,6 @@ function ElementStatTable({ songMap, fullSize, game, - gameConfig, metric: metric, scores, setScores, @@ -366,7 +362,6 @@ function BreakdownChartContents({ songMap, chartMap, fullSize, - gameConfig, metric, scores, setScores, @@ -374,7 +369,6 @@ function BreakdownChartContents({ chartMap: Map>; fullSize: boolean; game: V3Game; - gameConfig: GameConfig; metric: string; score: ScoreDocument; scoreInfo: SessionScoreInfo; @@ -443,39 +437,11 @@ function BreakdownChartContents({ let preScoreCell = No Play; if (!scoreInfo.isNewScore) { - const newScoreData = cloneDeep(score.scoreData); - - for (const [k, d] of Object.entries(scoreInfo.deltas)) { - // @ts-expect-error it'll be an enum - if (typeof score.scoreData[k] === "string") { - const enumConf = GetScoreMetricConf( - gameConfig, - k, - ) as ConfEnumScoreMetric; - - // @ts-expect-error alter the enum - const newIndex = score.scoreData.enumIndexes[k] - d; - - // @ts-expect-error alter the enum - newScoreData.enumIndexes[k] = newIndex; - // @ts-expect-error alter the enum - newScoreData[k] = enumConf.values[newIndex] ?? "UNKNOWN ENUM ??"; - } else { - // @ts-expect-error ugh - newScoreData[k] = score.scoreData[k] - d; - } - } - - const mockScore = deepmerge(score, { - scoreData: newScoreData, - }) as ScoreDocument; - - // We don't actually know what the user's previous score was, we can only walk - // back the raise information we have. As such, we don't keep track of - // judgements, and must nix them here. - mockScore.scoreData.judgements = {}; - - preScoreCell = ; + // The server hands us the user's exact PB as of the session start, so + // render that directly instead of reconstructing it from deltas. + preScoreCell = ( + + ); } if (score) { diff --git a/typescript/client/src/components/tables/game-core-cells/ScoreCoreCells.tsx b/typescript/client/src/components/tables/game-core-cells/ScoreCoreCells.tsx index c72d566b4..cb7b3bddc 100644 --- a/typescript/client/src/components/tables/game-core-cells/ScoreCoreCells.tsx +++ b/typescript/client/src/components/tables/game-core-cells/ScoreCoreCells.tsx @@ -20,7 +20,11 @@ export default function ScoreCoreCells({ chart: ChartDocument; game: V3Game; rating?: AnyScoreRatingAlg; - score: PBScoreDocument | ScoreDocument; + + // `Omit` covers historical/"as of" PBs (e.g. + // a session's previous PB), which carry no ranking data. Neither the score + // cells nor the rating cell read `rankingData`, so this is safe. + score: Omit | ScoreDocument; short?: boolean; }): JSX.Element { const [defaultRating] = useScoreRatingAlg(game); diff --git a/typescript/common/src/types/documents.ts b/typescript/common/src/types/documents.ts index 872966346..f54967f01 100644 --- a/typescript/common/src/types/documents.ts +++ b/typescript/common/src/types/documents.ts @@ -129,6 +129,12 @@ interface SessionScorePBInfo { // metric -> difference between previous PB. deltas: Record; + + // The user's PB on this chart as of the session's start, i.e. exactly what + // this score raised from. Lets consumers render the true previous values + // (optional metrics, judgements, merges) instead of reconstructing them from + // deltas. Has no `rankingData`, as that isn't meaningful for a historical PB. + previousPB: Omit; } interface SessionScoreNewInfo { diff --git a/typescript/server/src/lib/score-import/framework/sessions/sessions.ts b/typescript/server/src/lib/score-import/framework/sessions/sessions.ts index 0bacd3d22..f193e5b70 100644 --- a/typescript/server/src/lib/score-import/framework/sessions/sessions.ts +++ b/typescript/server/src/lib/score-import/framework/sessions/sessions.ts @@ -77,6 +77,7 @@ function ScoreToSessionScoreInfo( scoreID: score.scoreID, isNewScore: false, deltas, + previousPB, }; }