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 === 'Vanilla';
52 return value === 'Rand70Dup';
54 return value === 'Vanilla';
56 return value === 'Vanilla';
58 return value === 'Vanilla';
60 return value === 'false';
62 return value === '2.5';
68 const Seed = ({ onRetry, patch, seed }) => {
69 const { rom } = useAosBaseRom();
72 <h1>{i18n.t('aosSeeds.heading')}</h1>
74 <Col md={{ order: 2 }}>
77 disabled={!seed || seed.status !== 'generated' || !patch}
78 onClick={() => applyPatch(
81 `${i18n.t('aosSeeds.filename', {
88 {i18n.t(patch ? 'aosSeeds.patch' : 'aosSeeds.fetchingPatch')}
94 <Col md={{ order: 1 }}>
96 {i18n.t('aosSeeds.preset')}:
98 <strong>{i18n.t(`aosSeeds.presets.${seed.preset}`)}</strong>
102 {i18n.t('aosSeeds.seed')}:
104 <strong>{seed.seed}</strong>
108 <p>{i18n.t('aosSeeds.race')}</p>
111 <p>{i18n.t('aosSeeds.mystery')}</p>
113 {seed.status === 'generated' ?
115 {i18n.t('aosSeeds.generated')}:
118 {i18n.t('aosSeeds.date', { date: new Date(seed.updated_at) })}
123 {i18n.t('aosSeeds.status')}:
125 <strong>{i18n.t(`aosSeeds.statuses.${seed.status}`)}</strong>
128 {seed.status === 'error' ?
134 {i18n.t('button.retry')}
140 <h2 className="mt-5">{i18n.t('aosSeeds.generator')}</h2>
141 <p>{i18n.t(`aosSeeds.generators.${seed.generator}`)}</p>
143 <h2 className="mt-5">{i18n.t('aosSeeds.settings')}</h2>
145 {Object.entries(seed.settings).map(([key, value]) =>
146 <Col key={key} sm={4} md={3} lg={2} className="mb-2">
147 <small className="text-muted">
148 {i18n.t(`aosSeeds.settingName.${key}`)}
151 {isDefaultSetting(key, value) ?
152 i18n.t(`aosSeeds.settingValue.${key}.${value}`)
154 <strong>{i18n.t(`aosSeeds.settingValue.${key}.${value}`)}</strong>
164 onRetry: PropTypes.func,
165 patch: PropTypes.instanceOf(ArrayBuffer),
166 seed: PropTypes.shape({
167 generator: PropTypes.string,
168 hash: PropTypes.string,
169 mystery: PropTypes.bool,
170 preset: PropTypes.string,
171 race: PropTypes.bool,
172 seed: PropTypes.string,
173 settings: PropTypes.shape({
175 status: PropTypes.string,
176 updated_at: PropTypes.string,
180 export default withTranslation()(Seed);