]> git.localhorst.tv Git - alttp.git/blob - resources/js/components/aos-generate/Generate.js
first half of AoS generator
[alttp.git] / resources / js / components / aos-generate / Generate.js
1 import { withFormik } from 'formik';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, Col, Container, Form, Row } from 'react-bootstrap';
5 import { withTranslation } from 'react-i18next';
6
7 import i18n from '../../i18n';
8
9 const settings = [
10         'logic',
11         'nodupes',
12         'panther',
13         'area',
14         'boss',
15         'enemy',
16         'itempool',
17         'weight',
18         'grahm',
19         'kicker',
20         'startshop',
21         'shopprice',
22         'shopSouls',
23         'levelexp',
24         'telestart',
25         'mapassist',
26         'doublechaos',
27         'reqallsouls',
28         'noww',
29         'palette',
30 ];
31
32 const settingValues = {
33         area: [
34                 'AreaRandom',
35                 'DoorRandom',
36                 'Vanilla',
37         ],
38         boss: [
39                 'Dead-endShuffle',
40                 'Vanilla',
41         ],
42         doublechaos: [
43                 'false',
44                 'true',
45         ],
46         enemy: [
47                 'RandomNoLimit',
48                 'RandomP20M5',
49                 'RandomP30M10',
50                 'RandomPM10',
51                 'RandomPM20',
52                 'RandomPMaxM5',
53                 'Vanilla',
54         ],
55         grahm: [
56                 'AllBosses',
57                 'BookSouls',
58                 'NoCheck',
59         ],
60         itempool: [
61                 'AllSouls',
62                 'Standard',
63         ],
64         kicker: [
65                 'false',
66                 'true',
67         ],
68         levelexp: [
69                 'Casual',
70                 'Hard',
71                 'Lvl1',
72                 'Vanilla',
73         ],
74         logic: [
75                 'AreaTechTiers',
76                 'AreaTechTiersHard',
77                 'ForwardFeed',
78                 'ForwardFeedHard',
79                 'HybridProgression',
80                 'VeryRandom',
81                 'VeryRandomHard',
82                 'VeryRandomHardOnly',
83         ],
84         mapassist: [
85                 'false',
86                 'true',
87         ],
88         nodupes: [
89                 'false',
90                 'true',
91         ],
92         noww: [
93                 'false',
94                 'true',
95         ],
96         palette: [
97                 'Mode1',
98                 'Mode1.5',
99                 'Mode2',
100                 'Vanilla',
101         ],
102         panther: [
103                 'AlwaysRand',
104                 'ExtraFairRand',
105                 'FirstAlways',
106                 'NeverExists',
107                 'Rand70Dup',
108         ],
109         reqallsouls: [
110                 'false',
111                 'true',
112         ],
113         shopprice: [
114                 'RandHV',
115                 'Vanilla',
116         ],
117         shopSouls: [
118                 '2PerGroup',
119                 'Half',
120                 'OnlySouls',
121                 'Vanilla',
122         ],
123         startshop: [
124                 'Unlocked',
125                 'Unlocked30k',
126                 'Vanilla',
127         ],
128         telestart: [
129                 'false',
130                 'true',
131         ],
132         weight: [
133                 '0',
134                 '1.0',
135                 '1.5',
136                 '2.0',
137                 '2.5',
138                 '3.0',
139                 '3.5',
140         ],
141 };
142
143 const Generate = ({
144         handleBlur,
145         handleChange,
146         handleSubmit,
147         presets,
148         setFieldValue,
149         values,
150 }) =>
151 <Container>
152         <h1>{i18n.t('aosGenerate.heading')}</h1>
153         <Form noValidate onSubmit={handleSubmit}>
154                 <Row>
155                         <Col md={6}>
156                                 <Form.Group controlId="generate.preset">
157                                         <Form.Label>
158                                                 {i18n.t('aosSeeds.preset')}
159                                         </Form.Label>
160                                         <Form.Select
161                                                 name="preset"
162                                                 onBlur={handleBlur}
163                                                 onChange={e => {
164                                                         const presetName = e.target.value;
165                                                         const preset = presets.find(p => p.value === presetName);
166                                                         if (preset) {
167                                                                 setFieldValue('settings', preset.settings);
168                                                         }
169                                                         return handleChange(e);
170                                                 }}
171                                                 value={values.preset}
172                                         >
173                                                 <option value="custom">{i18n.t('aosSeeds.presets.custom')}</option>
174                                                 {presets.map(preset =>
175                                                         <option key={preset.value} value={preset.value}>
176                                                                 {i18n.t(`aosSeeds.presets.${preset.value}`)}
177                                                         </option>
178                                                 )}
179                                         </Form.Select>
180                                 </Form.Group>
181                         </Col>
182                         <Col sm={6} md={3}>
183                                 <Form.Group controlId="generate.submit">
184                                         <Form.Label>
185                                                 {i18n.t('button.generate')}
186                                         </Form.Label>
187                                         <div>
188                                                 <Button type="submit">
189                                                         {i18n.t('button.generate')}
190                                                 </Button>
191                                         </div>
192                                 </Form.Group>
193                         </Col>
194                 </Row>
195                 <Row>
196                         {settings.map(setting =>
197                                 <Form.Group as={Col} md={4} key={setting} controlId={`generate.${setting}`}>
198                                         <Form.Label>
199                                                 {i18n.t(`aosSeeds.settingName.${setting}`)}
200                                         </Form.Label>
201                                         <Form.Select
202                                                 name={`settings[${setting}]`}
203                                                 onBlur={handleBlur}
204                                                 onChange={e => {
205                                                         setFieldValue('preset', 'custom');
206                                                         return handleChange(e);
207                                                 }}
208                                                 value={values.settings[setting]}
209                                         >
210                                                 {settingValues[setting].map(value =>
211                                                         <option key={value} value={value}>
212                                                                 {i18n.t(`aosSeeds.settingValue.${setting}.${value}`)}
213                                                         </option>
214                                                 )}
215                                         </Form.Select>
216                                 </Form.Group>
217                         )}
218                 </Row>
219         </Form>
220 </Container>;
221
222 Generate.propTypes = {
223         handleBlur: PropTypes.func,
224         handleChange: PropTypes.func,
225         handleSubmit: PropTypes.func,
226         presets: PropTypes.arrayOf(PropTypes.shape({
227                 settings: PropTypes.shape({
228                 }),
229                 value: PropTypes.string,
230         })),
231         setFieldValue: PropTypes.func,
232         values: PropTypes.shape({
233                 preset: PropTypes.string,
234                 settings: PropTypes.shape({
235                 }),
236         }),
237 };
238
239 export default withFormik({
240         displayName: 'AosGenerateForm',
241         mapPropsToValues: () => ({
242                 preset: 'Normal',
243                 settings: {
244                         area: 'Vanilla',
245                         boss: 'Vanilla',
246                         doublechaos: 'false',
247                         enemy: 'Vanilla',
248                         grahm: 'BookSouls',
249                         itempool: 'Standard',
250                         kicker: 'false',
251                         levelexp: 'Vanilla',
252                         logic: 'AreaTechTiers',
253                         mapassist: 'false',
254                         nodupes: 'false',
255                         noww: 'false',
256                         palette: 'Vanilla',
257                         panther: 'Rand70Dup',
258                         reqallsouls: 'false',
259                         shopprice: 'Vanilla',
260                         shopSouls: 'Vanilla',
261                         startshop: 'Vanilla',
262                         telestart: 'false',
263                         weight: '2.5',
264                 },
265         }),
266 })(withTranslation()(Generate));