Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/web/app/components/spoiler.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.text_hidden > * {
background-color: white;
color: white;
cursor: pointer;
border-radius: 4px;
}

.text_notHidden > * {
background-color: unset;
color: unset;
cursor: unset;
transition: all 1s;
}

.text_hidden > *::selection {
color: white;
border-radius: 6px;
}
21 changes: 21 additions & 0 deletions apps/web/app/components/spoiler.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { useState } from 'react';
import styles from './spoiler.module.css';

function SpoilerText(props: any) {
const [hidden, setHidden] = useState(true);

const reveal = () => {
setHidden(false);
};

return (
<span
className={hidden ? styles.text_hidden : styles.text_notHidden}
onClick={reveal}
>
{props.children}
</span>
)
}

export default SpoilerText;
49 changes: 44 additions & 5 deletions apps/web/app/generate/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@ import {
import { fetchSignature } from 'core'
import { useCallback, useEffect, useState } from 'react'
import Spacer from '../components/spacer'
import SpoilerText from '../components/spoiler'
import { Eye } from 'react-feather'

const Sidebar = ({
name = null,
signature = null,
hash = null
hash = null,
speed = null
}: {
name?: string | null
signature?: string | null
hash?: string | null
speed?: string | null
}) => {
const { data } = useVanilla()
const mounted = useMounted()
Expand Down Expand Up @@ -91,7 +95,24 @@ const Sidebar = ({
</a>
</p>
</div>
</div>
{speed && (
<div style={{ margin: '2em 0' }} key={hash}>
<h4 className={styles.sidebarHeading}>
Predicted Speed
</h4>
<p style={{ margin: 0, fontSize: '14px', color: '#fff',
display: 'flex', alignItems: 'center', marginTop: '2px' }}>
<Eye height='18'></Eye>
<SpoilerText>
<span style={{ width: '80px', display: 'inline-flex',
marginLeft: '2px', paddingLeft: '8px'}}>
{speed}
</span>
</SpoilerText>
</p>
</div>
)}
</div>
)}
</div>
) : (
Expand Down Expand Up @@ -256,6 +277,7 @@ type RolledSeed = {
seed: any
name: string
hash: string
speed: string
}

export default function Form() {
Expand Down Expand Up @@ -290,7 +312,7 @@ export default function Form() {
} else {
setValue('mode', 'custom')
}
console.log('updating mode', value, matchedMode || 'custom')
//console.log('updating mode', value, matchedMode || 'custom')
}, [setValue])

const onSubmit = async (data: GenerateFormParams) => {
Expand Down Expand Up @@ -390,13 +412,29 @@ export default function Form() {
};

const seedNumber = getSeed();
const { data: seed, name } = await RandomizeRom(
const { data: seed, name, locs } = await RandomizeRom(
seedNumber, settings, options, config);
const hash = paramsToString(seedNumber, settings, options);
if (seed !== null) {
downloadFile(seed, name, hash)
}
setRolledSeed({ seed, name, hash })

let speed = null;
if (settings.preset == "2017MM") {
const input = {'type': 'standard_mm', 'locations': locs};
//console.log(input);
const response = await fetch("https://masshesteria.pythonanywhere.com/api/speed", {
method: "POST",
body: JSON.stringify(input),
headers: { "Content-Type": "application/json", },
})

const res_json = await response.json();
speed = res_json['speed'];
}

setRolledSeed({ seed, name, hash, speed })

} catch (error) {
console.error('SEED ERROR', error)
}
Expand Down Expand Up @@ -679,6 +717,7 @@ export default function Form() {
name={rolledSeed?.name || null}
signature={signature}
hash={rolledSeed?.hash}
speed={rolledSeed?.speed}
/>
</div>
</form>
Expand Down
38 changes: 37 additions & 1 deletion packages/core/lib/randomize.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import BpsPatch from "./bps-patch";
import { getBasePatch, getFileName, generateSeedPatch } from "./sm-rando";
import { getBasePatch, getFileName, generateSeedPatch, getItemNodes } from "./sm-rando";
import { generateSeed } from "./graph/fill";
import { patchRom } from "../helpers/patcher";
import { getLocations } from "./locations";

export type Opts = {
DisableFanfare: number
Expand All @@ -26,6 +27,30 @@ export type Settings = {
suitMode: number
}

const ITEM_TYPES: { [id:string] : number } = {
"Missile": 0,
"Super Missile": 1,
"Power Bomb": 2,
"Morph Ball": 3,
"Wave Beam": 4,
"Plasma Beam": 5,
"Ice Beam": 6,
"Charge Beam": 7,
"Energy Tank": 8,
"Reserve Tank": 9,
"Varia Suit": 10,
"Gravity Suit": 11,
"Grappling Beam": 12,
"Space Jump": 13,
"Screw Attack": 14,
"Spring Ball": 15,
"Bomb": 16,
"Spazer": 17,
"Xray Scope": 18,
"HiJump Boots": 19,
"Speed Booster": 20
}

async function RandomizeRom(
seed: number = 0,
settings: Settings,
Expand All @@ -40,6 +65,16 @@ async function RandomizeRom(

// Place the items.
const graph = generateSeed(seed, settings);
const nodes = getItemNodes(graph)

let encoded = ''
getLocations().forEach(l => {
const node = nodes.find(n => n.location.name == l.name);
if (node == undefined) {
return;
}
encoded += String.fromCharCode(65 + ITEM_TYPES[node.item.name])
})

// Load the base patch associated with the map layout.
const patch = getBasePatch(settings);
Expand All @@ -59,6 +94,7 @@ async function RandomizeRom(
return {
data: patchRom(config.vanillaBytes, basePatch, seedPatch),
name: getFileName(seed, settings, options),
locs: encoded
};
}

Expand Down
3 changes: 0 additions & 3 deletions packages/core/lib/sm-rando.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ export const generateSeedPatch = (seed, settings, graph, options) => {
.forEach((b) => {
if (settings.bossMode == BossMode.ShuffleStandard) {
bossUpdates.concat(getDoorUpdate(b.from.name, b.to.name));
console.debug(`from: ${b.from.name} to: ${b.to.name}`);
} else if (settings.bossMode == BossMode.ShuffleDash) {
console.debug(`from: ${b.from.name} to: ${b.to.name}`);
if (b.from.name == "Door_KraidBoss") {
if (b.to.name == "Exit_Draygon") {
bossUpdates.push({
Expand Down Expand Up @@ -266,7 +264,6 @@ export const generateSeedPatch = (seed, settings, graph, options) => {
.filter((e) => isAreaEdge(e))
.forEach((a) => {
const areaUpdates = getDoorUpdate(a.from.name, a.to.name);
console.debug(`from: ${a.from.name} to: ${a.to.name}`);
areaUpdates.forEach((p) => {
encodeBytes(seedPatch, p.door, U16toBytes(p.dest & 0xffff));
});
Expand Down