]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/common/ZeldaIcon.js
c5da0b554cbc242322ea3f8c2ab0a2510c50a23f
[alttp.git] / resources / js / components / common / ZeldaIcon.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { useTranslation } from 'react-i18next';
4
5 import Icon from './Icon';
6
7 const getIconURL = name => {
8         switch (name) {
9                 case 'big-key':
10                 case 'blue-boomerang':
11                 case 'blue-mail':
12                 case 'blue-pendant':
13                 case 'blue-potion':
14                 case 'bombos':
15                 case 'bomb':
16                 case 'book':
17                 case 'boots':
18                 case 'bottle-bee':
19                 case 'bottle':
20                 case 'bow':
21                 case 'bugnet':
22                 case 'byrna':
23                 case 'cape':
24                 case 'compass':
25                 case 'crystal':
26                 case 'duck':
27                 case 'ether':
28                 case 'fairy':
29                 case 'fighter-shield':
30                 case 'fighter-sword':
31                 case 'fire-rod':
32                 case 'fire-shield':
33                 case 'flippers':
34                 case 'flute':
35                 case 'glove':
36                 case 'green-mail':
37                 case 'green-pendant':
38                 case 'green-potion':
39                 case 'hammer':
40                 case 'heart-container':
41                 case 'heart-piece':
42                 case 'hookshot':
43                 case 'ice-rod':
44                 case 'lamp':
45                 case 'map':
46                 case 'mirror':
47                 case 'mirror-shield':
48                 case 'mitts':
49                 case 'moonpearl':
50                 case 'mushroom':
51                 case 'powder':
52                 case 'quake':
53                 case 'red-bomb':
54                 case 'red-boomerang':
55                 case 'red-mail':
56                 case 'red-pendant':
57                 case 'red-potion':
58                 case 'shovel':
59                 case 'silvers':
60                 case 'small-key':
61                 case 'somaria':
62                         return `/item/${name}.png`;
63                 case 'dungeon-ct':
64                 case 'dungeon-dp':
65                 case 'dungeon-ep':
66                 case 'dungeon-gt':
67                 case 'dungeon-hc':
68                 case 'dungeon-ip':
69                 case 'dungeon-mm':
70                 case 'dungeon-pd':
71                 case 'dungeon-sp':
72                 case 'dungeon-sw':
73                 case 'dungeon-th':
74                 case 'dungeon-tr':
75                 case 'dungeon-tt':
76                         return `/dungeon/${name.substr(8)}.png`;
77                 default:
78                         return '';
79         }
80 };
81
82 const ZeldaIcon = ({ name }) => {
83         const { t } = useTranslation();
84
85         const invert = name.startsWith('not-');
86         const strippedName = invert ? name.substr(4) : name;
87         const title = t(`icon.zelda.${name}`);
88
89         return <span className="zelda-icon">
90                 <img
91                         alt={title}
92                         src={getIconURL(strippedName)}
93                         title={title}
94                 />
95                 {invert ?
96                         <span className="strike">
97                                 <Icon.SLASH title="" />
98                         </span>
99                 : null}
100         </span>;
101 };
102
103 ZeldaIcon.propTypes = {
104         name: PropTypes.string,
105 };
106
107 export default ZeldaIcon;