-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate ROM hacks with modified palettes 💥.
- Loading branch information
Showing
20 changed files
with
390 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { useRef, useState } from 'react'; | ||
import { useRom } from '../contexts/RomContext'; | ||
import { generateRomHackFile } from '../lib/romUtils'; | ||
|
||
const type = 'application/x-nes-rom'; | ||
const fileName = 'mm-hack.nes'; | ||
|
||
const DownloadRom = ({ children }) => { | ||
const { prg, resources } = useRom(); | ||
const [aHref, setAHref] = useState(null); | ||
const aRef = useRef(null); | ||
|
||
if (prg === null) { | ||
return ( | ||
<button | ||
className="text-slate-500 opacity-50" | ||
disabled> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
return ( | ||
<> | ||
<button | ||
className="text-slate-500 transition hover:text-slate-800 hover:dark:text-slate-200" | ||
onClick={() => { | ||
const rom = generateRomHackFile(prg, resources); | ||
setAHref(window.URL.createObjectURL(new Blob([rom], { type }))); | ||
|
||
// Needs to render first. | ||
setTimeout(() => { | ||
// Trigger the download by simulating a click. | ||
aRef.current.click(); | ||
window.URL.revokeObjectURL(aHref); | ||
}); | ||
}}> | ||
{children} | ||
</button> | ||
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */} | ||
<a | ||
className="hidden" | ||
href={aHref} | ||
download={fileName} | ||
ref={aRef} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default DownloadRom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import Header from './Header'; | ||
import Footer from './Footer'; | ||
|
||
export default function Layout({ children }) { | ||
return ( | ||
<div className="flex h-dvh flex-col"> | ||
<Header /> | ||
<div className="mx-auto flex w-full max-w-7xl grow items-stretch divide-x divide-slate-500 overflow-y-auto"> | ||
{children} | ||
</div> | ||
<Footer /> | ||
const Layout = ({ children }) => ( | ||
<div className="flex h-dvh flex-col"> | ||
<Header /> | ||
<div className="mx-auto flex w-full max-w-7xl grow items-stretch divide-x divide-slate-500 overflow-y-auto"> | ||
{children} | ||
</div> | ||
); | ||
} | ||
<Footer /> | ||
</div> | ||
); | ||
|
||
export default Layout; |
Oops, something went wrong.