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}%` };
};
}
};
-const ZeldaIcon = ({ name, title }) => {
+const ZeldaIcon = ({ name, svg, title }) => {
const { t } = useTranslation();
const invert = name.startsWith('not-');
const alt = t(`icon.zelda.${name}`);
const realTitle = title !== '' ? title || alt : null;
+ if (svg) {
+ const clipX = getItemMapX(strippedName);
+ const clipY = getItemMapY(strippedName);
+ return <image
+ href={isOnItemMap(strippedName) ? '/items-v1.png' : src}
+ width="8"
+ height="11"
+ x="0"
+ y="0"
+ transform={`translate(-${clipX} -${clipY})`}
+ clipPath={`xywh(${clipX + 0.02} ${clipY + 0.02} 0.96 0.96)`}
+ >
+ {realTitle ?
+ <title>{realTitle}</title>
+ : null}
+ </image>;
+ }
+
return <span className="zelda-icon">
{isOnItemMap(strippedName) ?
<span
ZeldaIcon.propTypes = {
name: PropTypes.string.isRequired,
+ svg: PropTypes.bool,
title: PropTypes.string,
};