-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
executable file
·48 lines (40 loc) · 956 Bytes
/
index.ts
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
#! /usr/bin/env bun
import { generateWorld, interact } from "./src/world";
import { parseArgs } from "util";
import { strict as assert } from "assert";
const getArgs = (args: string[]) => {
const {
values: { seed },
} = parseArgs({
args,
options: {
seed: {
type: "string",
default: Math.floor(Math.random() * 1000000).toString(),
},
},
allowPositionals: true,
});
return {
seed: Number(seed),
};
};
const main = async () => {
const { seed } = getArgs(Bun.argv);
assert(Number.isInteger(seed), "Seed must be an integer");
console.log(`Seed: ${seed}`);
let state = await generateWorld({ seed });
console.log(state.reply);
console.log();
process.stdout.write("> ");
for await (const line of console) {
state = await interact({
...state,
question: line,
});
console.log(state.reply);
console.log();
process.stdout.write("> ");
}
};
main();