-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.stdio.js
69 lines (57 loc) · 1.34 KB
/
player.stdio.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env node
/**
* @see: https://github.com/curiousdannii/emglken/blob/master/bin/emglken.js
*/
import { readFileSync } from 'fs'
import minimist from 'minimist'
import CheapGlkOte from '../src/index.js'
import { handlers } from './stdio.js'
const formats = [
{
id: 'bocfel',
extensions: /z([3458]|blorb)$/,
engine: 'bocfel.js',
},
{
id: 'glulxe',
extensions: /(gblorb|ulx)$/,
engine: 'glulxe.js',
},
{
id: 'git',
extensions: /(gblorb|ulx)$/,
engine: 'git.js',
},
{
id: 'hugo',
extensions: /hex$/,
engine: 'hugo.js',
},
{
id: 'tads',
extensions: /(gam|t3)$/,
engine: 'tads.js',
}
]
const argv = minimist(process.argv.slice(2))
const storyfile = argv._[0]
const format = formats.find(x =>
x.extensions.test(storyfile))
if (!format) {
console.error('Unknown storyfile format.')
process.exit(0)
}
import(`emglken/src/${format.id}.js`)
.then(({default: engine}) => engine)
.then((engine) => new engine())
.then((vm) => {
const cheapGlkOte = CheapGlkOte(handlers)
handlers.setSend(cheapGlkOte.send)
vm.init(readFileSync(storyfile), {
Dialog: cheapGlkOte.Dialog,
GlkOte: cheapGlkOte.GlkOte,
Glk: {},
wasmBinary: readFileSync(new URL(`../node_modules/emglken/build/${format.id}-core.wasm`, import.meta.url))
})
vm.start()
})