feat: add spell and rune tooltips
This commit is contained in:
1 parent
4906f665fd
commit
292e37aaac
8 files changed
+404
-161
No files matched your search
@@ -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: '<span>커서 방향으로 순간이동합니다.</span>',
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
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:
|
||||
'<lol-uikit-tooltipped-keyword>기본 공격</lol-uikit-tooltipped-keyword>으로 적을 약화시킵니다.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
}
|
||||
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: '<span>커서 방향으로 순간이동합니다.</span>',
|
||||
},
|
||||
},
|
||||
runesReforged: [
|
||||
{
|
||||
id: 8000,
|
||||
name: '정밀',
|
||||
slots: [
|
||||
{
|
||||
runes: [
|
||||
{
|
||||
id: 8005,
|
||||
name: '집중 공격',
|
||||
shortDesc: '연속 공격 시 추가 피해',
|
||||
longDesc:
|
||||
'<lol-uikit-tooltipped-keyword>기본 공격</lol-uikit-tooltipped-keyword>으로 적을 약화시킵니다.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
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: '도란의 검' }),
|
||||
}),
|
||||
|
||||
@@ -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 : '',
|
||||
})),
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 (
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="h-6 w-6 overflow-hidden bg-base-content/10">
|
||||
{styleIcon ? (
|
||||
<img
|
||||
src={styleIcon}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<RuneStyleIcon
|
||||
styleId={runeStyle.id}
|
||||
manifest={manifest}
|
||||
className="h-6 w-6"
|
||||
slotClassName="bg-base-content/10"
|
||||
/>
|
||||
<div className="min-w-0">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
{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 (
|
||||
<span
|
||||
<RuneIcon
|
||||
key={rune.id}
|
||||
title={rune.name}
|
||||
className={`${iconSize} overflow-hidden border bg-base-content/10 transition ${
|
||||
runeId={rune.id}
|
||||
manifest={manifest}
|
||||
className={iconSize}
|
||||
slotClassName={`border bg-base-content/10 transition ${
|
||||
selected
|
||||
? "border-transparent opacity-100 ring-1 ring-primary/60"
|
||||
: "border-transparent opacity-20 grayscale"
|
||||
}`}
|
||||
>
|
||||
{icon ? (
|
||||
<img
|
||||
src={icon}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
@@ -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<HTMLSpanElement>(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 (
|
||||
<TooltipIcon
|
||||
active={hasItem}
|
||||
label={itemName}
|
||||
emptyLabel="빈 아이템 슬롯"
|
||||
icon={icon}
|
||||
className={className}
|
||||
imageClassName={imageClassName}
|
||||
slotClassName={`border ${slotTone}`}
|
||||
>
|
||||
<ItemTooltipContent itemId={itemId} manifest={manifest} />
|
||||
</TooltipIcon>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<TooltipIcon
|
||||
active={spellId > 0}
|
||||
label={spellName}
|
||||
emptyLabel="빈 스펠 슬롯"
|
||||
icon={summonerSpellIconUrl(manifest, spellId)}
|
||||
className={className}
|
||||
imageClassName={imageClassName}
|
||||
slotClassName={slotClassName}
|
||||
>
|
||||
<SummonerSpellTooltipContent spellId={spellId} manifest={manifest} />
|
||||
</TooltipIcon>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<TooltipIcon
|
||||
active={Boolean(runeId)}
|
||||
label={runeName}
|
||||
emptyLabel="빈 룬 슬롯"
|
||||
icon={runeIconUrl(manifest, runeId)}
|
||||
className={className}
|
||||
imageClassName={imageClassName}
|
||||
slotClassName={slotClassName}
|
||||
>
|
||||
<RuneTooltipContent runeId={runeId} manifest={manifest} />
|
||||
</TooltipIcon>
|
||||
);
|
||||
}
|
||||
|
||||
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 (
|
||||
<TooltipIcon
|
||||
active={Boolean(styleId)}
|
||||
label={styleName}
|
||||
emptyLabel="빈 룬 슬롯"
|
||||
icon={runeStyleIconUrl(manifest, styleId)}
|
||||
className={className}
|
||||
imageClassName={imageClassName}
|
||||
slotClassName={slotClassName}
|
||||
>
|
||||
<RuneStyleTooltipContent styleId={styleId} manifest={manifest} />
|
||||
</TooltipIcon>
|
||||
);
|
||||
}
|
||||
|
||||
function TooltipIcon({
|
||||
active,
|
||||
label,
|
||||
emptyLabel,
|
||||
icon,
|
||||
className,
|
||||
imageClassName,
|
||||
slotClassName,
|
||||
children,
|
||||
}: TooltipIconProps) {
|
||||
const anchorRef = useRef<HTMLSpanElement>(null);
|
||||
const tooltipId = useId();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
return (
|
||||
<span
|
||||
ref={anchorRef}
|
||||
className={`relative inline-flex shrink-0 ${className}`}
|
||||
role={hasItem ? "img" : undefined}
|
||||
tabIndex={hasItem ? 0 : undefined}
|
||||
aria-label={hasItem ? itemName : "빈 아이템 슬롯"}
|
||||
aria-describedby={hasItem && open ? tooltipId : undefined}
|
||||
role={active ? "img" : undefined}
|
||||
tabIndex={active ? 0 : undefined}
|
||||
aria-label={active ? label : emptyLabel}
|
||||
aria-describedby={active && open ? tooltipId : undefined}
|
||||
onBlur={() => setOpen(false)}
|
||||
onFocus={() => hasItem && setOpen(true)}
|
||||
onMouseEnter={() => hasItem && setOpen(true)}
|
||||
onFocus={() => active && setOpen(true)}
|
||||
onMouseEnter={() => active && setOpen(true)}
|
||||
onMouseLeave={() => setOpen(false)}
|
||||
>
|
||||
<span
|
||||
className={`block h-full w-full overflow-hidden border ${slotTone}`}
|
||||
className={`block h-full w-full overflow-hidden ${slotClassName}`}
|
||||
aria-hidden="true"
|
||||
>
|
||||
{icon ? (
|
||||
@@ -71,28 +196,23 @@ export function ItemIcon({
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
{hasItem && open ? (
|
||||
<ItemTooltipPortal
|
||||
id={tooltipId}
|
||||
anchorRef={anchorRef}
|
||||
itemId={itemId}
|
||||
manifest={manifest}
|
||||
/>
|
||||
{active && open ? (
|
||||
<TooltipPortal id={tooltipId} anchorRef={anchorRef}>
|
||||
{children}
|
||||
</TooltipPortal>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function ItemTooltipPortal({
|
||||
function TooltipPortal({
|
||||
id,
|
||||
anchorRef,
|
||||
itemId,
|
||||
manifest,
|
||||
children,
|
||||
}: {
|
||||
id: string;
|
||||
anchorRef: RefObject<HTMLElement | null>;
|
||||
itemId: number;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [position, setPosition] = useState<TooltipPosition | null>(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"
|
||||
>
|
||||
<ItemTooltipContent itemId={itemId} manifest={manifest} />
|
||||
{children}
|
||||
</div>,
|
||||
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 (
|
||||
<div className="space-y-2">
|
||||
<div className="font-black text-[#f0d878]">
|
||||
{spell?.name ?? `스펠 ${spellId}`}
|
||||
</div>
|
||||
{descriptionHtml ? (
|
||||
<div
|
||||
className="text-white/80 [&_br]:block [&_br]:content-['']"
|
||||
dangerouslySetInnerHTML={{ __html: descriptionHtml }}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-white/55">
|
||||
스펠 상세 정보를 불러오는 중입니다.
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RuneTooltipContent({
|
||||
runeId,
|
||||
manifest,
|
||||
}: {
|
||||
runeId: number | undefined;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
}) {
|
||||
const rune = runeDetails(manifest, runeId);
|
||||
const descriptionHtml = rune?.longDesc
|
||||
? safeDdragonDescriptionHtml(rune.longDesc)
|
||||
: "";
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="font-black text-[#f0d878]">
|
||||
{rune?.name ?? (runeId ? `룬 ${runeId}` : "룬")}
|
||||
</div>
|
||||
{rune?.shortDesc ? (
|
||||
<div className="font-bold text-white">{rune.shortDesc}</div>
|
||||
) : null}
|
||||
{descriptionHtml ? (
|
||||
<div
|
||||
className="text-white/80 [&_br]:block [&_br]:content-['']"
|
||||
dangerouslySetInnerHTML={{ __html: descriptionHtml }}
|
||||
/>
|
||||
) : (
|
||||
<div className="text-white/55">룬 상세 정보를 불러오는 중입니다.</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RuneStyleTooltipContent({
|
||||
styleId,
|
||||
manifest,
|
||||
}: {
|
||||
styleId: number | undefined;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
}) {
|
||||
const style = runeStyleDetails(manifest, styleId);
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<div className="font-black text-[#f0d878]">
|
||||
{style?.name ?? (styleId ? `룬 ${styleId}` : "룬")}
|
||||
</div>
|
||||
<div className="text-white/55">룬 스타일</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ItemTooltipContent({
|
||||
itemId,
|
||||
manifest,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<typeof useDdragonManifest>["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 (
|
||||
<div className="flex items-center gap-1.5">
|
||||
<div className="grid grid-cols-1 gap-0.5">
|
||||
{[0, 1].map((index) => (
|
||||
<span
|
||||
<SummonerSpellIcon
|
||||
key={`spell-${index}`}
|
||||
className="h-5 w-5 overflow-hidden bg-base-content/10"
|
||||
>
|
||||
{spellIcons[index] ? (
|
||||
<img
|
||||
src={spellIcons[index]}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
spellId={participant.summonerSpells[index] ?? 0}
|
||||
manifest={manifest}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<div className="grid grid-cols-1 gap-0.5">
|
||||
{[0, 1].map((index) => (
|
||||
<span
|
||||
key={`rune-${index}`}
|
||||
className="h-5 w-5 overflow-hidden bg-base-content/10"
|
||||
>
|
||||
{runeIcons[index] ? (
|
||||
<img
|
||||
src={runeIcons[index]}
|
||||
alt=""
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
))}
|
||||
<RuneIcon runeId={participant.perks.keystone} manifest={manifest} />
|
||||
<RuneStyleIcon
|
||||
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
|
||||
manifest={manifest}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -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 (
|
||||
<div
|
||||
className={`${className} bg-base-content/8 overflow-hidden border border-base-content/5`}
|
||||
title={label}
|
||||
aria-label={label}
|
||||
>
|
||||
{url ? (
|
||||
<img
|
||||
src={url}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LoadoutIcons({
|
||||
summonerSpells,
|
||||
perks,
|
||||
@@ -520,25 +495,12 @@ function LoadoutIcons({
|
||||
}) {
|
||||
return (
|
||||
<div className="grid grid-cols-2 gap-0.5 shrink-0">
|
||||
<AssetIcon
|
||||
url={summonerSpellIconUrl(manifest, summonerSpells[0])}
|
||||
label="스펠 1"
|
||||
className="w-5 h-5"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={runeKeystoneIconUrl(manifest, perks.keystone)}
|
||||
label="핵심 룬"
|
||||
className="w-5 h-5"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={summonerSpellIconUrl(manifest, summonerSpells[1])}
|
||||
label="스펠 2"
|
||||
className="w-5 h-5"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={runeStyleIconUrl(manifest, perks.subStyle ?? perks.primaryStyle)}
|
||||
label="보조 룬"
|
||||
className="w-5 h-5"
|
||||
<SummonerSpellIcon spellId={summonerSpells[0]} manifest={manifest} />
|
||||
<RuneIcon runeId={perks.keystone} manifest={manifest} />
|
||||
<SummonerSpellIcon spellId={summonerSpells[1]} manifest={manifest} />
|
||||
<RuneStyleIcon
|
||||
styleId={perks.subStyle ?? perks.primaryStyle}
|
||||
manifest={manifest}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -654,24 +616,25 @@ function ParticipantRow({
|
||||
)}
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-0.5 shrink-0">
|
||||
<AssetIcon
|
||||
url={summonerSpellIconUrl(manifest, participant.summonerSpells[0])}
|
||||
label="스펠 1"
|
||||
<SummonerSpellIcon
|
||||
spellId={participant.summonerSpells[0]}
|
||||
manifest={manifest}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={runeKeystoneIconUrl(manifest, participant.perks.keystone)}
|
||||
label="핵심 룬"
|
||||
<RuneIcon
|
||||
runeId={participant.perks.keystone}
|
||||
manifest={manifest}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={summonerSpellIconUrl(manifest, participant.summonerSpells[1])}
|
||||
label="스펠 2"
|
||||
<SummonerSpellIcon
|
||||
spellId={participant.summonerSpells[1]}
|
||||
manifest={manifest}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
<AssetIcon
|
||||
url={runeStyleIconUrl(
|
||||
manifest,
|
||||
participant.perks.subStyle ?? participant.perks.primaryStyle,
|
||||
)}
|
||||
label="보조 룬"
|
||||
<RuneStyleIcon
|
||||
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
|
||||
manifest={manifest}
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
|
||||
Reference in new issue
Block a user