Player: explicitly override Engine arguments

This commit is contained in:
He4eT 2023-05-28 13:26:22 +03:00 committed by Alexey
commit 2fdc39c1f0
2 changed files with 10 additions and 4 deletions

View file

@ -20,17 +20,18 @@ const INITIAL_STATUS = {
const runMachine = ({ engine: Engine, wasmBinary, storyfile, handlers }) => { const runMachine = ({ engine: Engine, wasmBinary, storyfile, handlers }) => {
const { Dialog, GlkOte, send } = CheapGlkOte(handlers) const { Dialog, GlkOte, send } = CheapGlkOte(handlers)
const vm = new Engine() const instance = new Engine()
vm.init(storyfile, { instance.init(storyfile, {
Dialog, Dialog,
GlkOte, GlkOte,
Glk: {}, Glk: {},
wasmBinary, wasmBinary,
arguments: ['storyfile'],
}) })
vm.start() instance.start()
return { send, instance: vm } return { send, instance }
} }
export default function Player ({ export default function Player ({
@ -68,6 +69,7 @@ export default function Player ({
window.addEventListener('unhandledrejection', rejectionHandler) window.addEventListener('unhandledrejection', rejectionHandler)
return () => { return () => {
setVm(null)
window.removeEventListener('unhandledrejection', rejectionHandler) window.removeEventListener('unhandledrejection', rejectionHandler)
} }
}, [storyfile, engine, wasmBinary]) }, [storyfile, engine, wasmBinary])
@ -76,6 +78,8 @@ export default function Player ({
setSendMessage(() => vm setSendMessage(() => vm
? vm.send ? vm.send
: null) : null)
return () => setSendMessage(null)
}, [vm]) }, [vm])
const textWindow = (inbox) => (currentWindow) => { const textWindow = (inbox) => (currentWindow) => {

View file

@ -66,6 +66,8 @@ export default function UrlPlayer ({ url, singleWindow }) {
setParts(null) setParts(null)
prepareVM({ url, setStatus, setParts }) prepareVM({ url, setStatus, setParts })
return () => setParts(null)
}, [url]) }, [url])
return vmParts return vmParts