@energy8platform/game-engine 0.9.2 → 0.10.0
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/README.md +293 -1414
- package/bin/simulate.ts +75 -0
- package/dist/debug.cjs.js +892 -18
- package/dist/debug.cjs.js.map +1 -1
- package/dist/debug.d.ts +64 -0
- package/dist/debug.esm.js +892 -18
- package/dist/debug.esm.js.map +1 -1
- package/dist/index.cjs.js +899 -18
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +239 -2
- package/dist/index.esm.js +893 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/lua.cjs.js +1000 -0
- package/dist/lua.cjs.js.map +1 -0
- package/dist/lua.d.ts +296 -0
- package/dist/lua.esm.js +990 -0
- package/dist/lua.esm.js.map +1 -0
- package/dist/vite.cjs.js +26 -0
- package/dist/vite.cjs.js.map +1 -1
- package/dist/vite.esm.js +26 -0
- package/dist/vite.esm.js.map +1 -1
- package/package.json +29 -13
- package/src/debug/DevBridge.ts +73 -22
- package/src/index.ts +17 -0
- package/src/lua/ActionRouter.ts +132 -0
- package/src/lua/LuaEngine.ts +322 -0
- package/src/lua/LuaEngineAPI.ts +305 -0
- package/src/lua/PersistentState.ts +80 -0
- package/src/lua/SessionManager.ts +178 -0
- package/src/lua/SimulationRunner.ts +195 -0
- package/src/lua/index.ts +22 -0
- package/src/lua/types.ts +132 -0
- package/src/vite/index.ts +30 -0
package/bin/simulate.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
import { SimulationRunner, formatSimulationResult } from '../src/lua/SimulationRunner';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
|
|
5
|
+
// ─── Argument Parsing ───────────────────────────────────
|
|
6
|
+
|
|
7
|
+
function parseArgs(argv: string[]): Record<string, string> {
|
|
8
|
+
const args: Record<string, string> = {};
|
|
9
|
+
for (let i = 2; i < argv.length; i++) {
|
|
10
|
+
const arg = argv[i];
|
|
11
|
+
if (arg.startsWith('--') && i + 1 < argv.length) {
|
|
12
|
+
const key = arg.slice(2);
|
|
13
|
+
args[key] = argv[++i];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return args;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
const args = parseArgs(process.argv);
|
|
21
|
+
|
|
22
|
+
const configPath = resolve(process.cwd(), args.config ?? './dev.config.ts');
|
|
23
|
+
const iterations = parseInt(args.iterations ?? '1000000', 10);
|
|
24
|
+
const bet = parseFloat(args.bet ?? '1');
|
|
25
|
+
const seed = args.seed ? parseInt(args.seed, 10) : undefined;
|
|
26
|
+
const action = args.action ?? 'spin';
|
|
27
|
+
const params = args.params ? JSON.parse(args.params) : undefined;
|
|
28
|
+
|
|
29
|
+
// Load dev config
|
|
30
|
+
let config: any;
|
|
31
|
+
try {
|
|
32
|
+
const mod = await import(configPath);
|
|
33
|
+
config = mod.default ?? mod.config ?? mod;
|
|
34
|
+
} catch (e: any) {
|
|
35
|
+
console.error(`Failed to load config from ${configPath}:`);
|
|
36
|
+
console.error(e.message);
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!config.luaScript) {
|
|
41
|
+
console.error('Config must contain `luaScript` (Lua source code string).');
|
|
42
|
+
console.error('Make sure your dev.config.ts exports luaScript and gameDefinition.');
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!config.gameDefinition) {
|
|
47
|
+
console.error('Config must contain `gameDefinition` (GameDefinition object).');
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const gameId = config.gameDefinition.id ?? 'unknown';
|
|
52
|
+
console.log(`Starting simulation for ${gameId} (${iterations.toLocaleString()} iterations, action: ${action})...`);
|
|
53
|
+
|
|
54
|
+
const runner = new SimulationRunner({
|
|
55
|
+
script: config.luaScript,
|
|
56
|
+
gameDefinition: config.gameDefinition,
|
|
57
|
+
iterations,
|
|
58
|
+
bet,
|
|
59
|
+
seed,
|
|
60
|
+
action,
|
|
61
|
+
params,
|
|
62
|
+
onProgress: (completed, total) => {
|
|
63
|
+
const pct = Math.round((completed / total) * 100);
|
|
64
|
+
console.log(`Progress: ${completed.toLocaleString()}/${total.toLocaleString()} (${pct}%)`);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const result = runner.run();
|
|
69
|
+
console.log(formatSimulationResult(result));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
main().catch((err) => {
|
|
73
|
+
console.error(err);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
});
|