X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=resources%2Fjs%2Fcomponents%2Fcommon%2FZeldaIcon.js;h=13efe31d87498d24c81b94ff3e46c4b1fab3a341;hb=5fe70ee6bc5380c556169756a375956799093604;hp=84f2220672ce3e622031b96ea6064325df774ec8;hpb=2110d91bc5016fd78aec02578b09506b6d67f45e;p=alttp.git
diff --git a/resources/js/components/common/ZeldaIcon.js b/resources/js/components/common/ZeldaIcon.js
index 84f2220..13efe31 100644
--- a/resources/js/components/common/ZeldaIcon.js
+++ b/resources/js/components/common/ZeldaIcon.js
@@ -1,80 +1,162 @@
import PropTypes from 'prop-types';
import React from 'react';
-import { withTranslation } from 'react-i18next';
+import { useTranslation } from 'react-i18next';
-import i18n from '../../i18n';
+import Icon from './Icon';
+
+const ITEM_MAP = [
+ 'aga',
+ 'armos',
+ 'arrghus',
+ 'big-key',
+ 'blind',
+ 'blue-boomerang',
+ 'blue-mail',
+ 'blue-pendant',
+ 'blue-potion',
+ 'bombos',
+ 'bomb',
+ 'book',
+ 'boots',
+ 'bottle-bee',
+ 'bottle',
+ 'bowless-silvers',
+ 'bow',
+ 'bugnet',
+ 'byrna',
+ 'cape',
+ 'chest',
+ 'compass',
+ 'crystal',
+ 'duck',
+ 'ether',
+ 'fairy',
+ 'fighter-shield',
+ 'fighter-sword',
+ 'fire-rod',
+ 'fire-shield',
+ 'flippers',
+ 'flute',
+ 'glove',
+ 'gold-sword',
+ 'green-mail',
+ 'green-pendant',
+ 'green-potion',
+ 'half-magic',
+ 'hammer',
+ 'heart-0',
+ 'heart-1',
+ 'heart-2',
+ 'heart-3',
+ 'heart-container',
+ 'heart-piece',
+ 'helma',
+ 'hookshot',
+ 'ice-rod',
+ 'kholdstare',
+ 'lamp',
+ 'lanmolas',
+ 'map',
+ 'master-sword',
+ 'mirror',
+ 'mirror-shield',
+ 'mitts',
+ 'moldorm',
+ 'moonpearl',
+ 'mothula',
+ 'mushroom',
+ 'open-chest',
+ 'powder',
+ 'quake',
+ 'quarter-magic',
+ 'red-bomb',
+ 'red-boomerang',
+ 'red-crystal',
+ 'red-mail',
+ 'red-pendant',
+ 'red-potion',
+ 'shovel',
+ 'silvers',
+ 'small-key',
+ 'somaria',
+ 'sword-1',
+ 'sword-2',
+ 'sword-3',
+ 'sword-4',
+ 'tempered-sword',
+ 'trinexx',
+ 'vitreous',
+];
+
+const isOnItemMap = name => ITEM_MAP.includes(name);
+
+const getItemMapStyle = name => {
+ const index = ITEM_MAP.indexOf(name);
+ const x = index % 8;
+ const y = Math.floor(index / 8);
+ return { backgroundPosition: `-${x * 100}% -${y * 100}%` };
+};
const getIconURL = name => {
switch (name) {
- case 'big-key':
- case 'blue-boomerang':
- case 'blue-mail':
- case 'blue-pendant':
- case 'blue-potion':
- case 'bombos':
- case 'bomb':
- case 'book':
- case 'boots':
- case 'bottle-bee':
- case 'bottle':
- case 'bow':
- case 'bugnet':
- case 'byrna':
- case 'cape':
- case 'compass':
- case 'crystal':
- case 'duck':
- case 'ether':
- case 'fairy':
- case 'fighter-shield':
- case 'fire-rod':
- case 'fire-shield':
- case 'flippers':
- case 'flute':
- case 'glove':
- case 'green-mail':
- case 'green-pendant':
- case 'green-potion':
- case 'hammer':
- case 'heart-container':
- case 'heart-piece':
- case 'hookshot':
- case 'ice-rod':
- case 'lamp':
- case 'map':
- case 'mirror':
- case 'mirror-shield':
- case 'mitts':
- case 'moonpearl':
- case 'mushroom':
- case 'powder':
- case 'quake':
- case 'red-bomb':
- case 'red-boomerang':
- case 'red-mail':
- case 'red-pendant':
- case 'red-potion':
- case 'shovel':
- case 'silvers':
- case 'small-key':
- case 'somaria':
- return `/item/${name}.png`;
+ case 'dungeon-ct':
+ case 'dungeon-dp':
+ case 'dungeon-ep':
+ case 'dungeon-gt':
+ case 'dungeon-hc':
+ case 'dungeon-ip':
+ case 'dungeon-mm':
+ case 'dungeon-pd':
+ case 'dungeon-sp':
+ case 'dungeon-sw':
+ case 'dungeon-th':
+ case 'dungeon-tr':
+ case 'dungeon-tt':
+ return `/dungeon/${name.substr(8)}.png`;
+ case 'crystal-switch':
+ case 'crystal-switch-blue':
+ case 'crystal-switch-red':
+ return `/icon/${name}.png`;
default:
return '';
}
};
-const ZeldaIcon = ({ name }) =>
-
-
-;
+const ZeldaIcon = ({ name, title }) => {
+ const { t } = useTranslation();
+
+ const invert = name.startsWith('not-');
+ const strippedName = invert ? name.substr(4) : name;
+ const src = getIconURL(strippedName);
+ const alt = t(`icon.zelda.${name}`);
+ const realTitle = title !== '' ? title || alt : null;
+
+ return
+ {isOnItemMap(strippedName) ?
+
+ : null}
+ {src ?
+
+ : null}
+ {invert ?
+
+
+
+ : null}
+ ;
+};
ZeldaIcon.propTypes = {
- name: PropTypes.string,
+ name: PropTypes.string.isRequired,
+ title: PropTypes.string,
};
-export default withTranslation()(ZeldaIcon);
+export default ZeldaIcon;