-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
54 lines (45 loc) · 1.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React, { useEffect, useContext, useState } from 'react'
import GBAEmulator, { GbaContext } from 'react-gbajs'
import useGbaSaveRestoreState from '../../hooks/useGbaSaveRestoreState'
import ROMContext from '../../context/ROMContext'
const Emulator = () => {
const [onError, setOnError] = useState(false)
const { play: playGba } = useContext(GbaContext)
const { romBufferMemory, romBufferStatus } = useContext(ROMContext)
useEffect(() => {
setOnError(false)
if (romBufferStatus === 'loaded') {
playGba({ newRomBuffer: romBufferMemory })
}
}, [romBufferStatus]) /* should not be called when romBufferState.memory updates */ // eslint-disable-line react-hooks/exhaustive-deps
useGbaSaveRestoreState()
const handleEmulatorCrashed = (...error) => {
setOnError(true)
// eslint-disable-next-line no-console
console.warn(error)
}
if (onError) {
return (
<span>
Emulator crashed. Please, open a new ROM or refresh this page.
</span>
)
}
return (
<>
<GBAEmulator
scale={2}
onLogReceived={handleEmulatorCrashed}
/>
<span>
Controls:{' '}
<strong>z</strong> → a;{' '}
<strong>x</strong> → b;{' '}
<strong>start</strong> → enter;{' '}
<strong>q</strong> → save state;{' '}
<strong>w</strong> → restore state
</span>
</>
)
}
export default Emulator