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 Seed = ({ patch, seed }) => {
26 const { rom } = useAosBaseRom();
29 <h1>{i18n.t('aosSeeds.heading')}</h1>
31 <Col md={{ order: 2 }}>
34 disabled={!seed || seed.status !== 'generated' || !patch}
35 onClick={() => applyPatch(
38 `${i18n.t('aosSeeds.filename', {
45 {i18n.t(patch ? 'aosSeeds.patch' : 'aosSeeds.fetchingPatch')}
51 <Col md={{ order: 1 }}>
53 {i18n.t('aosSeeds.preset')}:
55 <strong>{i18n.t(`aosSeeds.presets.${seed.preset}`)}</strong>
59 {i18n.t('aosSeeds.seed')}:
61 <strong>{seed.seed}</strong>
65 <p>{i18n.t('aosSeeds.race')}</p>
68 <p>{i18n.t('aosSeeds.mystery')}</p>
70 {seed.status === 'generated' ?
72 {i18n.t('aosSeeds.generated')}:
75 {i18n.t('aosSeeds.date', { date: new Date(seed.updated_at) })}
80 {i18n.t('aosSeeds.status')}:
82 <strong>{i18n.t(`aosSeeds.statuses.${seed.status}`)}</strong>
87 <h2 className="mt-5">{i18n.t('aosSeeds.generator')}</h2>
88 <p>{i18n.t(`aosSeeds.generators.${seed.generator}`)}</p>
93 patch: PropTypes.instanceOf(ArrayBuffer),
94 seed: PropTypes.shape({
95 generator: PropTypes.string,
96 hash: PropTypes.string,
97 mystery: PropTypes.bool,
98 preset: PropTypes.string,
100 seed: PropTypes.string,
101 status: PropTypes.string,
102 updated_at: PropTypes.string,
106 export default withTranslation()(Seed);