Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load ROMs from Nes Open DB #179

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"bootstrap": "4.2.1",
"jsnes": "git://github.com/bfirsh/jsnes.git",
"jsonp": "^0.2.1",
"node-sass": "^4.11.0",
"prop-types": "^15.6.2",
"raven-js": "^3.27.0",
Expand Down
44 changes: 44 additions & 0 deletions src/ListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,52 @@ import "./ListPage.css";
import { ListGroup } from "reactstrap";
import { Link } from "react-router-dom";
import config from "./config";
import jsonp from "jsonp";

class ListPage extends Component {
constructor(props) {
super(props);

this.state = {
NesOpenDBData: null
};
}
componentDidMount() {
jsonp(
"https://nes-open-db.github.io/api/v1/rawdump-jsonp.js",
{ name: "NesOpenDB_rawDump" },
(err, data) => this.setState({ NesOpenDBData: data })
);
}
render() {
const romList =
this.state.NesOpenDBData &&
this.state.NesOpenDBData.roms_index.map(function(rom) {
return (
<Link
key={rom.key}
to={
"/run/url/?" +
encodeURIComponent("https://nes-open-db.github.io") +
encodeURIComponent(rom.romLink)
}
className="list-group-item"
>
{rom.title}
<span className="float-right">&rsaquo;</span>
</Link>
);
});

const openDbList = this.state.NesOpenDBData ? (
<div>
<h2>
ROMs from <a href="https://nes-open-db.github.io/">NES Open DB</a>
</h2>
<ListGroup className="mb-4">{romList}</ListGroup>
</div>
) : null;

return (
<div
className="container ListPage my-4"
Expand Down Expand Up @@ -35,6 +78,7 @@ class ListPage extends Component {
</Link>
))}
</ListGroup>
{openDbList}
<p>Or, drag and drop a ROM file onto the page.</p>
<p>
If you want to play ROMs that aren't listed here, Google might be
Expand Down
6 changes: 5 additions & 1 deletion src/RunPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ class RunPage extends Component {
load = () => {
if (this.props.match.params.slug) {
const slug = this.props.match.params.slug;
const rom = config.ROMS[slug];
const rom =
slug === "url"
? { url: decodeURIComponent(window.location.search.substring(1)) }
: config.ROMS[slug];
if (!rom) {
this.setState({ error: `No such ROM: ${slug}` });
return;
}
console.log("rom is", rom);
this.setState({ rom: rom });
this.currentRequest = loadBinary(
rom.url,
Expand Down