Skip to content
Merged
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
35 changes: 19 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
"react-ga": "^3.3.1",
"react-router-dom": "^6.3.0",
"reactstrap": "^9.1.3",
"ringbufferjs": "^1.1.0",
"ringbufferjs": "^2.0.0",
"sass": "^1.54.5"
},
"devDependencies": {
"@svgr/webpack": "^6.3.1",
"canvas": "^3.1.2",
"prettier": "^1.16.4",
"prettier": "^3.6.2",
"prettier-check": "^2.0.0",
"react-scripts": "5.0.1"
},
Expand Down
22 changes: 11 additions & 11 deletions src/ControlMapperRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ControlMapperRow extends Component {
this.state = {
playerOneButton: "",
playerTwoButton: "",
waitingForKey: 0
waitingForKey: 0,
};
this.handleClick = this.handleClick.bind(this);
}
Expand All @@ -25,7 +25,7 @@ class ControlMapperRow extends Component {
}
this.setState({
playerOneButton: playerButtons[0],
playerTwoButton: playerButtons[1]
playerTwoButton: playerButtons[1],
});
}

Expand All @@ -46,22 +46,22 @@ class ControlMapperRow extends Component {
}

var searchButton = (gamepadConfig, buttonId) => {
return gamepadConfig.buttons.filter(b => b.buttonId === buttonId)[0];
return gamepadConfig.buttons.filter((b) => b.buttonId === buttonId)[0];
};

var searchNewButton = (prevGamepadConfig, gamepadConfig) => {
return gamepadConfig.buttons.filter(b => {
return gamepadConfig.buttons.filter((b) => {
return (
!prevGamepadConfig ||
!prevGamepadConfig.buttons.some(b2 => b2.buttonId === b.buttonId)
!prevGamepadConfig.buttons.some((b2) => b2.buttonId === b.buttonId)
);
})[0];
};

var waitingForKey = 0;
var waitingForKeyPlayer = 0;

var gamepadButtonName = gamepadButton => {
var gamepadButtonName = (gamepadButton) => {
if (gamepadButton.type === "button") return "Btn-" + gamepadButton.code;
if (gamepadButton.type === "axis")
return "Axis-" + gamepadButton.code + " " + gamepadButton.value;
Expand All @@ -73,11 +73,11 @@ class ControlMapperRow extends Component {
playerButtons[0] = "";
gamepadButton = searchButton(
this.props.gamepadConfig.configs[playerGamepadId[0]],
button
button,
);
newButton = searchNewButton(
prevProps.gamepadConfig.configs[playerGamepadId[0]],
this.props.gamepadConfig.configs[playerGamepadId[0]]
this.props.gamepadConfig.configs[playerGamepadId[0]],
);
if (gamepadButton) {
playerButtons[0] = gamepadButtonName(gamepadButton);
Expand All @@ -95,11 +95,11 @@ class ControlMapperRow extends Component {
playerButtons[1] = "";
gamepadButton = searchButton(
this.props.gamepadConfig.configs[playerGamepadId[1]],
button
button,
);
newButton = searchNewButton(
prevProps.gamepadConfig.configs[playerGamepadId[1]],
this.props.gamepadConfig.configs[playerGamepadId[1]]
this.props.gamepadConfig.configs[playerGamepadId[1]],
);
if (gamepadButton) {
playerButtons[1] = gamepadButtonName(gamepadButton);
Expand Down Expand Up @@ -148,7 +148,7 @@ class ControlMapperRow extends Component {
handleClick(player) {
this.props.handleClick([player, this.props.button]);
this.setState({
waitingForKey: player
waitingForKey: player,
});
}

Expand Down
38 changes: 19 additions & 19 deletions src/ControlsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ModalHeader,
ModalBody,
ModalFooter,
Table
Table,
} from "reactstrap";
import { Controller } from "jsnes";
import ControlMapperRow from "./ControlMapperRow";
Expand All @@ -20,7 +20,7 @@ class ControlsModal extends Component {
gamepadConfig: props.gamepadConfig,
keys: props.keys,
button: undefined,
modified: false
modified: false,
};
this.handleKeyDown = this.handleKeyDown.bind(this);
this.handleGamepadButtonDown = this.handleGamepadButtonDown.bind(this);
Expand All @@ -32,10 +32,10 @@ class ControlsModal extends Component {
this.state.gamepadConfig.configs = this.state.gamepadConfig.configs || {};

this.state.controllerIcon = this.state.gamepadConfig.playerGamepadId.map(
gamepadId => (gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON)
(gamepadId) => (gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON),
);
this.state.controllerIconAlt = this.state.gamepadConfig.playerGamepadId.map(
gamepadId => (gamepadId ? "gamepad" : "keyboard")
(gamepadId) => (gamepadId ? "gamepad" : "keyboard"),
);
this.state.currentPromptButton = -1;
}
Expand Down Expand Up @@ -74,34 +74,34 @@ class ControlsModal extends Component {

playerGamepadId[playerId - 1] = gamepadId;

const rejectButtonId = b => {
const rejectButtonId = (b) => {
return b.buttonId !== buttonId;
};

const newButton = {
code: buttonInfo.code,
type: buttonInfo.type,
buttonId: buttonId,
value: buttonInfo.value
value: buttonInfo.value,
};
newConfig[gamepadId] = {
buttons: (gamepadConfig.configs[gamepadId] || { buttons: [] }).buttons
.filter(rejectButtonId)
.concat([newButton])
.concat([newButton]),
};

const configs = Object.assign({}, gamepadConfig.configs, newConfig);

this.setState({
gamepadConfig: {
configs: configs,
playerGamepadId: playerGamepadId
playerGamepadId: playerGamepadId,
},
currentPromptButton: -1,
controllerIcon: playerGamepadId.map(gamepadId =>
gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON
controllerIcon: playerGamepadId.map((gamepadId) =>
gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON,
),
modified: true
modified: true,
});
}

Expand All @@ -126,22 +126,22 @@ class ControlsModal extends Component {
...newKeys,
[event.keyCode]: [
...button.slice(0, 2),
event.key.length > 1 ? event.key : String(event.key).toUpperCase()
]
event.key.length > 1 ? event.key : String(event.key).toUpperCase(),
],
},
button: undefined,
gamepadConfig: {
configs: this.state.gamepadConfig.configs,
playerGamepadId: playerGamepadId
playerGamepadId: playerGamepadId,
},
currentPromptButton: -1,
controllerIcon: playerGamepadId.map(gamepadId =>
gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON
controllerIcon: playerGamepadId.map((gamepadId) =>
gamepadId ? GAMEPAD_ICON : KEYBOARD_ICON,
),
controllerIconAlt: playerGamepadId.map(gamepadId =>
gamepadId ? "gamepad" : "keyboard"
controllerIconAlt: playerGamepadId.map((gamepadId) =>
gamepadId ? "gamepad" : "keyboard",
),
modified: true
modified: true,
});
}

Expand Down
26 changes: 13 additions & 13 deletions src/Emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Emulator extends Component {
render() {
return (
<Screen
ref={screen => {
ref={(screen) => {
this.screen = screen;
}}
onGenerateFrame={() => {
Expand Down Expand Up @@ -54,7 +54,7 @@ class Emulator extends Component {
// - System can't run emulator at full speed. In this case it'll stop
// firing requestAnimationFrame.
console.log(
"Buffer underrun, running another frame to try and catch up"
"Buffer underrun, running another frame to try and catch up",
);

this.frameTimer.generateFrame();
Expand All @@ -65,40 +65,40 @@ class Emulator extends Component {
console.log("Still buffer underrun, running a second frame");
this.frameTimer.generateFrame();
}
}
},
});

this.nes = new NES({
onFrame: this.screen.setBuffer,
onStatusUpdate: console.log,
onAudioSample: this.speakers.writeSample,
sampleRate: this.speakers.getSampleRate()
sampleRate: this.speakers.getSampleRate(),
});

// For debugging. (["nes"] instead of .nes to avoid VS Code type errors.)
window["nes"] = this.nes;

this.frameTimer = new FrameTimer({
onGenerateFrame: Raven.wrap(this.nes.frame),
onWriteFrame: Raven.wrap(this.screen.writeBuffer)
onWriteFrame: Raven.wrap(this.screen.writeBuffer),
});

// Set up gamepad and keyboard
this.gamepadController = new GamepadController({
onButtonDown: this.nes.buttonDown,
onButtonUp: this.nes.buttonUp
onButtonUp: this.nes.buttonUp,
});

this.gamepadController.loadGamepadConfig();
this.gamepadPolling = this.gamepadController.startPolling();

this.keyboardController = new KeyboardController({
onButtonDown: this.gamepadController.disableIfGamepadEnabled(
this.nes.buttonDown
this.nes.buttonDown,
),
onButtonUp: this.gamepadController.disableIfGamepadEnabled(
this.nes.buttonUp
)
this.nes.buttonUp,
),
});

// Load keys from localStorage (if they exist)
Expand All @@ -108,7 +108,7 @@ class Emulator extends Component {
document.addEventListener("keyup", this.keyboardController.handleKeyUp);
document.addEventListener(
"keypress",
this.keyboardController.handleKeyPress
this.keyboardController.handleKeyPress,
);

this.nes.loadROM(this.props.romData);
Expand All @@ -121,12 +121,12 @@ class Emulator extends Component {
// Unbind keyboard
document.removeEventListener(
"keydown",
this.keyboardController.handleKeyDown
this.keyboardController.handleKeyDown,
);
document.removeEventListener("keyup", this.keyboardController.handleKeyUp);
document.removeEventListener(
"keypress",
this.keyboardController.handleKeyPress
this.keyboardController.handleKeyPress,
);

// Stop gamepad
Expand Down Expand Up @@ -171,7 +171,7 @@ class Emulator extends Component {

Emulator.propTypes = {
paused: PropTypes.bool,
romData: PropTypes.string.isRequired
romData: PropTypes.string.isRequired,
};

export default Emulator;
Loading