diff --git a/apps/api/src/modules/community-stats/community-stats.service.spec.ts b/apps/api/src/modules/community-stats/community-stats.service.spec.ts new file mode 100644 index 00000000..f6e84cc4 --- /dev/null +++ b/apps/api/src/modules/community-stats/community-stats.service.spec.ts @@ -0,0 +1,193 @@ +import mongoose from 'mongoose'; +import { ConnectionService } from '../global/database/connection.service'; +import { CommunityStatsCacheService } from './community-stats-cache.service'; +import { CommunityStatsService } from './community-stats.service'; +import type { + InternalMatchCardView, + InternalMatchDetailResponse, +} from './community-stats.types'; +import { MatchStatsRepository } from './match-stats.repository'; +import { MatchStatsService } from './match-stats.service'; +import type { InternalGameDetail, InternalRecord } from './match-stats.types'; + +function objectives() { + return { + tower: 1, + dragon: 0, + inhibitor: 0, + baron: 0, + riftHerald: 0, + voidGrub: 0, + elderDragon: 0, + }; +} + +function record(matchId: mongoose.Types.ObjectId): InternalRecord { + return { + matchId: matchId.toString(), + title: '내전', + scheduledAt: new Date('2026-06-18T12:00:00.000Z'), + gameNumber: 1, + riotMatchId: 'KR_1', + gameCreation: 1_000, + gameDuration: 1_800, + userId: new mongoose.Types.ObjectId().toString(), + summonerName: 'Player', + profileIconId: 1, + teamIndex: 1, + side: 'blue', + championId: 266, + championLevel: 15, + teamPosition: 'TOP', + kills: 5, + deaths: 1, + assists: 7, + win: true, + cs: 200, + csPerMin: 6.7, + gold: 12_000, + gpm: 400, + damageDealtToChampions: 18_000, + damageTaken: 20_000, + damageShare: 30, + killParticipation: 60, + visionScore: 18, + controlWardsBought: 1, + wardsPlaced: 8, + wardsKilled: 2, + firstBloodKill: false, + firstBloodAssist: false, + items: [1054, 3071, 0, 0, 0, 0], + trinket: 3340, + summonerSpells: [4, 12], + perks: { + primaryStyle: 8000, + subStyle: 8400, + keystone: 8010, + selectedPerkIds: [8010, 9111, 9105, 8299, 8444, 8451], + styles: [ + { styleId: 8000, perkIds: [8010, 9111, 9105, 8299] }, + { styleId: 8400, perkIds: [8444, 8451] }, + ], + statPerks: { defense: 5001, flex: 5008, offense: 5005 }, + }, + itemBuild: [{ timestamp: 10, itemId: 1054, type: 'purchased' }], + skillBuild: [{ timestamp: 11, skillSlot: 1, level: 1 }], + rating: 8.5, + }; +} + +describe('CommunityStatsService', () => { + it('ignores stale detail cache entries missing timeline build fields', async () => { + const communityId = new mongoose.Types.ObjectId(); + const matchId = new mongoose.Types.ObjectId(); + const match: InternalMatchCardView = { + matchId: matchId.toString(), + title: '내전', + scheduledAt: '2026-06-18T12:00:00.000Z', + status: 'finished', + gameCount: 1, + games: [], + teams: [], + seriesResults: [], + }; + const participant = record(matchId); + const gameDetail: InternalGameDetail = { + gameNumber: 1, + riotMatchId: 'KR_1', + gameCreation: 1_000, + gameDuration: 1_800, + winnerSide: 'blue', + timelineLoaded: true, + timeline: [ + { + timestamp: 0, + blue: { gold: 500, xp: 0 }, + red: { gold: 500, xp: 0 }, + goldDiff: 0, + xpDiff: 0, + }, + ], + objectiveEvents: [], + teams: [ + { + teamIndex: 1, + side: 'blue', + win: true, + objectives: objectives(), + bans: [], + participants: [participant], + }, + ], + }; + const staleCache = { + match, + games: [ + { + gameNumber: 1, + riotMatchId: 'KR_1', + gameCreation: 1_000, + gameDuration: 1_800, + teams: [ + { + teamIndex: 1, + side: 'blue', + win: true, + objectives: { tower: 1, dragon: 0, baron: 0 }, + participants: [ + { + summonerName: 'Player', + perks: { + primaryStyle: 8000, + subStyle: 8400, + keystone: 8010, + }, + }, + ], + }, + ], + }, + ], + } as unknown as InternalMatchDetailResponse; + const cacheService = { + get: jest.fn().mockResolvedValue(staleCache), + setDetail: jest.fn().mockResolvedValue(undefined), + } as unknown as jest.Mocked; + const matchStatsService = { + buildAndUpsert: jest.fn().mockResolvedValue(undefined), + } as unknown as jest.Mocked; + const service = new CommunityStatsService( + {} as ConnectionService, + cacheService, + {} as MatchStatsRepository, + matchStatsService, + ); + (service as unknown as { buildBaseDataset: jest.Mock }).buildBaseDataset = + jest.fn().mockResolvedValue({ + season: { + id: 'all', + label: '전체', + startTime: null, + endTime: null, + }, + matches: [match], + records: [participant], + detailsByMatchId: new Map([[matchId.toString(), [gameDetail]]]), + }); + + const response = await service.getMatchDetail({ communityId, matchId }); + + expect(response.games[0].timeline).toHaveLength(1); + expect(response.games[0].teams[0].participants[0].itemBuild).toHaveLength( + 1, + ); + expect(response.games[0].teams[0].participants[0].perks).toMatchObject({ + selectedPerkIds: [8010, 9111, 9105, 8299, 8444, 8451], + }); + expect(matchStatsService.buildAndUpsert).not.toHaveBeenCalled(); + expect(cacheService.setDetail).toHaveBeenCalledWith( + expect.stringContaining(':r2:'), + response, + ); + }); +}); diff --git a/apps/api/src/modules/community-stats/community-stats.service.ts b/apps/api/src/modules/community-stats/community-stats.service.ts index bd42cbed..94655491 100644 --- a/apps/api/src/modules/community-stats/community-stats.service.ts +++ b/apps/api/src/modules/community-stats/community-stats.service.ts @@ -36,6 +36,7 @@ const DEFAULT_LIST_LIMIT = 20; const MAX_LIST_LIMIT = 50; const MAX_MATCH_SCAN = 300; const MIN_HIGHLIGHT_GAMES = 5; +const MATCH_DETAIL_RESPONSE_CACHE_VERSION = 2; interface CommunityStatsContext { community: CommunityDocument; @@ -205,10 +206,10 @@ export class CommunityStatsService { communityId: mongoose.Types.ObjectId; matchId: mongoose.Types.ObjectId; }): Promise { - const key = `riot:communitystats:matchDetail:v${MATCH_STATS_BUILDER_VERSION}:${params.communityId.toString()}:${params.matchId.toString()}`; + const key = `riot:communitystats:matchDetail:v${MATCH_STATS_BUILDER_VERSION}:r${MATCH_DETAIL_RESPONSE_CACHE_VERSION}:${params.communityId.toString()}:${params.matchId.toString()}`; const cached = await this.cacheService.get(key); - if (cached) return cached; + if (cached && isCompleteMatchDetailResponse(cached)) return cached; const dataset = await this.buildBaseDataset(params.communityId, { seasonId: 'all', @@ -1013,3 +1014,22 @@ export class CommunityStatsService { return Math.round(value * 10) / 10; } } + +function isCompleteMatchDetailResponse( + response: InternalMatchDetailResponse, +): boolean { + return response.games.every( + (game) => + Array.isArray(game.timeline) && + Array.isArray(game.objectiveEvents) && + game.teams.every( + (team) => + Array.isArray(team.bans) && + team.participants.every( + (participant) => + Array.isArray(participant.itemBuild) && + Array.isArray(participant.skillBuild), + ), + ), + ); +} diff --git a/apps/api/src/modules/community-stats/match-stats.service.spec.ts b/apps/api/src/modules/community-stats/match-stats.service.spec.ts index 2e5c9945..56b31069 100644 --- a/apps/api/src/modules/community-stats/match-stats.service.spec.ts +++ b/apps/api/src/modules/community-stats/match-stats.service.spec.ts @@ -114,7 +114,7 @@ describe('MatchStatsService', () => { scheduledAt, gameCreationMin: 1_000, gameCreationMax: 2_000, - builderVersion: 7, + builderVersion: 8, }), ); }); diff --git a/apps/api/src/modules/community-stats/match-stats.types.ts b/apps/api/src/modules/community-stats/match-stats.types.ts index a2af4788..0103e82d 100644 --- a/apps/api/src/modules/community-stats/match-stats.types.ts +++ b/apps/api/src/modules/community-stats/match-stats.types.ts @@ -4,7 +4,7 @@ import type { } from '../global/database/schema'; import type { InternalMatchCardView } from './community-stats.types'; -export const MATCH_STATS_BUILDER_VERSION = 7; +export const MATCH_STATS_BUILDER_VERSION = 8; export type InternalRecord = MatchStatsRecord; export type InternalGameDetail = MatchStatsGameDetail; diff --git a/apps/web/src/pages/MatchGameDetailPage.tsx b/apps/web/src/pages/MatchGameDetailPage.tsx index b9ae2c10..5e739b13 100644 --- a/apps/web/src/pages/MatchGameDetailPage.tsx +++ b/apps/web/src/pages/MatchGameDetailPage.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useState } from "react"; import { Link, useLocation, useParams } from "react-router"; import { Area, @@ -6,6 +6,7 @@ import { CartesianGrid, Line, ReferenceLine, + ResponsiveContainer, Tooltip, XAxis, YAxis, @@ -32,15 +33,19 @@ import { LANE_LABELS } from "../lib/riot-history"; type MatchGameDetail = ApiInternalMatchDetailResponse["games"][number]; type MatchGameTeam = MatchGameDetail["teams"][number]; type MatchGameParticipant = MatchGameTeam["participants"][number]; -type MatchGameObjectiveEvent = MatchGameDetail["objectiveEvents"][number]; type DdragonManifestData = ReturnType["data"]; type RuneStyleEntry = NonNullable["runesReforged"][number]; -type DetailTab = "summary" | "build" | "damageDealt" | "damageTaken"; +type DetailTab = + | "scoreboard" + | "matchup" + | "build" + | "damageDealt" + | "damageTaken"; type TimelineMetric = "gold" | "xp"; -type ObjectiveKey = keyof MatchGameTeam["objectives"]; const DETAIL_TABS: Array<{ id: DetailTab; label: string }> = [ - { id: "summary", label: "요약" }, + { id: "scoreboard", label: "스코어보드" }, + { id: "matchup", label: "라인전" }, { id: "build", label: "룬 / 빌드" }, { id: "damageDealt", label: "가한 데미지" }, { id: "damageTaken", label: "받은 데미지" }, @@ -51,20 +56,6 @@ const TIMELINE_METRICS: Array<{ id: TimelineMetric; label: string }> = [ { id: "xp", label: "경험치" }, ]; -const OBJECTIVE_ITEMS: Array<{ - key: ObjectiveKey; - label: string; - shortLabel: string; -}> = [ - { key: "tower", label: "타워", shortLabel: "TW" }, - { key: "dragon", label: "드래곤", shortLabel: "DR" }, - { key: "inhibitor", label: "억제기", shortLabel: "IN" }, - { key: "baron", label: "내셔남작", shortLabel: "BN" }, - { key: "riftHerald", label: "전령", shortLabel: "RH" }, - { key: "voidGrub", label: "유충", shortLabel: "VG" }, - { key: "elderDragon", label: "엘더드래곤", shortLabel: "ED" }, -]; - const SKILL_ROWS: Array<{ slot: 1 | 2 | 3 | 4; label: string; @@ -87,54 +78,6 @@ const STAT_PERK_LABELS: Record = { 5011: "체력", }; -const DRAGON_TYPE_META: Record< - string, - { label: string; dotClass: string; borderClass: string; textClass: string } -> = { - FIRE_DRAGON: { - label: "화염", - dotClass: "bg-red-500", - borderClass: "border-red-500/25", - textClass: "text-red-400", - }, - WATER_DRAGON: { - label: "바다", - dotClass: "bg-blue-500", - borderClass: "border-blue-500/25", - textClass: "text-blue-400", - }, - EARTH_DRAGON: { - label: "대지", - dotClass: "bg-emerald-500", - borderClass: "border-emerald-500/25", - textClass: "text-emerald-400", - }, - AIR_DRAGON: { - label: "바람", - dotClass: "bg-sky-400", - borderClass: "border-sky-400/25", - textClass: "text-sky-400", - }, - HEXTECH_DRAGON: { - label: "마법공학", - dotClass: "bg-violet-500", - borderClass: "border-violet-500/25", - textClass: "text-violet-400", - }, - CHEMTECH_DRAGON: { - label: "화학공학", - dotClass: "bg-lime-500", - borderClass: "border-lime-500/25", - textClass: "text-lime-500", - }, - ELDER_DRAGON: { - label: "엘더", - dotClass: "bg-amber-400", - borderClass: "border-amber-400/30", - textClass: "text-amber-400", - }, -}; - function formatDateTime(value: string | number) { return new Intl.DateTimeFormat("ko-KR", { month: "long", @@ -203,27 +146,6 @@ function sideTone(side: TeamSide) { }; } -function sideObjectiveTone(side: TeamSide) { - return side === "blue" - ? "border-blue-500/25 bg-blue-500/5 text-blue-400" - : "border-red-500/25 bg-red-500/5 text-red-400"; -} - -function dragonTypeMeta(event: MatchGameObjectiveEvent) { - return ( - DRAGON_TYPE_META[event.monsterSubType ?? ""] ?? { - label: event.type === "elderDragon" ? "엘더" : "드래곤", - dotClass: event.type === "elderDragon" ? "bg-amber-400" : "bg-base-content/35", - borderClass: - event.type === "elderDragon" - ? "border-amber-400/30" - : "border-base-content/10", - textClass: - event.type === "elderDragon" ? "text-amber-400" : "text-base-content/55", - } - ); -} - function teamTotals(team: MatchGameTeam) { return team.participants.reduce( (totals, participant) => ({ @@ -238,10 +160,6 @@ function teamTotals(team: MatchGameTeam) { ); } -function objectiveCount(team: MatchGameTeam | undefined, key: ObjectiveKey) { - return team?.objectives?.[key] ?? 0; -} - function getTeamName( detail: ApiInternalMatchDetailResponse, teamIndex: number, @@ -312,6 +230,18 @@ function StatBlock({ ); } +function WinBadge({ win }: { win: boolean }) { + return win ? ( + + 승리 + + ) : ( + + 패배 + + ); +} + function ChampionCell({ participant, manifest, @@ -416,13 +346,13 @@ function ItemStrip({ ]; return ( -
+
{itemIds.map((itemId, index) => { const icon = itemIconUrl(manifest, itemId); return ( {icon ? ( @@ -434,13 +364,7 @@ function ItemStrip({ ); } -function PercentBar({ - value, - side, -}: { - value: number; - side: TeamSide; -}) { +function PercentBar({ value, side }: { value: number; side: TeamSide }) { const width = `${Math.max(0, Math.min(100, value))}%`; return (
@@ -496,7 +420,11 @@ function PlayerRow({ {participant.assists}
- {formatKda(participant.kills, participant.deaths, participant.assists)} + {formatKda( + participant.kills, + participant.deaths, + participant.assists, + )} {participant.deaths === 0 ? "" : " KDA"}
@@ -531,6 +459,104 @@ function PlayerRow({ ); } +function PlayerCard({ + participant, + manifest, +}: { + participant: MatchGameParticipant; + manifest: ReturnType["data"]; +}) { + const location = useLocation(); + const historyBackTo = `${location.pathname}${location.search}${location.hash}`; + + return ( +
+
+ +
+
+ {participant.kills} + / + {participant.deaths} + / + {participant.assists} +
+
+ {formatKda( + participant.kills, + participant.deaths, + participant.assists, + )} + {participant.deaths === 0 ? "" : " KDA"} +
+
+
+
+
+ {participant.userId ? ( + + {participant.summonerName} + + ) : ( + + {participant.summonerName} + + )} + {(participant.firstBloodKill || participant.firstBloodAssist) && ( + + {participant.firstBloodKill ? "FB" : "FBA"} + + )} +
+ +
+
+ +
+
+
+
+ 피해량 +
+
+ {formatCompactNumber(participant.damageDealtToChampions)} + + {formatPercent(participant.damageShare)} + +
+ +
+
+
+ CS +
+
+ {participant.cs} + + {participant.csPerMin}/m + +
+
+
+
+ 시야 +
+
+ {participant.visionScore} + + {participant.wardsPlaced ?? 0}/{participant.wardsKilled ?? 0} + +
+
+
+
+ ); +} + function TeamScoreHeader({ team, detail, @@ -557,16 +583,12 @@ function TeamScoreHeader({

{getTeamName(detail, team.teamIndex)}

- + {sideLabel(team.side)} - - {team.win ? "승리" : "패배"} - +
타워 {team.objectives.tower} · 드래곤 {team.objectives.dragon} · @@ -579,7 +601,10 @@ function TeamScoreHeader({ - +
@@ -599,30 +624,31 @@ function BanStrip({ ); return (
- {sortedBans.length > 0 - ? sortedBans.map((ban) => { - const icon = championIconUrl(manifest, ban.championId); - const name = - championDisplayName(manifest, ban.championId) ?? - String(ban.championId); - return ( - - {icon ? ( - {name} - ) : null} - - ); - }) - : Array.from({ length: 5 }, (_, index) => ( + {sortedBans.length > 0 ? ( + sortedBans.map((ban) => { + const icon = championIconUrl(manifest, ban.championId); + const name = + championDisplayName(manifest, ban.championId) ?? + String(ban.championId); + return ( - ))} + key={`${ban.championId}-${ban.pickTurn}`} + className="h-8 w-8 overflow-hidden border border-base-content/5 bg-base-content/10 opacity-80" + title={name} + > + {icon ? ( + {name} + ) : null} + + ); + }) + ) : ( + 밴 없음 + )}
); } @@ -640,77 +666,40 @@ function PostgameBreakdown({ left.side === right.side ? 0 : left.side === "blue" ? -1 : 1, ); const version = formatGameVersion(selectedGame.gameVersion); - const maxGold = Math.max(1, ...orderedTeams.map((team) => teamTotals(team).gold)); return (
-

세트 요약

+

경기 요약

{version ? Ver. {version} : null} {formatDuration(selectedGame.gameDuration)} {selectedGame.riotMatchId}
-
+
{orderedTeams.map((team) => { - const totals = teamTotals(team); const tone = sideTone(team.side); const teamTone = teamIndexColorClasses(team.teamIndex); return (
-
-
-
- - {getTeamName(detail, team.teamIndex)} - - - {sideLabel(team.side)} - - - {team.win ? "승리" : "패배"} - -
-
- - - - -
-
-
-
- Bans -
- -
-
-
-
+
+ + {getTeamName(detail, team.teamIndex)} + + + 밴 +
+
); })}
-
); } @@ -735,15 +724,22 @@ function GoldComparisonStrip({ const leaderName = goldDiff === 0 ? "동률" - : getTeamName(detail, leaderSide === "blue" ? blueTeam.teamIndex : redTeam.teamIndex); + : getTeamName( + detail, + leaderSide === "blue" ? blueTeam.teamIndex : redTeam.teamIndex, + ); return (
- {getTeamName(detail, blueTeam.teamIndex)} - {formatNumber(blueTotals.gold)} + + {getTeamName(detail, blueTeam.teamIndex)} + + + {formatNumber(blueTotals.gold)} +
team.side === "blue"); - const redTeam = selectedGame.teams.find((team) => team.side === "red"); - const blueTeamName = blueTeam ? getTeamName(detail, blueTeam.teamIndex) : "BLUE"; - const redTeamName = redTeam ? getTeamName(detail, redTeam.teamIndex) : "RED"; - const dragonEvents = (selectedGame.objectiveEvents ?? []).filter( - (event) => event.type === "dragon" || event.type === "elderDragon", - ); - - return ( -
-
-

- 오브젝트 요약 -

-
- - {blueTeamName} - - VS - {redTeamName} -
-
-
- {OBJECTIVE_ITEMS.map((item) => { - const blueValue = objectiveCount(blueTeam, item.key); - const redValue = objectiveCount(redTeam, item.key); - return ( -
- - {blueValue} - -
- - {item.shortLabel} - - - {item.label} - -
- - {redValue} - -
- ); - })} -
- -
- ); -} - -function DragonEventTrail({ - events, - selectedGame, - detail, -}: { - events: MatchGameObjectiveEvent[]; - selectedGame: MatchGameDetail; - detail: ApiInternalMatchDetailResponse; -}) { - if (events.length === 0) return null; - - const teamBySide = new Map(selectedGame.teams.map((team) => [team.side, team])); - - return ( -
-
-

- 드래곤 종류 -

- - 시간순 - -
-
- {events.map((event, index) => { - const meta = dragonTypeMeta(event); - const team = teamBySide.get(event.side); - const teamName = team ? getTeamName(detail, team.teamIndex) : event.side; - return ( - - - ); - })} -
-
- ); -} - interface TimelineChartPoint { timestamp: number; timeLabel: string; @@ -972,11 +854,11 @@ function TimelineGraph({ detail: ApiInternalMatchDetailResponse; }) { const [metric, setMetric] = useState("gold"); - const chartHostRef = useRef(null); - const [chartWidth, setChartWidth] = useState(0); const blueTeam = selectedGame.teams.find((team) => team.side === "blue"); const redTeam = selectedGame.teams.find((team) => team.side === "red"); - const blueTeamName = blueTeam ? getTeamName(detail, blueTeam.teamIndex) : "BLUE"; + const blueTeamName = blueTeam + ? getTeamName(detail, blueTeam.teamIndex) + : "BLUE"; const redTeamName = redTeam ? getTeamName(detail, redTeam.teamIndex) : "RED"; const metricLabel = metric === "gold" ? "골드" : "경험치"; const chartData: TimelineChartPoint[] = (selectedGame.timeline ?? []).map( @@ -1006,30 +888,6 @@ function TimelineGraph({ ? redTeamName : "동률"; - useEffect(() => { - const node = chartHostRef.current; - if (!node) return; - - let frame = 0; - const updateChartWidth = () => { - window.cancelAnimationFrame(frame); - frame = window.requestAnimationFrame(() => { - setChartWidth( - Math.max(0, Math.floor(node.getBoundingClientRect().width)), - ); - }); - }; - const observer = new ResizeObserver(updateChartWidth); - - updateChartWidth(); - observer.observe(node); - - return () => { - window.cancelAnimationFrame(frame); - observer.disconnect(); - }; - }, []); - return (
@@ -1047,9 +905,9 @@ function TimelineGraph({ key={item.id} type="button" onClick={() => setMetric(item.id)} - className={`min-w-24 flex-1 border-r border-base-content/8 px-4 py-2 text-xs font-black transition-colors last:border-r-0 sm:flex-none ${ + className={`min-w-24 flex-1 border-r border-base-content/8 px-4 py-2 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 sm:flex-none ${ metric === item.id - ? "bg-base-content text-base-100" + ? "bg-primary text-primary-content" : "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content" }`} > @@ -1060,11 +918,9 @@ function TimelineGraph({
{chartData.length > 0 ? (
-
- {chartWidth > 0 ? ( +
+ @@ -1076,7 +932,9 @@ function TimelineGraph({ `${Math.round(Number(value) / 60)}분`} + tickFormatter={(value) => + `${Math.round(Number(value) / 60)}분` + } tick={{ fill: "currentColor", fontSize: 11 }} tickLine={false} axisLine={false} @@ -1124,14 +982,18 @@ function TimelineGraph({ - ) : null} +
{blueTeamName} @@ -1160,18 +1022,27 @@ function TeamTable({ return (
-
- +
+ {team.participants.map((participant) => ( + + ))} +
+
+
- - - - - - - - + + + + + + + + @@ -1203,9 +1074,9 @@ function DetailTabBar({ key={tab.id} type="button" onClick={() => onChange(tab.id)} - className={`min-w-[7.5rem] border-r border-base-content/8 px-4 py-3 text-xs font-black transition-colors last:border-r-0 ${ + className={`min-w-[7.5rem] border-r border-base-content/8 px-4 py-3 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 ${ activeTab === tab.id - ? "bg-base-content text-base-100" + ? "bg-primary text-primary-content" : "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content" }`} > @@ -1229,7 +1100,9 @@ function RuneBuildPanel({ left.side === right.side ? 0 : left.side === "blue" ? -1 : 1, ); const participants = orderedTeams.flatMap((team) => team.participants); - const defaultKey = participants[0] ? participantBuildKey(participants[0]) : ""; + const defaultKey = participants[0] + ? participantBuildKey(participants[0]) + : ""; const [selectedKey, setSelectedKey] = useState(defaultKey); const effectiveSelectedKey = participants.some( (participant) => participantBuildKey(participant) === selectedKey, @@ -1262,7 +1135,10 @@ function RuneBuildPanel({
- +
@@ -1341,7 +1217,7 @@ function BuildChampionButton({ type="button" onClick={onClick} title={`${participant.summonerName} · ${championName}`} - className={`relative h-11 w-11 overflow-hidden border bg-base-content/10 transition ${ + className={`relative h-11 w-11 overflow-hidden border bg-base-content/10 transition focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary ${ selected ? `${tone.border} opacity-100 ring-2 ring-current ${tone.text}` : "border-base-content/5 opacity-35 hover:opacity-75" @@ -1438,7 +1314,11 @@ function RuneTreeColumn({
{styleIcon ? ( - + ) : null}
@@ -1608,7 +1488,11 @@ function ItemBuildNode({ ); } -function SkillBuildPanel({ participant }: { participant: MatchGameParticipant }) { +function SkillBuildPanel({ + participant, +}: { + participant: MatchGameParticipant; +}) { const skillEvents = participant.skillBuild ?? []; const skillByLevel = new Map( skillEvents.map((event) => [event.level, event]), @@ -1699,7 +1583,9 @@ function DamagePanel({ key={`${team.side}-${metric}`} className="overflow-hidden border border-base-content/10 bg-base-100" > -
+
{getTeamName(detail, team.teamIndex)} · {sideLabel(team.side)}
@@ -1741,6 +1627,295 @@ function DamagePanel({ ); } +const LANE_SORT_ORDER = ["TOP", "JUNGLE", "MIDDLE", "BOTTOM", "UTILITY"]; + +function laneSortValue(position: string) { + const index = LANE_SORT_ORDER.indexOf(position); + return index === -1 ? 99 : index; +} + +function ChampionAvatar({ + participant, + manifest, + size = "h-9 w-9", +}: { + participant: MatchGameParticipant; + manifest: ReturnType["data"]; + size?: string; +}) { + const icon = championIconUrl(manifest, participant.championId); + const name = + championDisplayName(manifest, participant.championId) ?? + String(participant.championId); + return ( + + {icon ? ( + {name} + ) : null} + {participant.championLevel > 0 ? ( + + {participant.championLevel} + + ) : null} + + ); +} + +function MatchupMetricRow({ + label, + blueLead, + redLead, + blueText, + redText, + bluePct, +}: { + label: string; + blueLead: boolean; + redLead: boolean; + blueText: string; + redText: string; + bluePct: number; +}) { + return ( +
+
+ + {blueText} + + + {label} + + + {redText} + +
+
+
+
+
+
+ ); +} + +function LaneMatchupCard({ + blue, + red, + detail, + manifest, +}: { + blue: MatchGameParticipant; + red: MatchGameParticipant; + detail: ApiInternalMatchDetailResponse; + manifest: ReturnType["data"]; +}) { + const laneLabel = + LANE_LABELS[blue.teamPosition] ?? + LANE_LABELS[red.teamPosition] ?? + blue.teamPosition ?? + "-"; + + 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: formatCompactNumber(blue.gold), + redText: formatCompactNumber(red.gold), + }, + { + key: "damage", + label: "딜량", + blueValue: blue.damageDealtToChampions, + redValue: red.damageDealtToChampions, + blueText: formatCompactNumber(blue.damageDealtToChampions), + redText: formatCompactNumber(red.damageDealtToChampions), + }, + { + 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: MatchGameParticipant) => + championDisplayName(manifest, participant.championId) ?? + String(participant.championId); + + return ( +
+
+
+
+
+ {blue.summonerName} +
+
+ {championName(blue)} +
+
+ +
+ + {laneLabel} + +
+ +
+
+ {red.summonerName} +
+
+ {championName(red)} +
+
+
+
+
+ {metrics.map((metric) => { + const total = metric.blueValue + metric.redValue; + const bluePct = total > 0 ? (metric.blueValue / total) * 100 : 50; + return ( + metric.redValue} + redLead={metric.redValue > metric.blueValue} + blueText={metric.blueText} + redText={metric.redText} + bluePct={bluePct} + /> + ); + })} +
+
+ ); +} + +function LaneMatchupPanel({ + selectedGame, + detail, + manifest, +}: { + selectedGame: MatchGameDetail; + detail: ApiInternalMatchDetailResponse; + manifest: ReturnType["data"]; +}) { + const blueTeam = selectedGame.teams.find((team) => team.side === "blue"); + const redTeam = selectedGame.teams.find((team) => team.side === "red"); + + if (!blueTeam || !redTeam) { + return ( +
+ 라인전 비교 데이터가 없습니다 +
+ ); + } + + 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 blueTeamName = getTeamName(detail, blueTeam.teamIndex); + const redTeamName = getTeamName(detail, redTeam.teamIndex); + + return ( +
+
+ + {blueTeamName} + + VS + {redTeamName} +
+
+ {blueSorted.map((blue, index) => { + const red = redSorted[index]; + if (!red) return null; + return ( + + ); + })} +
+
+ ); +} + +function ScoreboardTables({ + selectedGame, + detail, + manifest, +}: { + selectedGame: MatchGameDetail; + detail: ApiInternalMatchDetailResponse; + manifest: ReturnType["data"]; +}) { + const orderedTeams = [...selectedGame.teams].sort((left, right) => + left.side === right.side ? 0 : left.side === "blue" ? -1 : 1, + ); + + return ( +
+ {orderedTeams.map((team) => ( + + ))} +
+ ); +} + function GameAnalysisPanel({ activeTab, selectedGame, @@ -1752,9 +1927,15 @@ function GameAnalysisPanel({ detail: ApiInternalMatchDetailResponse; manifest: ReturnType["data"]; }) { - const orderedTeams = [...selectedGame.teams].sort((left, right) => - left.side === right.side ? 0 : left.side === "blue" ? -1 : 1, - ); + if (activeTab === "scoreboard") { + return ( + + ); + } if (activeTab === "build") { return ( @@ -1789,16 +1970,11 @@ function GameAnalysisPanel({ } return ( -
- {orderedTeams.map((team) => ( - - ))} -
+ ); } @@ -1897,7 +2073,9 @@ function MatchScoreHero({ {leftScore ?? (leftTeam.win ? 1 : 0)} - VS + + VS + {rightScore ?? (rightTeam.win ? 1 : 0)} @@ -1926,7 +2104,7 @@ function MatchScoreHero({ export default function MatchGameDetailPage() { const { id, gameNumber } = useParams(); - const [activeTab, setActiveTab] = useState("summary"); + const [activeTab, setActiveTab] = useState("scoreboard"); const requestedGameNumber = Number(gameNumber); const detailQuery = useInternalMatchDetail(id, DEFAULT_COMMUNITY_ID); const { data: ddragon } = useDdragonManifest(); @@ -1979,8 +2157,6 @@ export default function MatchGameDetailPage() { manifest={ddragon} /> - -
+ + ); }
챔피언스펠/룬선수KDA피해량시야CS아이템챔피언스펠/룬선수KDA피해량시야CS아이템