From a5e53546a5960f54fb45e06767f89e9dfeef6a47 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 27 Jul 2022 09:50:43 +0200 Subject: [PATCH] first half of AoS generator --- app/Http/Controllers/AosSeedController.php | 4 + .../js/components/aos-generate/Generate.js | 266 ++++++++++++++++++ resources/js/components/aos/App.js | 2 + resources/js/components/pages/AosGenerate.js | 56 ++++ resources/js/i18n/de.js | 5 + resources/js/i18n/en.js | 5 + routes/api.php | 1 + 7 files changed, 339 insertions(+) create mode 100644 resources/js/components/aos-generate/Generate.js create mode 100644 resources/js/components/pages/AosGenerate.js diff --git a/app/Http/Controllers/AosSeedController.php b/app/Http/Controllers/AosSeedController.php index 8cdc58b..a1718a1 100644 --- a/app/Http/Controllers/AosSeedController.php +++ b/app/Http/Controllers/AosSeedController.php @@ -42,6 +42,10 @@ class AosSeedController extends Controller return $seed->toJson(); } + public function presets() { + return array_values(AosrPresetCommand::$presets); + } + public function retry($hash) { $seed = AosSeed::where('hash', '=', $hash)->firstOrFail(); diff --git a/resources/js/components/aos-generate/Generate.js b/resources/js/components/aos-generate/Generate.js new file mode 100644 index 0000000..cbdeeb0 --- /dev/null +++ b/resources/js/components/aos-generate/Generate.js @@ -0,0 +1,266 @@ +import { withFormik } from 'formik'; +import PropTypes from 'prop-types'; +import React from 'react'; +import { Button, Col, Container, Form, Row } from 'react-bootstrap'; +import { withTranslation } from 'react-i18next'; + +import i18n from '../../i18n'; + +const settings = [ + 'logic', + 'nodupes', + 'panther', + 'area', + 'boss', + 'enemy', + 'itempool', + 'weight', + 'grahm', + 'kicker', + 'startshop', + 'shopprice', + 'shopSouls', + 'levelexp', + 'telestart', + 'mapassist', + 'doublechaos', + 'reqallsouls', + 'noww', + 'palette', +]; + +const settingValues = { + area: [ + 'AreaRandom', + 'DoorRandom', + 'Vanilla', + ], + boss: [ + 'Dead-endShuffle', + 'Vanilla', + ], + doublechaos: [ + 'false', + 'true', + ], + enemy: [ + 'RandomNoLimit', + 'RandomP20M5', + 'RandomP30M10', + 'RandomPM10', + 'RandomPM20', + 'RandomPMaxM5', + 'Vanilla', + ], + grahm: [ + 'AllBosses', + 'BookSouls', + 'NoCheck', + ], + itempool: [ + 'AllSouls', + 'Standard', + ], + kicker: [ + 'false', + 'true', + ], + levelexp: [ + 'Casual', + 'Hard', + 'Lvl1', + 'Vanilla', + ], + logic: [ + 'AreaTechTiers', + 'AreaTechTiersHard', + 'ForwardFeed', + 'ForwardFeedHard', + 'HybridProgression', + 'VeryRandom', + 'VeryRandomHard', + 'VeryRandomHardOnly', + ], + mapassist: [ + 'false', + 'true', + ], + nodupes: [ + 'false', + 'true', + ], + noww: [ + 'false', + 'true', + ], + palette: [ + 'Mode1', + 'Mode1.5', + 'Mode2', + 'Vanilla', + ], + panther: [ + 'AlwaysRand', + 'ExtraFairRand', + 'FirstAlways', + 'NeverExists', + 'Rand70Dup', + ], + reqallsouls: [ + 'false', + 'true', + ], + shopprice: [ + 'RandHV', + 'Vanilla', + ], + shopSouls: [ + '2PerGroup', + 'Half', + 'OnlySouls', + 'Vanilla', + ], + startshop: [ + 'Unlocked', + 'Unlocked30k', + 'Vanilla', + ], + telestart: [ + 'false', + 'true', + ], + weight: [ + '0', + '1.0', + '1.5', + '2.0', + '2.5', + '3.0', + '3.5', + ], +}; + +const Generate = ({ + handleBlur, + handleChange, + handleSubmit, + presets, + setFieldValue, + values, +}) => + +

{i18n.t('aosGenerate.heading')}

+
+ + + + + {i18n.t('aosSeeds.preset')} + + { + const presetName = e.target.value; + const preset = presets.find(p => p.value === presetName); + if (preset) { + setFieldValue('settings', preset.settings); + } + return handleChange(e); + }} + value={values.preset} + > + + {presets.map(preset => + + )} + + + + + + + {i18n.t('button.generate')} + +
+ +
+
+ +
+ + {settings.map(setting => + + + {i18n.t(`aosSeeds.settingName.${setting}`)} + + { + setFieldValue('preset', 'custom'); + return handleChange(e); + }} + value={values.settings[setting]} + > + {settingValues[setting].map(value => + + )} + + + )} + +
+
; + +Generate.propTypes = { + handleBlur: PropTypes.func, + handleChange: PropTypes.func, + handleSubmit: PropTypes.func, + presets: PropTypes.arrayOf(PropTypes.shape({ + settings: PropTypes.shape({ + }), + value: PropTypes.string, + })), + setFieldValue: PropTypes.func, + values: PropTypes.shape({ + preset: PropTypes.string, + settings: PropTypes.shape({ + }), + }), +}; + +export default withFormik({ + displayName: 'AosGenerateForm', + mapPropsToValues: () => ({ + preset: 'Normal', + settings: { + area: 'Vanilla', + boss: 'Vanilla', + doublechaos: 'false', + enemy: 'Vanilla', + grahm: 'BookSouls', + itempool: 'Standard', + kicker: 'false', + levelexp: 'Vanilla', + logic: 'AreaTechTiers', + mapassist: 'false', + nodupes: 'false', + noww: 'false', + palette: 'Vanilla', + panther: 'Rand70Dup', + reqallsouls: 'false', + shopprice: 'Vanilla', + shopSouls: 'Vanilla', + startshop: 'Vanilla', + telestart: 'false', + weight: '2.5', + }, + }), +})(withTranslation()(Generate)); diff --git a/resources/js/components/aos/App.js b/resources/js/components/aos/App.js index 0001f01..a092074 100644 --- a/resources/js/components/aos/App.js +++ b/resources/js/components/aos/App.js @@ -4,6 +4,7 @@ import { BrowserRouter, Route, Routes } from 'react-router-dom'; import Header from './Header'; import AosFront from '../pages/AosFront'; +import AosGenerate from '../pages/AosGenerate'; import AosSeed from '../pages/AosSeed'; import Tracker from '../pages/AosTracker'; import User from '../pages/User'; @@ -55,6 +56,7 @@ const App = () => {
+ } /> } /> } /> } /> diff --git a/resources/js/components/pages/AosGenerate.js b/resources/js/components/pages/AosGenerate.js new file mode 100644 index 0000000..0c27b06 --- /dev/null +++ b/resources/js/components/pages/AosGenerate.js @@ -0,0 +1,56 @@ +import axios from 'axios'; +import React, { useCallback, useEffect, useState } from 'react'; + +import Generate from '../aos-generate/Generate'; +import ErrorBoundary from '../common/ErrorBoundary'; +import ErrorMessage from '../common/ErrorMessage'; +import Loading from '../common/Loading'; +import i18n from '../../i18n'; + +const AosGenerate = () => { + const [error, setError] = useState(null); + const [loading, setLoading] = useState(true); + const [presets, setPresets] = useState([]); + + const loadPresets = useCallback(ctrl => { + axios + .get('/api/aos-presets', { signal: ctrl.signal }) + .then(response => { + setError(null); + setLoading(false); + setPresets(response.data); + }) + .catch(error => { + setError(error); + setLoading(false); + setPresets([]); + }); + }, []); + + useEffect(() => { + setLoading(true); + const ctrl = new AbortController(); + loadPresets(ctrl); + return () => { + ctrl.abort(); + }; + }, []); + + useEffect(() => { + window.document.title = i18n.t('aosGenerate.heading'); + }, [i18n.language]); + + if (loading) { + return ; + } + + if (error) { + return ; + } + + return + + ; +}; + +export default AosGenerate; diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index 6171548..56b2d06 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -55,6 +55,9 @@ export default { setBaseRom: 'Base ROM auswählen', tourneyDiscord: 'Turnier Discord', }, + aosGenerate: { + heading: 'AoSR Seed Generieren', + }, aosSeeds: { date: '{{ date, L LT }}', fetchingPatch: 'Lade Patch', @@ -80,6 +83,7 @@ export default { AreaRequireAllSouls: 'Area alle Seelen', AreaSpicy: 'Area spicy', Beginner: 'Beginner', + custom: 'Custom', DoorAllBosses: 'Door alle Bosse', DoorAllBossesEasy: 'Door alle Bosses einfach', ExtraFastNormal: 'Extra schnell normal', @@ -247,6 +251,7 @@ export default { chart: 'Diagramm', close: 'Schließen', edit: 'Bearbeiten', + generate: 'Generieren', help: 'Hilfe', login: 'Login', logout: 'Logout', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 32249dd..f91e63b 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -55,6 +55,9 @@ export default { setBaseRom: 'Set base ROM', tourneyDiscord: 'Tournament Discord', }, + aosGenerate: { + heading: 'Generate AoSR Seed', + }, aosSeeds: { date: '{{ date, L LT }}', fetchingPatch: 'Fetching patch', @@ -80,6 +83,7 @@ export default { AreaRequireAllSouls: 'Area require all souls', AreaSpicy: 'Area spicy', Beginner: 'Beginner', + custom: 'Custom', DoorAllBosses: 'Door all bosses', DoorAllBossesEasy: 'Door all bosses easy', ExtraFastNormal: 'Extra fast normal', @@ -247,6 +251,7 @@ export default { chart: 'Chart', close: 'Close', edit: 'Edit', + generate: 'Generate', help: 'Help', login: 'Login', logout: 'Logout', diff --git a/routes/api.php b/routes/api.php index ad624c3..1b0ea84 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,6 +22,7 @@ Route::get('alttp-seed/{hash}', 'App\Http\Controllers\AlttpSeedController@byHash Route::post('alttp-seed/{hash}/retry', 'App\Http\Controllers\AlttpSeedController@retry'); Route::post('aos-generate', 'App\Http\Controllers\AosSeedController@generate'); +Route::get('aos-presets', 'App\Http\Controllers\AosSeedController@presets'); Route::get('aos-seed/{hash}', 'App\Http\Controllers\AosSeedController@byHash'); Route::post('aos-seed/{hash}/retry', 'App\Http\Controllers\AosSeedController@retry'); -- 2.39.2