1 import FileSaver from 'file-saver';
2 import PropTypes from 'prop-types';
3 import React from 'react';
4 import { Button, Col, Container, Row } from 'react-bootstrap';
5 import { withTranslation } from 'react-i18next';
6 import toastr from 'toastr';
8 import BaseRomButton from './BaseRomButton';
9 import { useAosBaseRom } from '../../helpers/AosBaseRomContext';
10 import BPS from '../../helpers/bps';
11 import i18n from '../../i18n';
13 const applyPatch = (rom, patch, filename) => {
15 const bps = new BPS();
18 const result = bps.applyPatch();
19 FileSaver.saveAs(new Blob([result], { type: 'application/octet-stream' }), filename);
21 toastr.error(i18n.t('aosSeeds.patchError', { msg: e.message }));
25 const isDefaultSetting = (name, value) => {
28 return value === 'Vanilla';
30 return value === 'Vanilla';
32 return value === 'false';
34 return value === 'Vanilla';
36 return value === 'BookSouls';
38 return value === 'Standard';
40 return value === 'false';
42 return value === 'Vanilla';
44 return value === 'AreaTechTiers';
46 return value === 'false';
48 return value === 'false';
50 return value === 'false';
52 return value === 'Vanilla';
54 return value === 'Rand70Dup';
56 return value === 'false';
58 return value === 'Vanilla';
60 return value === 'Vanilla';
62 return value === 'Vanilla';
64 return value === 'false';
66 return value === '2.5';
72 const Seed = ({ onRetry, patch, seed }) => {
73 const { rom } = useAosBaseRom();
76 <h1>{i18n.t('aosSeeds.heading')}</h1>
78 <Col md={{ order: 2 }}>
81 disabled={!seed || seed.status !== 'generated' || !patch}
82 onClick={() => applyPatch(
85 `${i18n.t('aosSeeds.filename', {
92 {i18n.t(patch ? 'aosSeeds.patch' : 'aosSeeds.fetchingPatch')}
98 <Col md={{ order: 1 }}>
100 {i18n.t('aosSeeds.preset')}:
102 <strong>{i18n.t(`aosSeeds.presets.${seed.preset}`)}</strong>
106 {i18n.t('aosSeeds.seed')}:
108 <strong>{seed.seed}</strong>
112 <p>{i18n.t('aosSeeds.race')}</p>
115 <p>{i18n.t('aosSeeds.mystery')}</p>
117 {seed.status === 'generated' ?
119 {i18n.t('aosSeeds.generated')}:
122 {i18n.t('aosSeeds.date', { date: new Date(seed.updated_at) })}
127 {i18n.t('aosSeeds.status')}:
129 <strong>{i18n.t(`aosSeeds.statuses.${seed.status}`)}</strong>
132 {seed.status === 'error' ?
138 {i18n.t('button.retry')}
144 <h2 className="mt-5">{i18n.t('aosSeeds.generator')}</h2>
145 <p>{i18n.t(`aosSeeds.generators.${seed.generator}`)}</p>
147 <h2 className="mt-5">{i18n.t('aosSeeds.settings')}</h2>
149 {Object.entries(seed.settings).map(([key, value]) =>
150 <Col key={key} sm={4} md={3} lg={2} className="mb-2">
151 <small className="text-muted">
152 {i18n.t(`aosSeeds.settingName.${key}`)}
155 {isDefaultSetting(key, value) ?
156 i18n.t(`aosSeeds.settingValue.${key}.${value}`)
158 <strong>{i18n.t(`aosSeeds.settingValue.${key}.${value}`)}</strong>
168 onRetry: PropTypes.func,
169 patch: PropTypes.instanceOf(ArrayBuffer),
170 seed: PropTypes.shape({
171 generator: PropTypes.string,
172 hash: PropTypes.string,
173 mystery: PropTypes.bool,
174 preset: PropTypes.string,
175 race: PropTypes.bool,
176 seed: PropTypes.string,
177 settings: PropTypes.shape({
179 status: PropTypes.string,
180 updated_at: PropTypes.string,
184 export default withTranslation()(Seed);