1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { useTranslation } from 'react-i18next';
5 import Icon from './Icon';
33 'crystal-switch-blue',
101 const ITEM_MAP_WIDTH = 8;
103 const ITEM_MAP_HEIGHT = Math.ceil(ITEM_MAP.length / ITEM_MAP_WIDTH);
105 const ITEM_MAP_URL = '/items-v2.png';
107 const isOnItemMap = name => ITEM_MAP.includes(name);
109 const getItemMapX = name => ITEM_MAP.indexOf(name) % ITEM_MAP_WIDTH;
111 const getItemMapY = name => Math.floor(ITEM_MAP.indexOf(name) / ITEM_MAP_WIDTH);
113 const getItemMapStyle = name => {
114 const x = getItemMapX(name);
115 const y = getItemMapY(name);
117 backgroundImage: `url(${ITEM_MAP_URL})`,
118 backgroundPosition: `-${x * 100}% -${y * 100}%`,
119 backgroundSize: `${ITEM_MAP_WIDTH * 100}% ${ITEM_MAP_HEIGHT * 100}%`,
123 const getIconURL = name => {
138 return `/dungeon/${name.substr(8)}.png`;
144 const isHalfWidth = name => [
152 const ZeldaIcon = ({ name, svg, title }) => {
153 const { t } = useTranslation();
155 const invert = name.startsWith('not-');
156 const strippedName = invert ? name.substr(4) : name;
157 const src = getIconURL(strippedName);
158 const alt = t(`icon.zelda.${name}`);
159 const realTitle = title !== '' ? title || alt : null;
162 const clipX = getItemMapX(strippedName);
163 const clipY = getItemMapY(strippedName);
164 const cropX = isHalfWidth(strippedName) ? 0.25 : 0.02;
166 const cropW = 1 - (2 * cropX);
167 const cropH = 1 - (2 * cropY);
169 href={isOnItemMap(strippedName) ? ITEM_MAP_URL : src}
170 width={ITEM_MAP_WIDTH}
171 height={ITEM_MAP_HEIGHT}
174 transform={`translate(-${clipX + 0.5} -${clipY + 0.5})`}
175 clipPath={`xywh(${clipX + cropX} ${clipY + cropY} ${cropW} ${cropH})`}
178 <title>{realTitle}</title>
183 return <span className="zelda-icon">
184 {isOnItemMap(strippedName) ?
186 className="item-map-icon"
187 style={getItemMapStyle(strippedName)}
199 <span className="strike">
200 <Icon.SLASH title="" />
206 ZeldaIcon.propTypes = {
207 name: PropTypes.string.isRequired,
209 title: PropTypes.string,
212 export default ZeldaIcon;