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 1595e806..53fc3fa8 100644 --- a/apps/api/src/modules/community-stats/community-stats.service.ts +++ b/apps/api/src/modules/community-stats/community-stats.service.ts @@ -883,10 +883,24 @@ export class CommunityStatsService { gameName: participant.summonerName, tagLine: '', championId: participant.championId, + championLevel: participant.championLevel, teamPosition: participant.teamPosition, kills: participant.kills, deaths: participant.deaths, assists: participant.assists, + items: participant.items, + trinket: participant.trinket, + summonerSpells: participant.summonerSpells, + perks: participant.perks, + totalCs: participant.cs, + csPerMin: participant.csPerMin, + goldEarned: participant.gold, + damageDealtToChampions: participant.damageDealtToChampions, + damageTaken: participant.damageTaken, + visionScore: participant.visionScore, + wardsPlaced: participant.wardsPlaced, + wardsKilled: participant.wardsKilled, + controlWardsBought: participant.controlWardsBought, })), })), }; diff --git a/apps/api/src/modules/match-history/match-history.service.ts b/apps/api/src/modules/match-history/match-history.service.ts index 43a9644c..2ff34648 100644 --- a/apps/api/src/modules/match-history/match-history.service.ts +++ b/apps/api/src/modules/match-history/match-history.service.ts @@ -579,16 +579,45 @@ export class MatchHistoryService { }, participants: match.info.participants .filter((participant) => participant.teamId === team.teamId) - .map((participant) => ({ - puuid: participant.puuid, - gameName: participant.riotIdGameName || participant.summonerName || 'Unknown', - tagLine: participant.riotIdTagLine || '', - championId: participant.championId, - teamPosition: participant.teamPosition || participant.individualPosition, - kills: participant.kills, - deaths: participant.deaths, - assists: participant.assists, - })), + .map((participant) => { + const totalCs = this.resolveTotalCs(participant); + const minutes = this.resolveGameMinutes(match, participant); + + return { + puuid: participant.puuid, + gameName: participant.riotIdGameName || participant.summonerName || 'Unknown', + tagLine: participant.riotIdTagLine || '', + championId: participant.championId, + championLevel: participant.champLevel, + teamPosition: participant.teamPosition || participant.individualPosition, + kills: participant.kills, + deaths: participant.deaths, + assists: participant.assists, + items: [ + participant.item0, + participant.item1, + participant.item2, + participant.item3, + participant.item4, + participant.item5, + ], + trinket: participant.item6, + summonerSpells: [participant.summoner1Id, participant.summoner2Id], + perks: this.resolvePerks(participant), + totalCs, + csPerMin: this.average(totalCs, minutes), + goldEarned: participant.goldEarned, + damageDealtToChampions: participant.totalDamageDealtToChampions, + damageTaken: participant.totalDamageTaken, + visionScore: participant.visionScore, + wardsPlaced: participant.wardsPlaced, + wardsKilled: participant.wardsKilled, + controlWardsBought: this.numberField( + participant, + 'visionWardsBoughtInGame', + ), + }; + }), })); } diff --git a/apps/api/src/modules/match-history/match-history.types.ts b/apps/api/src/modules/match-history/match-history.types.ts index d553c1ca..e5aeafb8 100644 --- a/apps/api/src/modules/match-history/match-history.types.ts +++ b/apps/api/src/modules/match-history/match-history.types.ts @@ -98,6 +98,31 @@ export interface RecentMatchesResponse { season: HistorySeasonDto; } +export interface RecentMatchTeamParticipantView { + puuid: string; + gameName: string; + tagLine: string; + championId: number; + championLevel: number; + teamPosition: string; + kills: number; + deaths: number; + assists: number; + items: number[]; + trinket: number; + summonerSpells: [number, number]; + perks: { primaryStyle?: number; subStyle?: number; keystone?: number }; + totalCs: number; + csPerMin: number; + goldEarned: number; + damageDealtToChampions: number; + damageTaken: number; + visionScore: number; + wardsPlaced: number; + wardsKilled: number; + controlWardsBought: number; +} + export interface RecentMatchView { matchId: string; queueId: number; @@ -132,15 +157,6 @@ export interface RecentMatchView { side: 100 | 200; win: boolean; objectives?: { baron?: number; dragon?: number; tower?: number }; - participants: Array<{ - puuid: string; - gameName: string; - tagLine: string; - championId: number; - teamPosition: string; - kills: number; - deaths: number; - assists: number; - }>; + participants: RecentMatchTeamParticipantView[]; }>; } diff --git a/apps/api/src/modules/riot/riot-ddragon.service.ts b/apps/api/src/modules/riot/riot-ddragon.service.ts index 218e87ca..a66d65fb 100644 --- a/apps/api/src/modules/riot/riot-ddragon.service.ts +++ b/apps/api/src/modules/riot/riot-ddragon.service.ts @@ -5,7 +5,7 @@ const DDRAGON_BASE = 'https://ddragon.leagueoflegends.com'; const DDRAGON_CDN = `${DDRAGON_BASE}/cdn`; const DEFAULT_LOCALE = 'ko_KR'; const CACHE_TTL_SECONDS = 24 * 60 * 60; -const CACHE_VERSION = 'v2'; +const CACHE_VERSION = 'v3'; const FETCH_TIMEOUT_MS = 10_000; export interface DdragonChampionEntry { @@ -13,11 +13,29 @@ export interface DdragonChampionEntry { name: string; } +export interface DdragonSummonerSpellEntry { + key: string; + name: string; +} + +export interface DdragonRuneEntry { + id: number; + key: string; + icon: string; + name: string; +} + +export interface DdragonRuneStyleEntry extends DdragonRuneEntry { + slots: Array<{ runes: DdragonRuneEntry[] }>; +} + export interface DdragonManifest { version: string; cdn: string; locale: string; champions: Record; + summonerSpells: Record; + runesReforged: DdragonRuneStyleEntry[]; fetchedAt: string; } @@ -31,6 +49,27 @@ interface ChampionDataResponse { data: Record; } +interface SummonerSpellDataEntry { + key: string; + id: string; + name: string; +} + +interface SummonerSpellDataResponse { + data: Record; +} + +interface RuneDataEntry { + id: number; + key: string; + icon: string; + name: string; +} + +interface RuneStyleDataEntry extends RuneDataEntry { + slots?: Array<{ runes?: RuneDataEntry[] }>; +} + @Injectable() export class RiotDdragonService { private readonly logger = new Logger(RiotDdragonService.name); @@ -63,12 +102,18 @@ export class RiotDdragonService { private async buildManifest(locale: string): Promise { const version = await this.fetchLatestVersion(); - const champions = await this.fetchChampionMap(version, locale); + const [champions, summonerSpells, runesReforged] = await Promise.all([ + this.fetchChampionMap(version, locale), + this.fetchSummonerSpellMap(version, locale), + this.fetchRuneStyles(version, locale), + ]); return { version, cdn: DDRAGON_CDN, locale, champions, + summonerSpells, + runesReforged, fetchedAt: new Date().toISOString(), }; } @@ -103,6 +148,58 @@ export class RiotDdragonService { return map; } + private async fetchSummonerSpellMap( + version: string, + locale: string, + ): Promise> { + const url = `${DDRAGON_CDN}/${version}/data/${locale}/summoner.json`; + const payload = await this.fetchJson(url); + if (!payload || typeof payload !== 'object' || !payload.data) { + throw new Error(`ddragon summoner.json response is malformed (${url}).`); + } + + const map: Record = {}; + for (const entry of Object.values(payload.data)) { + if (entry?.key && entry.id) { + map[entry.key] = { + key: entry.id, + name: typeof entry.name === 'string' ? entry.name : entry.id, + }; + } + } + return map; + } + + private async fetchRuneStyles( + version: string, + locale: string, + ): Promise { + const url = `${DDRAGON_CDN}/${version}/data/${locale}/runesReforged.json`; + const payload = await this.fetchJson(url); + if (!Array.isArray(payload)) { + throw new Error(`ddragon runesReforged.json response is malformed (${url}).`); + } + + return payload + .filter((style): style is RuneStyleDataEntry => isRuneEntry(style)) + .map((style) => ({ + id: style.id, + key: style.key, + icon: style.icon, + name: style.name, + slots: (style.slots ?? []).map((slot) => ({ + runes: (slot.runes ?? []) + .filter((rune): rune is RuneDataEntry => isRuneEntry(rune)) + .map((rune) => ({ + id: rune.id, + key: rune.key, + icon: rune.icon, + name: rune.name, + })), + })), + })); + } + private async fetchJson(url: string): Promise { const controller = new AbortController(); const timeout = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); @@ -137,6 +234,17 @@ function normalizeLocale(locale: string): string { return `${trimmed.slice(0, 2).toLowerCase()}_${trimmed.slice(3).toUpperCase()}`; } +function isRuneEntry(value: unknown): value is RuneDataEntry { + if (!value || typeof value !== 'object') return false; + const entry = value as Partial; + return ( + typeof entry.id === 'number' && + typeof entry.key === 'string' && + typeof entry.icon === 'string' && + typeof entry.name === 'string' + ); +} + function manifestCacheKey(locale: string): string { return `ddragon:manifest:${CACHE_VERSION}:${locale}`; } diff --git a/apps/web/src/api/types.ts b/apps/web/src/api/types.ts index 2888ab99..f668056e 100644 --- a/apps/web/src/api/types.ts +++ b/apps/web/src/api/types.ts @@ -333,11 +333,29 @@ export interface DdragonChampionEntry { name: string; } +export interface DdragonSummonerSpellEntry { + key: string; + name: string; +} + +export interface DdragonRuneEntry { + id: number; + key: string; + icon: string; + name: string; +} + +export interface DdragonRuneStyleEntry extends DdragonRuneEntry { + slots: Array<{ runes: DdragonRuneEntry[] }>; +} + export interface DdragonManifest { version: string; cdn: string; locale: string; champions: Record; + summonerSpells: Record; + runesReforged: DdragonRuneStyleEntry[]; fetchedAt: string; } @@ -480,20 +498,36 @@ export interface ApiRecentSummaryResponse { lastFetchedAt: string | null; } +export interface ApiRecentMatchTeamParticipant { + puuid: string; + gameName: string; + tagLine: string; + championId: number; + championLevel: number; + teamPosition: string; + kills: number; + deaths: number; + assists: number; + items: number[]; + trinket: number; + summonerSpells: [number, number]; + perks: { primaryStyle?: number; subStyle?: number; keystone?: number }; + totalCs: number; + csPerMin: number; + goldEarned: number; + damageDealtToChampions: number; + damageTaken: number; + visionScore: number; + wardsPlaced: number; + wardsKilled: number; + controlWardsBought: number; +} + export interface ApiRecentMatchTeam { side: 100 | 200; win: boolean; objectives?: { baron?: number; dragon?: number; tower?: number }; - participants: Array<{ - puuid: string; - gameName: string; - tagLine: string; - championId: number; - teamPosition: string; - kills: number; - deaths: number; - assists: number; - }>; + participants: ApiRecentMatchTeamParticipant[]; } export interface ApiRecentMatchView { diff --git a/apps/web/src/pages/UserHistoryPage.tsx b/apps/web/src/pages/UserHistoryPage.tsx index 58f8a033..45c4923e 100644 --- a/apps/web/src/pages/UserHistoryPage.tsx +++ b/apps/web/src/pages/UserHistoryPage.tsx @@ -1,5 +1,6 @@ -import { useMemo, useState } from "react"; +import { useState } from "react"; import { useQueryClient } from "@tanstack/react-query"; +import { ChevronDown, ChevronUp } from "lucide-react"; import { Link, useLocation, useParams, useSearchParams } from "react-router"; import { useChampionStats, @@ -17,6 +18,8 @@ import type { ApiEnqueueRefreshResult, ApiTierInfo, ApiRiotRefreshEvent, + ApiRecentMatchTeam, + ApiRecentMatchTeamParticipant, ApiRecentMatchView, DdragonManifest, RiotQueueGroup, @@ -29,6 +32,9 @@ import { championIconUrl, itemIconUrl, profileIconUrl, + runeKeystoneIconUrl, + runeStyleIconUrl, + summonerSpellIconUrl, } from "../lib/ddragon"; import { isRiotQueueGroup, @@ -415,20 +421,29 @@ function ChampionStatsTable({ } function ItemGrid({ - match, + items, + trinket, manifest, + itemKey, + variant = "card", }: { - match: ApiRecentMatchView; + items: number[]; + trinket: number; manifest: DdragonManifest | null | undefined; + itemKey: string; + variant?: "card" | "detail"; }) { - const slots = [...match.items, match.trinket]; + const slots = [...items.slice(0, 6), trinket]; + const layoutClass = + variant === "detail" ? "grid-cols-7 w-[164px]" : "grid-cols-4 w-[92px]"; + return ( -
+
{slots.map((itemId, index) => { const url = itemIconUrl(manifest, itemId); return (
{url ? ( @@ -486,13 +501,355 @@ function TeamMini({ ); } -function RecentMatchCard({ +type MatchDetailScales = { + maxGold: number; + maxDamage: number; + maxTaken: number; +}; + +function formatCompactNumber(value: number) { + const safeValue = Number.isFinite(value) ? value : 0; + const abs = Math.abs(safeValue); + if (abs >= 1000) { + return `${(safeValue / 1000).toFixed(1).replace(/\.0$/, "")}k`; + } + return safeValue.toLocaleString(); +} + +function resolveParticipantKda(participant: ApiRecentMatchTeamParticipant) { + const score = participant.kills + participant.assists; + return participant.deaths === 0 + ? score + : Math.round((score / participant.deaths) * 10) / 10; +} + +function barPercent(value: number, max: number) { + if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) return 0; + return Math.max(0, Math.min(100, Math.round((value / max) * 100))); +} + +function AssetIcon({ + url, + label, + className = "w-4 h-4", +}: { + url: string | null; + label: string; + className?: string; +}) { + return ( +
+ {url ? ( + + ) : null} +
+ ); +} + +function LoadoutIcons({ + summonerSpells, + perks, + manifest, +}: { + summonerSpells: [number, number]; + perks: ApiRecentMatchTeamParticipant["perks"]; + manifest: DdragonManifest | null | undefined; +}) { + return ( +
+ + + + +
+ ); +} + +function DetailStatBar({ + label, + value, + max, + fillClass, +}: { + label: string; + value: number; + max: number; + fillClass: string; +}) { + return ( +
+
+ {label} + + {formatCompactNumber(value)} + +
+
+
+
+
+ ); +} + +function TeamHeader({ team }: { team: ApiRecentMatchTeam }) { + const sideLabel = team.side === 100 ? "블루팀" : "레드팀"; + const sideClass = team.side === 100 ? "text-sky-400" : "text-rose-400"; + const resultClass = team.win ? "text-blue-400" : "text-red-400"; + + return ( +
+
+ + {sideLabel} + + + {team.win ? "승리" : "패배"} + +
+
+ 드래곤 {team.objectives?.dragon ?? 0} + 바론 {team.objectives?.baron ?? 0} + 타워 {team.objectives?.tower ?? 0} +
+
+ ); +} + +function ParticipantRow({ + participant, + manifest, + ownerParticipantId, + scales, + teamSide, +}: { + participant: ApiRecentMatchTeamParticipant; + manifest: DdragonManifest | null | undefined; + ownerParticipantId: string; + scales: MatchDetailScales; + teamSide: 100 | 200; +}) { + const championName = + championDisplayName(manifest, participant.championId) ?? + String(participant.championId); + const championUrl = championIconUrl(manifest, participant.championId); + const participantName = participant.gameName || championName; + const isOwner = participant.puuid === ownerParticipantId; + const kda = resolveParticipantKda(participant); + const fillClass = teamSide === 100 ? "bg-sky-400/70" : "bg-rose-400/70"; + + return ( +
+
+
+ {championUrl ? ( + {championName} + ) : null} + {participant.championLevel > 0 && ( + + {participant.championLevel} + + )} +
+
+ + + + +
+
+
+ {participantName} +
+
+ {participant.tagLine ? `#${participant.tagLine} · ` : ""} + {(LANE_LABELS[participant.teamPosition] ?? participant.teamPosition) || + "포지션 없음"} +
+
+
+ +
+
+ {participant.kills} + / + {participant.deaths} + / + {participant.assists} +
+
+ {participant.deaths === 0 ? "Perfect" : `${kda} KDA`} +
+
+ +
+
+ CS + + {participant.totalCs} ({participant.csPerMin}/m) + +
+ +
+ +
+
+ + +
+
+ 시야 {participant.visionScore} · 와드 {participant.wardsPlaced}/ + {participant.wardsKilled} · 제어 {participant.controlWardsBought} +
+
+ + +
+ ); +} + +function MatchDetailPanel({ match, manifest, + ownerParticipantId, }: { match: ApiRecentMatchView; manifest: DdragonManifest | null | undefined; + ownerParticipantId: string; }) { + const teams = [...match.teams].sort((left, right) => left.side - right.side); + const participants = teams.flatMap((team) => team.participants); + const scales: MatchDetailScales = { + maxGold: Math.max(1, ...participants.map((participant) => participant.goldEarned)), + maxDamage: Math.max( + 1, + ...participants.map((participant) => participant.damageDealtToChampions), + ), + maxTaken: Math.max(1, ...participants.map((participant) => participant.damageTaken)), + }; + + if (participants.length === 0) { + return ( +
+ 이 경기의 상세 팀 데이터가 아직 없습니다. +
+ ); + } + + return ( +
+ {teams.map((team) => ( +
+ +
+
+
소환사
+
KDA
+
CS · 골드
+
피해량 · 와드
+
아이템
+
+ {team.participants.map((participant) => ( + + ))} +
+
+ ))} +
+ ); +} + +function RecentMatchCard({ + match, + manifest, + ownerParticipantId, +}: { + match: ApiRecentMatchView; + manifest: DdragonManifest | null | undefined; + ownerParticipantId: string; +}) { + const [expanded, setExpanded] = useState(false); const championName = championDisplayName(manifest, match.championId) ?? String(match.championId); const accent = match.win ? "border-l-blue-500" : "border-l-red-500"; @@ -502,7 +859,7 @@ function RecentMatchCard({
-
+
{match.remake ? "다시하기" : match.win ? "승리" : "패배"} @@ -533,8 +890,12 @@ function RecentMatchCard({ {(LANE_LABELS[match.teamPosition] ?? match.teamPosition) || "포지션 없음"}
-
- 스펠 {match.summonerSpells.join(" / ")} +
+
@@ -581,17 +942,44 @@ function RecentMatchCard({
- +
-
-
+
+
+ {expanded && ( +
+ +
+ )} ); } @@ -688,7 +1076,7 @@ export default function UserHistoryPage() { ? (championDisplayName(ddragon, championId) ?? String(championId)) : null; - const visibleChampionRows = useMemo(() => { + const visibleChampionRows = (() => { const rows = isInternalQueue ? (internalFirstPage?.championStats.champions ?? []) : (championStatsQuery.data?.champions ?? []); @@ -702,14 +1090,7 @@ export default function UserHistoryPage() { return displayName.toLowerCase().includes(keyword); }) .sort((left, right) => right[sortKey] - left[sortKey]); - }, [ - championSearch, - championStatsQuery.data?.champions, - ddragon, - internalFirstPage?.championStats.champions, - isInternalQueue, - sortKey, - ]); + })(); const refreshSocket = useRiotRefreshSocket({ puuid: isInternalQueue ? undefined : profile?.puuid, @@ -1104,6 +1485,7 @@ export default function UserHistoryPage() { key={match.matchId} match={match} manifest={ddragon} + ownerParticipantId={isInternalQueue ? profile.userId : profile.puuid} /> ))}
diff --git a/상세전적.png b/상세전적.png new file mode 100644 index 00000000..fc57278f Binary files /dev/null and b/상세전적.png differ