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 = ({ 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>
130 <h2 className="mt-5">{i18n.t('aosSeeds.generator')}</h2>
131 <p>{i18n.t(`aosSeeds.generators.${seed.generator}`)}</p>
133 <h2 className="mt-5">{i18n.t('aosSeeds.settings')}</h2>
135 {Object.entries(seed.settings).map(([key, value]) =>
136 <Col key={key} sm={4} md={3} lg={2} className="mb-2">
137 <small className="text-muted">
138 {i18n.t(`aosSeeds.settingName.${key}`)}
141 {isDefaultSetting(key, value) ?
142 i18n.t(`aosSeeds.settingValue.${key}.${value}`)
144 <strong>{i18n.t(`aosSeeds.settingValue.${key}.${value}`)}</strong>
154 patch: PropTypes.instanceOf(ArrayBuffer),
155 seed: PropTypes.shape({
156 generator: PropTypes.string,
157 hash: PropTypes.string,
158 mystery: PropTypes.bool,
159 preset: PropTypes.string,
160 race: PropTypes.bool,
161 seed: PropTypes.string,
162 settings: PropTypes.shape({
164 status: PropTypes.string,
165 updated_at: PropTypes.string,
169 export default withTranslation()(Seed);