]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/rounds/SeedCodeInput.js
basic seed code input
[alttp.git] / resources / js / components / rounds / SeedCodeInput.js
1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Form } from 'react-bootstrap';
4 import { withTranslation } from 'react-i18next';
5
6 import i18n from '../../i18n';
7
8 const ALTTPR_CODES = [
9         'big-key',
10         'bow',
11         'blue-boomerang',
12         'bomb',
13         'bombos',
14         'book',
15         'boots',
16         'bottle',
17         'bow',
18         'bugnet',
19         'cape',
20         'compass',
21         'ether',
22         'flippers',
23         'flute',
24         'glove',
25         'green-mail',
26         'green-pendant',
27         'green-potion',
28         'hammer',
29         'heart-container',
30         'hookshot',
31         'ice-rod',
32         'lamp',
33         'map',
34         'mirror',
35         'mirror-shield',
36         'moonpearl',
37         'mushroom',
38         'powder',
39         'quake',
40         'shovel',
41 ];
42
43 const SMR_CODES = [
44         'ALCOON',
45         'ATOMIC',
46         'BEETOM',
47         'BOYON',
48         'BULL',
49         'CHOOT',
50         'COVERN',
51         'EVIR',
52         'FUNE',
53         'GAMET',
54         'GEEMER',
55         'GERUTA',
56         'HOLTZ',
57         'KAGO',
58         'NAMIHE',
59         'OUM',
60         'OWTCH',
61         'POWAMP',
62         'PUROMI',
63         'PUYO',
64         'RINKA',
65         'RIPPER',
66         'SCISER',
67         'SKREE',
68         'SOVA',
69         'TATORI',
70         'VIOLA',
71         'WAVER',
72         'YARD',
73         'ZEBBO',
74         'ZEELA',
75         'ZOA',
76 ];
77
78 const SeedCodeInput = ({
79         className,
80         game,
81         name,
82         onBlur,
83         onChange,
84         value,
85 }) => {
86         if (game === 'alttpr') {
87                 const code_trans = ALTTPR_CODES
88                         .map(code => ({ code, label: i18n.t(`icon.zelda.${code}`)}))
89                         .sort((a, b) => a.label.localeCompare(b.label));
90                 return <div
91                         className={`${className} seed-code-input-alttpr`}
92                 >
93                         {[0, 1, 2, 3, 4].map(num =>
94                                 <Form.Select
95                                         key={num}
96                                         onBlur={onBlur}
97                                         onChange={onChange}
98                                         name={`${name}[${num}]`}
99                                         value={(value && value[num]) || ''}
100                                 >
101                                         <option value=""></option>
102                                         {code_trans.map(({ code, label }) =>
103                                                 <option key={code} value={code}>{label}</option>
104                                         )}
105                                 </Form.Select>
106                         )}
107                 </div>;
108         }
109         if (game === 'smr') {
110                 return <div
111                         className={`${className} seed-code-input-smr`}
112                 >
113                         {[0, 1, 2, 3].map(num =>
114                                 <Form.Select
115                                         key={num}
116                                         onBlur={onBlur}
117                                         onChange={onChange}
118                                         name={`${name}[${num}]`}
119                                         value={(value && value[num]) || ''}
120                                 >
121                                         <option value=""></option>
122                                         {SMR_CODES.sort((a, b) => a.localeCompare(b)).map(code =>
123                                                 <option key={code} value={code}>{code}</option>
124                                         )}
125                                 </Form.Select>
126                         )}
127                 </div>;
128         }
129         return <div
130                 className={`${className} seed-code-input-default`}
131         >
132                 {[0, 1, 2, 3, 4].map(num =>
133                         <Form.Control
134                                 key={num}
135                                 onBlur={onBlur}
136                                 onChange={onChange}
137                                 name={`${name}[${num}]`}
138                                 value={(value && value[num]) || ''}
139                         />
140                 )}
141         </div>;
142 };
143
144 SeedCodeInput.propTypes = {
145         className: PropTypes.string,
146         game: PropTypes.string,
147         name: PropTypes.string,
148         onBlur: PropTypes.func,
149         onChange: PropTypes.func,
150         value: PropTypes.arrayOf(PropTypes.string),
151 };
152
153 SeedCodeInput.defaultProps = {
154         className: '',
155         game: '',
156         name: '',
157         onBlur: null,
158         onChange: null,
159         value: [],
160 };
161
162 export default withTranslation()(SeedCodeInput);