feat: enrich internal match game analysis

This commit is contained in:
dahyeon committed 2026-07-13 09:35:25 +00:00
1 parent 9f698a8fec
commit aa675199af
22 files changed
+3123 -241

No files matched your search

@@ -6,6 +6,14 @@ import {
} from "../lib/ddragon";
import { teamIndexLabel } from "../lib/league";
import { LANE_LABELS } from "../lib/riot-history";
import {
DEFAULT_LANE_CHECKPOINT,
pairLaneParticipants,
resolveCheckpointComparison,
type LaneCheckpointKey,
type LaneParticipantLike,
type NormalizedLanePosition,
} from "../lib/internal-game-matchups";
import { ItemIcon, RuneIcon, RuneStyleIcon } from "./ItemTooltip";
export type InternalGameDetailTab = "scoreboard" | "matchup" | "build";
@@ -13,6 +21,7 @@ export type InternalGameDetailTab = "scoreboard" | "matchup" | "build";
type InternalGameDetail = ApiInternalMatchDetailResponse["games"][number];
type InternalGameTeam = InternalGameDetail["teams"][number];
type InternalGameParticipant = InternalGameTeam["participants"][number];
type CheckpointParticipant = InternalGameParticipant & LaneParticipantLike;
type DdragonManifestData = DdragonManifest | null | undefined;
type RuneStyleEntry = DdragonManifest["runesReforged"][number];
@@ -44,8 +53,6 @@ const STAT_PERK_LABELS: Record<number, string> = {
5011: "체력",
};
const LANE_SORT_ORDER = ["TOP", "JUNGLE", "MIDDLE", "BOTTOM", "UTILITY"];
function formatDuration(seconds: number) {
const minutes = Math.floor(seconds / 60);
const rest = seconds % 60;
@@ -56,6 +63,11 @@ function formatNumber(value: number) {
return new Intl.NumberFormat("ko-KR").format(value);
}
function formatSignedNumber(value: number) {
if (value === 0) return "0";
return `${value > 0 ? "+" : "-"}${formatNumber(Math.abs(value))}`;
}
function sideTone(side: TeamSide) {
return side === "blue"
? {
@@ -111,11 +123,6 @@ function runeStyleSelection(
return participant.perks.styles?.find((style) => style.styleId === styleId);
}
function laneSortValue(position: string) {
const index = LANE_SORT_ORDER.indexOf(position);
return index === -1 ? 99 : index;
}
function ChampionCell({
participant,
manifest,
@@ -648,12 +655,14 @@ function SkillBuildPanel({
function MatchupMetricRow({
label,
difference,
blueLead,
redLead,
blueText,
redText,
}: {
label: string;
difference?: string;
blueLead: boolean;
redLead: boolean;
blueText: string;
@@ -668,8 +677,13 @@ function MatchupMetricRow({
>
{blueText}
</span>
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
{label}
<span className="min-w-16 text-center text-[10px] font-bold uppercase tracking-wider text-base-content/30">
<span className="block">{label}</span>
{difference ? (
<span className="mt-0.5 block normal-case text-base-content/50">
{difference}
</span>
) : null}
</span>
<span
className={`tabular-nums ${
@@ -682,101 +696,172 @@ function MatchupMetricRow({
);
}
function LaneMatchupCard({
blue,
red,
detail,
function checkpointKda(kills: number, deaths: number, assists: number) {
return deaths === 0 ? kills + assists : (kills + assists) / deaths;
}
function LaneParticipantIdentity({
participant,
manifest,
align,
ambiguous,
}: {
blue: InternalGameParticipant;
red: InternalGameParticipant;
detail: ApiInternalMatchDetailResponse;
participant: CheckpointParticipant | null;
manifest: DdragonManifestData;
align: "left" | "right";
ambiguous: boolean;
}) {
const laneLabel =
LANE_LABELS[blue.teamPosition] ??
LANE_LABELS[red.teamPosition] ??
blue.teamPosition ??
"-";
if (!participant) {
return (
<div
className={`min-w-0 text-[11px] font-bold text-base-content/30 ${
align === "right" ? "text-right" : "text-left"
}`}
>
{ambiguous ? "포지션 중복" : "선수 없음"}
</div>
);
}
const metrics = [
{
key: "kda",
label: "KDA",
blueValue:
blue.deaths === 0
? blue.kills + blue.assists
: (blue.kills + blue.assists) / blue.deaths,
redValue:
red.deaths === 0
? red.kills + red.assists
: (red.kills + red.assists) / red.deaths,
blueText: `${blue.kills}/${blue.deaths}/${blue.assists}`,
redText: `${red.kills}/${red.deaths}/${red.assists}`,
},
{
key: "gold",
label: "골드",
blueValue: blue.gold,
redValue: red.gold,
blueText: formatNumber(blue.gold),
redText: formatNumber(red.gold),
},
{
key: "cs",
label: "CS",
blueValue: blue.cs,
redValue: red.cs,
blueText: `${blue.cs} (${blue.csPerMin}/m)`,
redText: `${red.cs} (${red.csPerMin}/m)`,
},
];
const championName = (participant: InternalGameParticipant) =>
const championName =
championDisplayName(manifest, participant.championId) ??
String(participant.championId);
const details = (
<div className={`min-w-0 ${align === "right" ? "text-right" : ""}`}>
<div className="truncate text-xs font-bold text-base-content">
{participant.summonerName}
</div>
<div className="truncate text-[11px] text-base-content/40">
{championName}
</div>
</div>
);
return (
<div
className={`flex min-w-0 items-center gap-2 ${
align === "right" ? "justify-end" : ""
}`}
>
{align === "right" ? details : null}
<ChampionAvatar participant={participant} manifest={manifest} />
{align === "left" ? details : null}
</div>
);
}
function LaneMatchupCard({
position,
blue,
red,
ambiguousBlue,
ambiguousRed,
checkpointKey,
manifest,
}: {
position: NormalizedLanePosition;
blue: CheckpointParticipant | null;
red: CheckpointParticipant | null;
ambiguousBlue: boolean;
ambiguousRed: boolean;
checkpointKey: LaneCheckpointKey;
manifest: DdragonManifestData;
}) {
const laneLabel = LANE_LABELS[position] ?? position;
const comparison = resolveCheckpointComparison(blue, red, checkpointKey);
const metrics = comparison
? [
{
key: "gold",
label: "골드",
difference: `GD ${formatSignedNumber(comparison.goldDiff)}`,
blueValue: comparison.blue.gold,
redValue: comparison.red.gold,
blueText: formatNumber(comparison.blue.gold),
redText: formatNumber(comparison.red.gold),
},
{
key: "cs",
label: "CS",
difference: `CSD ${formatSignedNumber(comparison.csDiff)}`,
blueValue: comparison.blue.cs,
redValue: comparison.red.cs,
blueText: formatNumber(comparison.blue.cs),
redText: formatNumber(comparison.red.cs),
},
{
key: "xp",
label: "경험치",
difference: `XPD ${formatSignedNumber(comparison.xpDiff)}`,
blueValue: comparison.blue.xp,
redValue: comparison.red.xp,
blueText: formatNumber(comparison.blue.xp),
redText: formatNumber(comparison.red.xp),
},
{
key: "kda",
label: "K / D / A",
blueValue: checkpointKda(
comparison.blue.kills,
comparison.blue.deaths,
comparison.blue.assists,
),
redValue: checkpointKda(
comparison.red.kills,
comparison.red.deaths,
comparison.red.assists,
),
blueText: `${comparison.blue.kills}/${comparison.blue.deaths}/${comparison.blue.assists}`,
redText: `${comparison.red.kills}/${comparison.red.deaths}/${comparison.red.assists}`,
},
]
: [];
return (
<div className="overflow-hidden border border-base-content/10 bg-base-100">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 border-b border-base-content/8 bg-base-content/[0.015] px-3 py-2">
<div className="flex min-w-0 items-center justify-end gap-2">
<div className="min-w-0 text-right">
<div className="truncate text-xs font-bold text-base-content">
{blue.summonerName}
</div>
<div className="truncate text-[11px] text-base-content/40">
{championName(blue)}
</div>
</div>
<ChampionAvatar participant={blue} manifest={manifest} />
</div>
<LaneParticipantIdentity
participant={blue}
manifest={manifest}
align="right"
ambiguous={ambiguousBlue}
/>
<span className="border border-base-content/10 px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-base-content/45">
{laneLabel}
</span>
<div className="flex min-w-0 items-center gap-2">
<ChampionAvatar participant={red} manifest={manifest} />
<div className="min-w-0">
<div className="truncate text-xs font-bold text-base-content">
{red.summonerName}
</div>
<div className="truncate text-[11px] text-base-content/40">
{championName(red)}
</div>
<LaneParticipantIdentity
participant={red}
manifest={manifest}
align="left"
ambiguous={ambiguousRed}
/>
</div>
{comparison ? (
<>
<div className="divide-y divide-base-content/5">
{metrics.map((metric) => (
<MatchupMetricRow
key={`${position}-${checkpointKey}-${metric.key}`}
label={metric.label}
difference={metric.difference}
blueLead={metric.blueValue > metric.redValue}
redLead={metric.redValue > metric.blueValue}
blueText={metric.blueText}
redText={metric.redText}
/>
))}
</div>
<div className="border-t border-base-content/5 px-3 py-1.5 text-center text-[10px] font-bold text-base-content/30">
실제 기준 {formatDuration(comparison.blue.timestamp)} · {formatDuration(comparison.red.timestamp)}
</div>
</>
) : (
<div className="px-3 py-7 text-center text-xs font-bold text-base-content/35">
{ambiguousBlue || ambiguousRed
? "포지션이 중복되어 상대를 확정할 수 없습니다"
: "선택한 시점의 라인전 데이터가 없습니다"}
</div>
</div>
<div className="divide-y divide-base-content/5">
{metrics.map((metric) => (
<MatchupMetricRow
key={`${detail.match.matchId}-${blue.teamPosition}-${metric.key}`}
label={metric.label}
blueLead={metric.blueValue > metric.redValue}
redLead={metric.redValue > metric.blueValue}
blueText={metric.blueText}
redText={metric.redText}
/>
))}
</div>
)}
</div>
);
}
@@ -790,6 +875,8 @@ function LaneMatchupPanel({
detail: ApiInternalMatchDetailResponse;
manifest: DdragonManifestData;
}) {
const [checkpointKey, setCheckpointKey] =
useState<LaneCheckpointKey>(DEFAULT_LANE_CHECKPOINT);
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
const redTeam = selectedGame.teams.find((team) => team.side === "red");
@@ -801,40 +888,64 @@ function LaneMatchupPanel({
);
}
const blueSorted = [...blueTeam.participants].sort(
(left, right) =>
laneSortValue(left.teamPosition) - laneSortValue(right.teamPosition),
);
const redSorted = [...redTeam.participants].sort(
(left, right) =>
laneSortValue(left.teamPosition) - laneSortValue(right.teamPosition),
const matchups = pairLaneParticipants(
blueTeam.participants as CheckpointParticipant[],
redTeam.participants as CheckpointParticipant[],
);
const blueTeamName = getTeamName(detail, blueTeam.teamIndex);
const redTeamName = getTeamName(detail, redTeam.teamIndex);
return (
<section className="overflow-hidden border border-base-content/10 bg-base-100">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-base-content/8 px-4 py-3 text-xs font-bold">
<span className="truncate text-right text-blue-400">
{blueTeamName}
</span>
<span className="text-base-content/20">VS</span>
<span className="truncate text-red-400">{redTeamName}</span>
<div className="border-b border-base-content/8 px-4 py-3">
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-3 text-xs font-bold">
<span className="truncate text-right text-blue-400">
{blueTeamName}
</span>
<span className="text-base-content/20">VS</span>
<span className="truncate text-red-400">{redTeamName}</span>
</div>
<div
className="mx-auto mt-3 flex w-fit border border-base-content/10"
role="group"
aria-label="라인전 비교 시점"
>
{(["at10", "at15"] as const).map((key) => (
<button
key={key}
type="button"
aria-pressed={checkpointKey === key}
onClick={() => setCheckpointKey(key)}
className={`border-r border-base-content/8 px-4 py-1.5 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${
checkpointKey === key
? "bg-primary text-primary-content"
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
}`}
>
{key === "at10" ? "10분" : "15분"}
</button>
))}
</div>
</div>
<div className="grid gap-3 p-4 lg:grid-cols-2">
{blueSorted.map((blue, index) => {
const red = redSorted[index];
if (!red) return null;
return (
{matchups.length > 0 ? (
matchups.map((matchup) => (
<LaneMatchupCard
key={`matchup-${blue.teamPosition}-${blue.summonerName}`}
blue={blue}
red={red}
detail={detail}
key={`matchup-${matchup.position}`}
position={matchup.position}
blue={matchup.blue}
red={matchup.red}
ambiguousBlue={matchup.ambiguousBlue}
ambiguousRed={matchup.ambiguousRed}
checkpointKey={checkpointKey}
manifest={manifest}
/>
);
})}
))
) : (
<div className="py-10 text-center text-sm font-bold text-base-content/35 lg:col-span-2">
비교 가능한 포지션 정보가 없습니다
</div>
)}
</div>
</section>
);