From 292e37aaac54147f72150d01124ee26e03ccff63 Mon Sep 17 00:00:00 2001 From: dahyeon Date: Fri, 26 Jun 2026 23:29:47 -0700 Subject: [PATCH] feat: add spell and rune tooltips --- .../modules/riot/riot-ddragon.service.spec.ts | 77 +++++- .../src/modules/riot/riot-ddragon.service.ts | 19 +- apps/web/src/api/types.ts | 4 + .../components/InternalGameAnalysisTabs.tsx | 39 +-- apps/web/src/components/ItemTooltip.tsx | 250 ++++++++++++++++-- apps/web/src/lib/ddragon.ts | 31 ++- apps/web/src/pages/MatchGameDetailPage.tsx | 52 ++-- apps/web/src/pages/UserHistoryPage.tsx | 93 ++----- 8 files changed, 404 insertions(+), 161 deletions(-) diff --git a/apps/api/src/modules/riot/riot-ddragon.service.spec.ts b/apps/api/src/modules/riot/riot-ddragon.service.spec.ts index 4539bd96..be6e3c7a 100644 --- a/apps/api/src/modules/riot/riot-ddragon.service.spec.ts +++ b/apps/api/src/modules/riot/riot-ddragon.service.spec.ts @@ -20,7 +20,7 @@ describe('RiotDdragonService', () => { jest.restoreAllMocks(); }); - it('includes localized item metadata in the manifest', async () => { + it('includes localized item, spell, and rune metadata in the manifest', async () => { const fetchMock = jest.fn(async (url: string) => { if (url.endsWith('/api/versions.json')) { return jsonResponse(['15.24.1']); @@ -35,12 +35,40 @@ describe('RiotDdragonService', () => { if (url.endsWith('/summoner.json')) { return jsonResponse({ data: { - SummonerFlash: { key: '4', id: 'SummonerFlash', name: '점멸' }, + SummonerFlash: { + key: '4', + id: 'SummonerFlash', + name: '점멸', + description: '커서 방향으로 순간이동합니다.', + tooltip: '커서 방향으로 순간이동합니다.', + }, }, }); } if (url.endsWith('/runesReforged.json')) { - return jsonResponse([]); + return jsonResponse([ + { + id: 8000, + key: 'Precision', + icon: 'perk-images/Styles/7201_Precision.png', + name: '정밀', + slots: [ + { + runes: [ + { + id: 8005, + key: 'PressTheAttack', + icon: 'perk-images/Styles/Precision/PressTheAttack/PressTheAttack.png', + name: '집중 공격', + shortDesc: '연속 공격 시 추가 피해', + longDesc: + '기본 공격으로 적을 약화시킵니다.', + }, + ], + }, + ], + }, + ]); } if (url.endsWith('/item.json')) { return jsonResponse({ @@ -70,6 +98,33 @@ describe('RiotDdragonService', () => { await expect(service.getManifest('ko_KR')).resolves.toMatchObject({ version: '15.24.1', locale: 'ko_KR', + summonerSpells: { + '4': { + key: 'SummonerFlash', + name: '점멸', + description: '커서 방향으로 순간이동합니다.', + tooltip: '커서 방향으로 순간이동합니다.', + }, + }, + runesReforged: [ + { + id: 8000, + name: '정밀', + slots: [ + { + runes: [ + { + id: 8005, + name: '집중 공격', + shortDesc: '연속 공격 시 추가 피해', + longDesc: + '기본 공격으로 적을 약화시킵니다.', + }, + ], + }, + ], + }, + ], items: { '1055': { name: '도란의 검', @@ -90,8 +145,22 @@ describe('RiotDdragonService', () => { expect.any(Object), ); expect(redis.setJson).toHaveBeenCalledWith( - 'ddragon:manifest:v4:ko_KR', + 'ddragon:manifest:v5:ko_KR', expect.objectContaining({ + summonerSpells: expect.objectContaining({ + '4': expect.objectContaining({ description: '커서 방향으로 순간이동합니다.' }), + }), + runesReforged: expect.arrayContaining([ + expect.objectContaining({ + slots: expect.arrayContaining([ + expect.objectContaining({ + runes: expect.arrayContaining([ + expect.objectContaining({ longDesc: expect.stringContaining('기본 공격') }), + ]), + }), + ]), + }), + ]), items: expect.objectContaining({ '1055': expect.objectContaining({ name: '도란의 검' }), }), diff --git a/apps/api/src/modules/riot/riot-ddragon.service.ts b/apps/api/src/modules/riot/riot-ddragon.service.ts index c4ff9d8a..cff9ab2c 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 = 'v4'; +const CACHE_VERSION = 'v5'; const FETCH_TIMEOUT_MS = 10_000; export interface DdragonChampionEntry { @@ -16,6 +16,8 @@ export interface DdragonChampionEntry { export interface DdragonSummonerSpellEntry { key: string; name: string; + description: string; + tooltip: string; } export interface DdragonRuneEntry { @@ -23,6 +25,8 @@ export interface DdragonRuneEntry { key: string; icon: string; name: string; + shortDesc: string; + longDesc: string; } export interface DdragonRuneStyleEntry extends DdragonRuneEntry { @@ -66,6 +70,8 @@ interface SummonerSpellDataEntry { key: string; id: string; name: string; + description?: string; + tooltip?: string; } interface SummonerSpellDataResponse { @@ -77,6 +83,8 @@ interface RuneDataEntry { key: string; icon: string; name: string; + shortDesc?: string; + longDesc?: string; } interface RuneStyleDataEntry extends RuneDataEntry { @@ -195,6 +203,9 @@ export class RiotDdragonService { map[entry.key] = { key: entry.id, name: typeof entry.name === 'string' ? entry.name : entry.id, + description: + typeof entry.description === 'string' ? entry.description : '', + tooltip: typeof entry.tooltip === 'string' ? entry.tooltip : '', }; } } @@ -218,6 +229,9 @@ export class RiotDdragonService { key: style.key, icon: style.icon, name: style.name, + shortDesc: + typeof style.shortDesc === 'string' ? style.shortDesc : '', + longDesc: typeof style.longDesc === 'string' ? style.longDesc : '', slots: (style.slots ?? []).map((slot) => ({ runes: (slot.runes ?? []) .filter((rune): rune is RuneDataEntry => isRuneEntry(rune)) @@ -226,6 +240,9 @@ export class RiotDdragonService { key: rune.key, icon: rune.icon, name: rune.name, + shortDesc: + typeof rune.shortDesc === 'string' ? rune.shortDesc : '', + longDesc: typeof rune.longDesc === 'string' ? rune.longDesc : '', })), })), })); diff --git a/apps/web/src/api/types.ts b/apps/web/src/api/types.ts index 219271dc..bce1341e 100644 --- a/apps/web/src/api/types.ts +++ b/apps/web/src/api/types.ts @@ -482,6 +482,8 @@ export interface DdragonChampionEntry { export interface DdragonSummonerSpellEntry { key: string; name: string; + description: string; + tooltip: string; } export interface DdragonRuneEntry { @@ -489,6 +491,8 @@ export interface DdragonRuneEntry { key: string; icon: string; name: string; + shortDesc: string; + longDesc: string; } export interface DdragonRuneStyleEntry extends DdragonRuneEntry { diff --git a/apps/web/src/components/InternalGameAnalysisTabs.tsx b/apps/web/src/components/InternalGameAnalysisTabs.tsx index 7a75d6c0..2ebf3edc 100644 --- a/apps/web/src/components/InternalGameAnalysisTabs.tsx +++ b/apps/web/src/components/InternalGameAnalysisTabs.tsx @@ -3,12 +3,10 @@ import type { ApiInternalMatchDetailResponse, DdragonManifest, TeamSide } from " import { championDisplayName, championIconUrl, - runeIconUrl, - runeStyleIconUrl, } from "../lib/ddragon"; import { teamIndexLabel } from "../lib/league"; import { LANE_LABELS } from "../lib/riot-history"; -import { ItemIcon } from "./ItemTooltip"; +import { ItemIcon, RuneIcon, RuneStyleIcon } from "./ItemTooltip"; export type InternalGameDetailTab = "scoreboard" | "matchup" | "build"; @@ -413,21 +411,17 @@ function RuneTreeColumn({ ); } - const styleIcon = runeStyleIconUrl(manifest, runeStyle.id); const selectionIds = new Set(selection?.perkIds ?? []); return (
- - {styleIcon ? ( - - ) : null} - +
{label} @@ -455,25 +449,18 @@ function RuneTreeColumn({ {slot.runes.map((rune) => { const selected = selectedIds.has(rune.id) || selectionIds.has(rune.id); - const icon = runeIconUrl(manifest, rune.id); return ( - - {icon ? ( - - ) : null} - + /> ); })}
diff --git a/apps/web/src/components/ItemTooltip.tsx b/apps/web/src/components/ItemTooltip.tsx index bb20b888..1fae4133 100644 --- a/apps/web/src/components/ItemTooltip.tsx +++ b/apps/web/src/components/ItemTooltip.tsx @@ -1,4 +1,4 @@ -import type { CSSProperties, RefObject } from "react"; +import type { CSSProperties, ReactNode, RefObject } from "react"; import { useEffect, useId, useRef, useState } from "react"; import { createPortal } from "react-dom"; import type { DdragonManifest } from "../api/types"; @@ -6,7 +6,13 @@ import { itemDetails, itemDisplayName, itemIconUrl, + runeDetails, + runeIconUrl, + runeStyleDetails, + runeStyleIconUrl, safeDdragonDescriptionHtml, + summonerSpellDetails, + summonerSpellIconUrl, } from "../lib/ddragon"; type TooltipPosition = { @@ -24,6 +30,24 @@ type ItemIconProps = { trinket?: boolean; }; +type TooltipIconProps = { + active: boolean; + label: string; + emptyLabel: string; + icon: string | null; + className: string; + imageClassName: string; + slotClassName: string; + children: ReactNode; +}; + +type ManifestIconProps = { + manifest: DdragonManifest | null | undefined; + className?: string; + imageClassName?: string; + slotClassName?: string; +}; + const VIEWPORT_MARGIN = 8; const TOOLTIP_GAP = 8; const TOOLTIP_WIDTH = 320; @@ -35,9 +59,6 @@ export function ItemIcon({ imageClassName = "scale-[1.18]", trinket = false, }: ItemIconProps) { - const anchorRef = useRef(null); - const tooltipId = useId(); - const [open, setOpen] = useState(false); const icon = itemIconUrl(manifest, itemId); const hasItem = itemId > 0; const itemName = itemDisplayName(manifest, itemId) ?? `아이템 ${itemId}`; @@ -45,21 +66,125 @@ export function ItemIcon({ ? "border-primary/25 bg-base-content/[0.04]" : "border-base-content/5 bg-base-content/8"; + return ( + + + + ); +} + +export function SummonerSpellIcon({ + spellId, + manifest, + className = "h-5 w-5", + imageClassName = "", + slotClassName = "border border-base-content/5 bg-base-content/10", +}: ManifestIconProps & { spellId: number }) { + const spell = summonerSpellDetails(manifest, spellId); + const spellName = spell?.name ?? `스펠 ${spellId}`; + + return ( + 0} + label={spellName} + emptyLabel="빈 스펠 슬롯" + icon={summonerSpellIconUrl(manifest, spellId)} + className={className} + imageClassName={imageClassName} + slotClassName={slotClassName} + > + + + ); +} + +export function RuneIcon({ + runeId, + manifest, + className = "h-5 w-5", + imageClassName = "", + slotClassName = "border border-base-content/5 bg-base-content/10", +}: ManifestIconProps & { runeId: number | undefined }) { + const rune = runeDetails(manifest, runeId); + const runeName = rune?.name ?? (runeId ? `룬 ${runeId}` : "룬"); + + return ( + + + + ); +} + +export function RuneStyleIcon({ + styleId, + manifest, + className = "h-5 w-5", + imageClassName = "", + slotClassName = "border border-base-content/5 bg-base-content/10", +}: ManifestIconProps & { styleId: number | undefined }) { + const style = runeStyleDetails(manifest, styleId); + const styleName = style?.name ?? (styleId ? `룬 ${styleId}` : "룬"); + + return ( + + + + ); +} + +function TooltipIcon({ + active, + label, + emptyLabel, + icon, + className, + imageClassName, + slotClassName, + children, +}: TooltipIconProps) { + const anchorRef = useRef(null); + const tooltipId = useId(); + const [open, setOpen] = useState(false); + return ( setOpen(false)} - onFocus={() => hasItem && setOpen(true)} - onMouseEnter={() => hasItem && setOpen(true)} + onFocus={() => active && setOpen(true)} + onMouseEnter={() => active && setOpen(true)} onMouseLeave={() => setOpen(false)} > - {hasItem && open ? ( - + {active && open ? ( + + {children} + ) : null} ); } -function ItemTooltipPortal({ +function TooltipPortal({ id, anchorRef, - itemId, - manifest, + children, }: { id: string; anchorRef: RefObject; - itemId: number; - manifest: DdragonManifest | null | undefined; + children: ReactNode; }) { const [position, setPosition] = useState(null); @@ -149,12 +269,94 @@ function ItemTooltipPortal({ style={style} className="pointer-events-none fixed z-[1000] border border-base-content/20 bg-black px-3 py-3 text-xs leading-relaxed text-white shadow-2xl" > - + {children}
, document.body, ); } +function SummonerSpellTooltipContent({ + spellId, + manifest, +}: { + spellId: number; + manifest: DdragonManifest | null | undefined; +}) { + const spell = summonerSpellDetails(manifest, spellId); + const descriptionHtml = spell?.description + ? safeDdragonDescriptionHtml(spell.description) + : ""; + + return ( +
+
+ {spell?.name ?? `스펠 ${spellId}`} +
+ {descriptionHtml ? ( +
+ ) : ( +
+ 스펠 상세 정보를 불러오는 중입니다. +
+ )} +
+ ); +} + +function RuneTooltipContent({ + runeId, + manifest, +}: { + runeId: number | undefined; + manifest: DdragonManifest | null | undefined; +}) { + const rune = runeDetails(manifest, runeId); + const descriptionHtml = rune?.longDesc + ? safeDdragonDescriptionHtml(rune.longDesc) + : ""; + + return ( +
+
+ {rune?.name ?? (runeId ? `룬 ${runeId}` : "룬")} +
+ {rune?.shortDesc ? ( +
{rune.shortDesc}
+ ) : null} + {descriptionHtml ? ( +
+ ) : ( +
룬 상세 정보를 불러오는 중입니다.
+ )} +
+ ); +} + +function RuneStyleTooltipContent({ + styleId, + manifest, +}: { + styleId: number | undefined; + manifest: DdragonManifest | null | undefined; +}) { + const style = runeStyleDetails(manifest, styleId); + + return ( +
+
+ {style?.name ?? (styleId ? `룬 ${styleId}` : "룬")} +
+
룬 스타일
+
+ ); +} + function ItemTooltipContent({ itemId, manifest, diff --git a/apps/web/src/lib/ddragon.ts b/apps/web/src/lib/ddragon.ts index 86756197..aabffdd4 100644 --- a/apps/web/src/lib/ddragon.ts +++ b/apps/web/src/lib/ddragon.ts @@ -98,21 +98,44 @@ export function summonerSpellIconUrl( return `${cdn(manifest)}/${version(manifest)}/img/spell/${spell.key}.png`; } +export function summonerSpellDetails( + manifest: DdragonManifest | null | undefined, + spellId: number, +) { + if (!spellId) return null; + return manifest?.summonerSpells[String(spellId)] ?? null; +} + +export function runeStyleDetails( + manifest: DdragonManifest | null | undefined, + styleId: number | undefined, +) { + return manifest?.runesReforged.find((entry) => entry.id === styleId) ?? null; +} + export function runeStyleIconUrl( manifest: DdragonManifest | null | undefined, styleId: number | undefined, ) { - const style = manifest?.runesReforged.find((entry) => entry.id === styleId); + const style = runeStyleDetails(manifest, styleId); return style ? `${cdn(manifest)}/img/${style.icon}` : null; } +export function runeDetails( + manifest: DdragonManifest | null | undefined, + runeId: number | undefined, +) { + if (!runeId) return null; + return manifest?.runesReforged + .flatMap((style) => style.slots.flatMap((slot) => slot.runes)) + .find((entry) => entry.id === runeId) ?? null; +} + export function runeKeystoneIconUrl( manifest: DdragonManifest | null | undefined, runeId: number | undefined, ) { - const rune = manifest?.runesReforged - .flatMap((style) => style.slots.flatMap((slot) => slot.runes)) - .find((entry) => entry.id === runeId); + const rune = runeDetails(manifest, runeId); return rune ? `${cdn(manifest)}/img/${rune.icon}` : null; } diff --git a/apps/web/src/pages/MatchGameDetailPage.tsx b/apps/web/src/pages/MatchGameDetailPage.tsx index b40dd4f7..9ccbd39b 100644 --- a/apps/web/src/pages/MatchGameDetailPage.tsx +++ b/apps/web/src/pages/MatchGameDetailPage.tsx @@ -17,9 +17,6 @@ import { DEFAULT_COMMUNITY_ID } from "../config"; import { championDisplayName, championIconUrl, - runeKeystoneIconUrl, - runeStyleIconUrl, - summonerSpellIconUrl, } from "../lib/ddragon"; import { sideShortLabel, @@ -36,7 +33,12 @@ import { InternalGameDetailTabBar, type InternalGameDetailTab, } from "../components/InternalGameAnalysisTabs"; -import { ItemIcon } from "../components/ItemTooltip"; +import { + ItemIcon, + RuneIcon, + RuneStyleIcon, + SummonerSpellIcon, +} from "../components/ItemTooltip"; type MatchGameDetail = ApiInternalMatchDetailResponse["games"][number]; type MatchGameTeam = MatchGameDetail["teams"][number]; @@ -258,47 +260,23 @@ function SpellRuneStrip({ participant: MatchGameParticipant; manifest: ReturnType["data"]; }) { - const spellIcons = participant.summonerSpells - .map((spellId) => summonerSpellIconUrl(manifest, spellId)) - .filter((icon): icon is string => Boolean(icon)); - const runeIcons = [ - runeKeystoneIconUrl(manifest, participant.perks.keystone), - runeStyleIconUrl(manifest, participant.perks.subStyle), - ].filter((icon): icon is string => Boolean(icon)); - return (
{[0, 1].map((index) => ( - - {spellIcons[index] ? ( - - ) : null} - + spellId={participant.summonerSpells[index] ?? 0} + manifest={manifest} + /> ))}
- {[0, 1].map((index) => ( - - {runeIcons[index] ? ( - - ) : null} - - ))} + +
); diff --git a/apps/web/src/pages/UserHistoryPage.tsx b/apps/web/src/pages/UserHistoryPage.tsx index 5192a529..e06f3611 100644 --- a/apps/web/src/pages/UserHistoryPage.tsx +++ b/apps/web/src/pages/UserHistoryPage.tsx @@ -32,9 +32,6 @@ import { championDisplayName, championIconUrl, profileIconUrl, - runeKeystoneIconUrl, - runeStyleIconUrl, - summonerSpellIconUrl, } from "../lib/ddragon"; import { isRiotQueueGroup, @@ -49,7 +46,12 @@ import { InternalGameDetailTabBar, type InternalGameDetailTab, } from "../components/InternalGameAnalysisTabs"; -import { ItemIcon } from "../components/ItemTooltip"; +import { + ItemIcon, + RuneIcon, + RuneStyleIcon, + SummonerSpellIcon, +} from "../components/ItemTooltip"; // recharts가 무거워 메인 번들에서 분리한다 (전적 페이지에서만 로드). const TierHistoryChart = lazy(() => import("../components/TierHistoryChart")); @@ -482,33 +484,6 @@ function barPercent(value: number, max: number) { 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, @@ -520,25 +495,12 @@ function LoadoutIcons({ }) { return (
- - - - + + +
); @@ -654,24 +616,25 @@ function ParticipantRow({ )}
- - - -