const ts = require('typescript'); const fs = require('node:fs'); const assert = require('node:assert/strict'); // Execute the actual addLevel method, with external game services stubbed. const source = fs.readFileSync('assets/Script/module/Tool/GameTool.ts', 'utf8'); const ast = ts.createSourceFile('GameTool.ts', source, ts.ScriptTarget.Latest, true); let method; function visit(node) { if (ts.isMethodDeclaration(node) && node.name.getText(ast) === 'addLevel') method = node; ts.forEachChild(node, visit); } visit(ast); assert.ok(method); const calls = []; const info = { level: 10, GameplayType: 0, otherLevel: 0 }; let max = false; const cc = { fx: { GameConfig: { GM_INFO: info }, StorageMessage: { setStorage() {} }, GameTool: { maxLevel: () => max, shushu_Track() {} } } }; const run = new Function('cc', 'recordCoinMadnessMockWin', 'MiniGameSdk', 'Utils', 'MapConroler', 'return ({' + method.getText(ast) + '}).addLevel;')(cc, level => calls.push(level), { API: { setNewCloudlevel() {}, shushu_SetSuperProperties() {} } }, { setUserLevel() {} }, { _instance: null }); run(1000, 0, null); assert.deepEqual(calls, [11]); info.GameplayType = 1; run(1000, 0, null); assert.equal(calls.length, 1); info.GameplayType = 0; info.otherLevel = 3; run(1000, 0, null); assert.equal(calls.length, 1); info.otherLevel = 0; run(null, null, null); assert.equal(calls.length, 1); max = true; run(1000, 0, null); assert.equal(calls.length, 1); max = false; info.level = 1979; run(1000, 0, null); assert.deepEqual(calls, [11, 1980]); console.log('Actual addLevel hook passed: normal wins, last normal level, excluded endless/special/config catchup.');