@slot-engine/core 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +58 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -31,6 +31,7 @@ function createPermanentFilePaths(basePath) {
|
|
|
31
31
|
`books_${mode}_chunk_${worker}-${chunk}.jsonl.zst`
|
|
32
32
|
),
|
|
33
33
|
booksCompressed: (mode) => path.join(basePath, "publish_files", `books_${mode}.jsonl.zst`),
|
|
34
|
+
booksUncompressed: (mode) => path.join(basePath, `books_${mode}.jsonl`),
|
|
34
35
|
lookupTable: (mode) => path.join(basePath, `lookUpTable_${mode}.csv`),
|
|
35
36
|
lookupTableIndex: (mode) => path.join(basePath, `lookUpTable_${mode}.index`),
|
|
36
37
|
lookupTableSegmented: (mode) => path.join(basePath, `lookUpTableSegmented_${mode}.csv`),
|
|
@@ -1751,6 +1752,8 @@ var TerminalUi = class {
|
|
|
1751
1752
|
logs = [];
|
|
1752
1753
|
logScrollOffset = 0;
|
|
1753
1754
|
isScrolled = false;
|
|
1755
|
+
maxLogs = 500;
|
|
1756
|
+
totalLogs = 0;
|
|
1754
1757
|
minWidth = 50;
|
|
1755
1758
|
minHeight = 12;
|
|
1756
1759
|
isRendering = false;
|
|
@@ -1776,12 +1779,13 @@ var TerminalUi = class {
|
|
|
1776
1779
|
this.scrollDown();
|
|
1777
1780
|
} else if (key === "l") {
|
|
1778
1781
|
this.scrollToBottom();
|
|
1779
|
-
} else if (key === "") {
|
|
1782
|
+
} else if (key === "q" || key === "") {
|
|
1780
1783
|
this.stop();
|
|
1781
1784
|
process.exit(0);
|
|
1782
1785
|
}
|
|
1783
1786
|
};
|
|
1784
1787
|
process.stdout.on("resize", this.resizeHandler);
|
|
1788
|
+
process.on("SIGINT", this.sigintHandler);
|
|
1785
1789
|
}
|
|
1786
1790
|
get terminalWidth() {
|
|
1787
1791
|
return process.stdout.columns || 80;
|
|
@@ -1803,7 +1807,6 @@ var TerminalUi = class {
|
|
|
1803
1807
|
}
|
|
1804
1808
|
this.render();
|
|
1805
1809
|
this.renderInterval = setInterval(() => this.render(), 100);
|
|
1806
|
-
process.on("SIGINT", this.sigintHandler);
|
|
1807
1810
|
}
|
|
1808
1811
|
stop() {
|
|
1809
1812
|
if (this.renderInterval) {
|
|
@@ -1831,7 +1834,16 @@ var TerminalUi = class {
|
|
|
1831
1834
|
this.totalSims = opts.totalSims;
|
|
1832
1835
|
}
|
|
1833
1836
|
log(message) {
|
|
1834
|
-
this.logs.push({ i: this.
|
|
1837
|
+
this.logs.push({ i: this.totalLogs, m: message });
|
|
1838
|
+
this.totalLogs++;
|
|
1839
|
+
if (this.logs.length > this.maxLogs) {
|
|
1840
|
+
const excess = this.logs.length - this.maxLogs;
|
|
1841
|
+
this.logs.splice(0, excess);
|
|
1842
|
+
this.logScrollOffset = Math.min(
|
|
1843
|
+
this.logScrollOffset,
|
|
1844
|
+
Math.max(0, this.logs.length - this.getLogAreaHeight())
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1835
1847
|
if (!this.isScrolled) this.scrollToBottom();
|
|
1836
1848
|
}
|
|
1837
1849
|
scrollUp(lines = 1) {
|
|
@@ -1996,6 +2008,7 @@ var Simulation = class {
|
|
|
1996
2008
|
gameConfig;
|
|
1997
2009
|
simRunsAmount;
|
|
1998
2010
|
concurrency;
|
|
2011
|
+
makeUncompressedBooks;
|
|
1999
2012
|
debug = false;
|
|
2000
2013
|
actualSims = 0;
|
|
2001
2014
|
wallet = new Wallet();
|
|
@@ -2024,6 +2037,7 @@ var Simulation = class {
|
|
|
2024
2037
|
const { config, metadata } = createGameConfig(gameConfigOpts);
|
|
2025
2038
|
this.gameConfig = { ...config, ...metadata };
|
|
2026
2039
|
this.gameConfigOpts = gameConfigOpts;
|
|
2040
|
+
this.makeUncompressedBooks = opts.makeUncompressedBooks || false;
|
|
2027
2041
|
this.simRunsAmount = opts.simRunsAmount || {};
|
|
2028
2042
|
this.concurrency = (opts.concurrency || 6) >= 2 ? opts.concurrency || 6 : 2;
|
|
2029
2043
|
this.maxPendingSims = opts.maxPendingSims ?? 25;
|
|
@@ -2101,9 +2115,7 @@ var Simulation = class {
|
|
|
2101
2115
|
const startTime = Date.now();
|
|
2102
2116
|
statusMessage = `Simulating mode "${mode}" with ${this.simRunsAmount[mode]} runs.`;
|
|
2103
2117
|
this.tui?.log(statusMessage);
|
|
2104
|
-
|
|
2105
|
-
this.socket.emit("simulationStatus", statusMessage);
|
|
2106
|
-
}
|
|
2118
|
+
this.sendSimulationStatus(statusMessage);
|
|
2107
2119
|
const runs = this.simRunsAmount[mode] || 0;
|
|
2108
2120
|
if (runs <= 0) continue;
|
|
2109
2121
|
if (!configuredGameModes.includes(mode)) {
|
|
@@ -2140,9 +2152,7 @@ var Simulation = class {
|
|
|
2140
2152
|
createDirIfNotExists(this.PATHS.publishFiles);
|
|
2141
2153
|
statusMessage = `Writing final files for game mode "${mode}". This may take a while...`;
|
|
2142
2154
|
this.tui?.log(statusMessage);
|
|
2143
|
-
|
|
2144
|
-
this.socket.emit("simulationStatus", statusMessage);
|
|
2145
|
-
}
|
|
2155
|
+
this.sendSimulationStatus(statusMessage);
|
|
2146
2156
|
writeFile(
|
|
2147
2157
|
this.PATHS.booksIndexMeta(mode),
|
|
2148
2158
|
JSON.stringify(
|
|
@@ -2197,13 +2207,43 @@ var Simulation = class {
|
|
|
2197
2207
|
}
|
|
2198
2208
|
await this.writeRecords(mode);
|
|
2199
2209
|
this.writeIndexJson();
|
|
2210
|
+
if (this.makeUncompressedBooks) {
|
|
2211
|
+
statusMessage = `Creating decompressed book file for mode "${mode}". This may take a while...`;
|
|
2212
|
+
this.tui?.log(statusMessage);
|
|
2213
|
+
this.sendSimulationStatus(statusMessage);
|
|
2214
|
+
const uncompressedBooksPath = this.PATHS.booksUncompressed(mode);
|
|
2215
|
+
const outputStream = fs3.createWriteStream(uncompressedBooksPath, {
|
|
2216
|
+
highWaterMark: this.streamHighWaterMark
|
|
2217
|
+
});
|
|
2218
|
+
try {
|
|
2219
|
+
for (const { worker, chunks: chunks2 } of this.bookIndexMetas) {
|
|
2220
|
+
for (let chunk = 0; chunk < chunks2; chunk++) {
|
|
2221
|
+
const bookChunkPath = this.PATHS.booksChunk(mode, worker, chunk);
|
|
2222
|
+
if (!fs3.existsSync(bookChunkPath)) continue;
|
|
2223
|
+
const inputStream = fs3.createReadStream(bookChunkPath);
|
|
2224
|
+
const compress = zlib.createZstdDecompress();
|
|
2225
|
+
for await (const decompChunk of inputStream.pipe(compress)) {
|
|
2226
|
+
if (!outputStream.write(decompChunk)) {
|
|
2227
|
+
await new Promise((r) => outputStream.once("drain", () => r()));
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
}
|
|
2231
|
+
}
|
|
2232
|
+
outputStream.end();
|
|
2233
|
+
await new Promise((r) => outputStream.on("finish", () => r()));
|
|
2234
|
+
} catch (error) {
|
|
2235
|
+
statusMessage = chalk2.yellow(
|
|
2236
|
+
`Error creating uncompressed book file: ${error.message}`
|
|
2237
|
+
);
|
|
2238
|
+
this.tui?.log(statusMessage);
|
|
2239
|
+
this.sendSimulationStatus(statusMessage);
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2200
2242
|
const endTime = Date.now();
|
|
2201
2243
|
const prettyTime = new Date(endTime - startTime).toISOString().slice(11, -1);
|
|
2202
2244
|
statusMessage = `Mode ${mode} done! Time taken: ${prettyTime}`;
|
|
2203
2245
|
this.tui?.log(statusMessage);
|
|
2204
|
-
|
|
2205
|
-
this.socket.emit("simulationStatus", statusMessage);
|
|
2206
|
-
}
|
|
2246
|
+
this.sendSimulationStatus(statusMessage);
|
|
2207
2247
|
}
|
|
2208
2248
|
this.tui?.stop();
|
|
2209
2249
|
await this.printSimulationSummary();
|
|
@@ -2405,7 +2445,7 @@ var Simulation = class {
|
|
|
2405
2445
|
`
|
|
2406
2446
|
)
|
|
2407
2447
|
]);
|
|
2408
|
-
if (this.bookBufferSizes.get(index) >=
|
|
2448
|
+
if (this.bookBufferSizes.get(index) >= 10 * 1024 * 1024) {
|
|
2409
2449
|
await flushBookChunk();
|
|
2410
2450
|
}
|
|
2411
2451
|
if (this.recordsWriteStream) {
|
|
@@ -2851,6 +2891,11 @@ var Simulation = class {
|
|
|
2851
2891
|
});
|
|
2852
2892
|
}
|
|
2853
2893
|
}
|
|
2894
|
+
sendSimulationStatus(message) {
|
|
2895
|
+
if (this.socket && this.panelActive) {
|
|
2896
|
+
this.socket.emit("simulationStatus", message);
|
|
2897
|
+
}
|
|
2898
|
+
}
|
|
2854
2899
|
};
|
|
2855
2900
|
|
|
2856
2901
|
// src/analysis/index.ts
|