-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
73 lines (61 loc) · 1.69 KB
/
mod.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { isConfig } from "./isConfig.ts";
import { ensureDir, parsePath, joinPath } from "./deps.ts";
const CONFIG_PATH = "./batch-randomize-config.json";
let config: unknown;
try {
config = JSON.parse(await Deno.readTextFile(CONFIG_PATH));
} catch {
throw new Deno.errors.NotFound(
`Unable to read configuration from '${CONFIG_PATH}'.`
);
}
if (!isConfig(config)) {
throw new Deno.errors.InvalidData(
`Invalid configuration. Please check configuration file located at '${CONFIG_PATH}'.`
);
}
await ensureDir(config.outputPath);
try {
await Deno.stat(config.romPath);
} catch {
throw new Deno.errors.NotFound(
`Unable to find ROM file at '${config.romPath}'.`
);
}
try {
await Deno.stat(config.randomizerJarPath);
} catch {
throw new Deno.errors.NotFound(
`Unable to find randomizer jar file at '${config.randomizerJarPath}'.`
);
}
try {
await Deno.stat(config.randomizerSettingsPath);
} catch {
throw new Deno.errors.NotFound(
`Unable to find randomizer settings file at '${config.randomizerSettingsPath}'.`
);
}
const parsedRomPath = parsePath(config.romPath);
for (let i = 0; i < config.seedCount; i++) {
const paddedFileNumber = `${i + config.firstSeedNumber}`.padStart(5, "0");
const outputFileName = `${parsedRomPath.name} Randomized ${paddedFileNumber}${parsedRomPath.ext}`;
console.log(`Generating ${outputFileName}`);
const process = Deno.run({
cmd: [
"java",
"-Xmx4608M",
"-jar",
config.randomizerJarPath,
"cli",
"-i",
config.romPath,
"-o",
joinPath(config.outputPath, outputFileName),
"-s",
config.randomizerSettingsPath,
],
stdout: "null",
});
await process.status();
}