From: Daniel Karbach Date: Thu, 28 Mar 2024 12:35:51 +0000 (+0100) Subject: add zelda icon SVG support X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=7a73d355a9f387b1bae2e218af8a7d4d0aab0c0c;p=alttp.git add zelda icon SVG support --- diff --git a/resources/js/components/common/ZeldaIcon.js b/resources/js/components/common/ZeldaIcon.js index 13efe31..230b14e 100644 --- a/resources/js/components/common/ZeldaIcon.js +++ b/resources/js/components/common/ZeldaIcon.js @@ -90,10 +90,13 @@ const ITEM_MAP = [ const isOnItemMap = name => ITEM_MAP.includes(name); +const getItemMapX = name => ITEM_MAP.indexOf(name) % 8; + +const getItemMapY = name => Math.floor(ITEM_MAP.indexOf(name) / 8); + const getItemMapStyle = name => { - const index = ITEM_MAP.indexOf(name); - const x = index % 8; - const y = Math.floor(index / 8); + const x = getItemMapX(name); + const y = getItemMapY(name); return { backgroundPosition: `-${x * 100}% -${y * 100}%` }; }; @@ -122,7 +125,7 @@ const getIconURL = name => { } }; -const ZeldaIcon = ({ name, title }) => { +const ZeldaIcon = ({ name, svg, title }) => { const { t } = useTranslation(); const invert = name.startsWith('not-'); @@ -131,6 +134,24 @@ const ZeldaIcon = ({ name, title }) => { const alt = t(`icon.zelda.${name}`); const realTitle = title !== '' ? title || alt : null; + if (svg) { + const clipX = getItemMapX(strippedName); + const clipY = getItemMapY(strippedName); + return + {realTitle ? + {realTitle} + : null} + ; + } + return {isOnItemMap(strippedName) ? { ZeldaIcon.propTypes = { name: PropTypes.string.isRequired, + svg: PropTypes.bool, title: PropTypes.string, };