72 lines
2.1 KiB
TypeScript
72 lines
2.1 KiB
TypeScript
import type { DdragonManifest } from '../api/types';
|
|
|
|
const FALLBACK_VERSION = '15.24.1';
|
|
const FALLBACK_CDN = 'https://ddragon.leagueoflegends.com/cdn';
|
|
|
|
function cdn(manifest: DdragonManifest | null | undefined) {
|
|
return manifest?.cdn ?? FALLBACK_CDN;
|
|
}
|
|
|
|
function version(manifest: DdragonManifest | null | undefined) {
|
|
return manifest?.version ?? FALLBACK_VERSION;
|
|
}
|
|
|
|
export function championDisplayName(
|
|
manifest: DdragonManifest | null | undefined,
|
|
championId: number,
|
|
) {
|
|
return manifest?.champions[String(championId)]?.name ?? null;
|
|
}
|
|
|
|
export function championIconUrl(
|
|
manifest: DdragonManifest | null | undefined,
|
|
championId: number,
|
|
) {
|
|
const champion = manifest?.champions[String(championId)];
|
|
if (!champion) return null;
|
|
return `${cdn(manifest)}/${version(manifest)}/img/champion/${champion.key}.png`;
|
|
}
|
|
|
|
export function profileIconUrl(
|
|
manifest: DdragonManifest | null | undefined,
|
|
profileIconId: number,
|
|
) {
|
|
return `${cdn(manifest)}/${version(manifest)}/img/profileicon/${profileIconId}.png`;
|
|
}
|
|
|
|
export function itemIconUrl(
|
|
manifest: DdragonManifest | null | undefined,
|
|
itemId: number,
|
|
) {
|
|
if (!itemId) return null;
|
|
return `${cdn(manifest)}/${version(manifest)}/img/item/${itemId}.png`;
|
|
}
|
|
|
|
export function summonerSpellIconUrl(
|
|
manifest: DdragonManifest | null | undefined,
|
|
spellId: number,
|
|
) {
|
|
const spell = manifest?.summonerSpells[String(spellId)];
|
|
if (!spell) return null;
|
|
return `${cdn(manifest)}/${version(manifest)}/img/spell/${spell.key}.png`;
|
|
}
|
|
|
|
export function runeStyleIconUrl(
|
|
manifest: DdragonManifest | null | undefined,
|
|
styleId: number | undefined,
|
|
) {
|
|
const style = manifest?.runesReforged.find((entry) => entry.id === styleId);
|
|
return style ? `${cdn(manifest)}/img/${style.icon}` : 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);
|
|
|
|
return rune ? `${cdn(manifest)}/img/${rune.icon}` : null;
|
|
}
|