mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Player: add message on the vm termination
This commit is contained in:
parent
e7c1384436
commit
7a58f92434
3 changed files with 41 additions and 13 deletions
|
|
@ -106,6 +106,11 @@ export default function InputBox ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const noopHandler = (event) => {
|
||||||
|
event.target.valut = ''
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
|
||||||
const inputHandlers = {
|
const inputHandlers = {
|
||||||
char: {
|
char: {
|
||||||
maxlength: '1',
|
maxlength: '1',
|
||||||
|
|
@ -120,6 +125,11 @@ export default function InputBox ({
|
||||||
onKeyDown: lineArrowHandler,
|
onKeyDown: lineArrowHandler,
|
||||||
onKeyPress: lineHandler,
|
onKeyPress: lineHandler,
|
||||||
},
|
},
|
||||||
|
finished: {
|
||||||
|
placeholder: 'The program has finished',
|
||||||
|
onKeyDown: noopHandler,
|
||||||
|
onKeyPress: noopHandler,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const enterFullscreen = () =>
|
const enterFullscreen = () =>
|
||||||
|
|
@ -134,6 +144,6 @@ export default function InputBox ({
|
||||||
autocomplete='off'
|
autocomplete='off'
|
||||||
onDblClick={enterFullscreen}
|
onDblClick={enterFullscreen}
|
||||||
onInput={({ target: { value } }) => setInputText(value)}
|
onInput={({ target: { value } }) => setInputText(value)}
|
||||||
type='search' />
|
type='text' />
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import GridBuffer from './GridBuffer'
|
||||||
import InputBox from './InputBox'
|
import InputBox from './InputBox'
|
||||||
import Status from './Status'
|
import Status from './Status'
|
||||||
|
|
||||||
import { Handlers } from './playerHandlers'
|
import { Handlers, unhandledRejectionHandler } from './playerHandlers'
|
||||||
|
|
||||||
import './player.css'
|
import './player.css'
|
||||||
|
|
||||||
|
|
@ -47,20 +47,29 @@ export default function Player ({
|
||||||
const [sendMessage, setSendMessage] = useState(null)
|
const [sendMessage, setSendMessage] = useState(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const vm = runMachine({
|
const handlers = Handlers({
|
||||||
|
setStatus,
|
||||||
|
setWindows,
|
||||||
|
setCurrentWindowId,
|
||||||
|
setInputType,
|
||||||
|
setInbox,
|
||||||
|
})
|
||||||
|
|
||||||
|
setVm(runMachine({
|
||||||
engine,
|
engine,
|
||||||
wasmBinary,
|
wasmBinary,
|
||||||
storyfile,
|
storyfile,
|
||||||
handlers: Handlers({
|
handlers,
|
||||||
setStatus,
|
}))
|
||||||
setWindows,
|
|
||||||
setCurrentWindowId,
|
|
||||||
setInputType,
|
|
||||||
setInbox,
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
|
|
||||||
setVm(vm)
|
const rejectionHandler =
|
||||||
|
unhandledRejectionHandler(handlers.onExit)
|
||||||
|
|
||||||
|
window.addEventListener('unhandledrejection', rejectionHandler)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('unhandledrejection', rejectionHandler)
|
||||||
|
}
|
||||||
}, [storyfile, engine, wasmBinary])
|
}, [storyfile, engine, wasmBinary])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,15 @@ export const Handlers = ({
|
||||||
},
|
},
|
||||||
/* */
|
/* */
|
||||||
onExit: () => {
|
onExit: () => {
|
||||||
setInputType(null)
|
setInputType('finished')
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const unhandledRejectionHandler = (onExit) => (event) => {
|
||||||
|
if (event.reason.name === 'ExitStatus' || event.reason.message === 'Program terminated with exit(0)') {
|
||||||
|
onExit()
|
||||||
|
} else {
|
||||||
|
console.error('Unhandled rejection (promise: ', event.promise, ', reason: ', event.reason, ').');
|
||||||
|
}
|
||||||
|
event.preventDefault()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue