From 84bba89e7eb5bd56ab716863e5900ad8f790ca6d Mon Sep 17 00:00:00 2001 From: JianMiau Date: Fri, 30 Aug 2024 15:37:33 +0800 Subject: [PATCH] =?UTF-8?q?[add]=20=E8=A8=AD=E5=AE=9Aenv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 1 + .env.dev | 2 + .env.prod | 2 + .vscode/launch.json | 3 + .vscode/tasks.json | 4 +- package-lock.json | 504 ++++-------------- package.json | 12 +- shared/jsons/slot1.json | 25 + src/Utils/tools.ts | 12 + src/api/slot/SlotInBase.ts | 3 +- src/api/slot/{spin.ts => SlotSpinBase.ts} | 35 +- src/api/slot1/spin.ts | 27 +- src/electron/index.html | 1 + src/electron/main.ts | 117 ++-- src/electron/preload.ts | 1 + src/electron/renderer.ts | 4 + src/global.d.ts | 1 + src/pkg/server.ts | 2 +- .../CatanEngine/NetManagerV2/NetConnector.ts | 2 +- src/shared/protocols/define/interface.ts | 1 + tsconfig.json | 2 +- tsrpc.config.ts | 38 -- 22 files changed, 249 insertions(+), 550 deletions(-) create mode 100644 .env.dev create mode 100644 .env.prod create mode 100644 shared/jsons/slot1.json create mode 100644 src/Utils/tools.ts rename src/api/slot/{spin.ts => SlotSpinBase.ts} (80%) delete mode 100644 tsrpc.config.ts diff --git a/.env b/.env index a439f2d..797e032 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ PORT=9005 +NODE_ENV=dev \ No newline at end of file diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..797e032 --- /dev/null +++ b/.env.dev @@ -0,0 +1,2 @@ +PORT=9005 +NODE_ENV=dev \ No newline at end of file diff --git a/.env.prod b/.env.prod new file mode 100644 index 0000000..6b1cca8 --- /dev/null +++ b/.env.prod @@ -0,0 +1,2 @@ +PORT=9005 +NODE_ENV=prod \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index ddcea28..7ea1512 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,9 @@ "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd" }, "args": ["."], + "env": { + "NODE_ENV": "dev" + }, "outputCapture": "std", "sourceMaps": true, "restart": true diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f6db282..3b74e22 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,14 +6,14 @@ "type": "shell", "command": "npm", "args": ["run", "build"], - "problemMatcher": [] + "problemMatcher": [], }, { "label": "npm: start", "type": "shell", "command": "npm", "args": ["start"], - "problemMatcher": [] + "problemMatcher": [], } ] } diff --git a/package-lock.json b/package-lock.json index 5c8b504..0450c84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "dayjs": "^1.11.13", "dotenv": "^16.4.5", "module-alias": "^2.2.3", - "tsrpc": "^3.4.16", "ws": "^8.18.0" }, "bin": { @@ -22,6 +21,7 @@ "@types/node": "^22.5.0", "@types/ws": "^8.5.12", "copyfiles": "^2.4.1", + "cross-env": "^7.0.3", "electron": "^32.0.1", "electron-builder": "^24.7.0", "electron-packager": "^17.1.2", @@ -98,6 +98,29 @@ "global-agent": "^3.0.0" } }, + "node_modules/@electron/get/node_modules/fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/@electron/get/node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, "node_modules/@electron/get/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", @@ -107,6 +130,15 @@ "semver": "bin/semver.js" } }, + "node_modules/@electron/get/node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, "node_modules/@electron/notarize": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/@electron/notarize/-/notarize-1.2.4.tgz", @@ -135,27 +167,6 @@ "node": ">=10" } }, - "node_modules/@electron/notarize/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/@electron/notarize/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/@electron/osx-sign": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.3.1.tgz", @@ -191,27 +202,6 @@ "node": ">=12" } }, - "node_modules/@electron/osx-sign/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/@electron/osx-sign/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/@electron/universal": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/@electron/universal/-/universal-1.5.1.tgz", @@ -245,27 +235,6 @@ "node": ">=10" } }, - "node_modules/@electron/universal/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/@electron/universal/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", @@ -439,27 +408,6 @@ "node": ">=10" } }, - "node_modules/@malept/flatpak-bundler/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/@malept/flatpak-bundler/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -582,6 +530,7 @@ "version": "22.5.0", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.0.tgz", "integrity": "sha512-DkFrJOe+rfdHTqqMg0bSNlGlQ85hSoh2TPzZyhHsXnMtligRWpxUySiyw8FY14ITt24HVCiQPWxS3KO/QlGmWg==", + "dev": true, "dependencies": { "undici-types": "~6.19.2" } @@ -748,6 +697,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -928,18 +878,6 @@ "url": "https://github.com/sponsors/gjtorikian/" } }, - "node_modules/app-builder-lib/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/app-builder-lib/node_modules/minimatch": { "version": "5.1.6", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", @@ -952,15 +890,6 @@ "node": ">=10" } }, - "node_modules/app-builder-lib/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/archiver": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/archiver/-/archiver-5.3.2.tgz", @@ -1390,27 +1319,6 @@ "node": ">=12" } }, - "node_modules/builder-util/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/builder-util/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/cacheable-lookup": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", @@ -1442,6 +1350,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -1457,6 +1366,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, "engines": { "node": ">=8" } @@ -1465,6 +1375,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "dependencies": { "has-flag": "^4.0.0" }, @@ -1618,6 +1529,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -1628,7 +1540,8 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "node_modules/combined-stream": { "version": "1.0.8", @@ -1911,6 +1824,24 @@ "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -2121,27 +2052,6 @@ "node": ">=12" } }, - "node_modules/dmg-builder/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/dmg-builder/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/dmg-license": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/dmg-license/-/dmg-license-1.0.11.tgz", @@ -2324,29 +2234,6 @@ "node": ">=12" } }, - "node_modules/electron-builder-squirrel-windows/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "peer": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/electron-builder-squirrel-windows/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "peer": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/electron-builder/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", @@ -2375,27 +2262,6 @@ "node": ">=12" } }, - "node_modules/electron-builder/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/electron-builder/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/electron-builder/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -2451,41 +2317,6 @@ "url": "https://github.com/electron/electron-packager?sponsor=1" } }, - "node_modules/electron-packager/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, - "node_modules/electron-packager/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/electron-packager/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/electron-publish": { "version": "24.13.1", "resolved": "https://registry.npmjs.org/electron-publish/-/electron-publish-24.13.1.tgz", @@ -2515,27 +2346,6 @@ "node": ">=12" } }, - "node_modules/electron-publish/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/electron-publish/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/electron/node_modules/@types/node": { "version": "20.16.1", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.1.tgz", @@ -2885,27 +2695,6 @@ "node": ">=12" } }, - "node_modules/flora-colossus/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/flora-colossus/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/foreground-child": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", @@ -2944,17 +2733,17 @@ "peer": true }, "node_modules/fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", "dev": true, "dependencies": { "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" }, "engines": { - "node": ">=6 <7 || >=8" + "node": ">=14.14" } }, "node_modules/fs-minipass": { @@ -3038,27 +2827,6 @@ "node": ">=12" } }, - "node_modules/galactus/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/galactus/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/get-caller-file": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", @@ -3735,10 +3503,13 @@ } }, "node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, "optionalDependencies": { "graceful-fs": "^4.1.6" } @@ -3762,6 +3533,7 @@ "version": "1.4.6", "resolved": "https://registry.npmjs.org/k8w-extend-native/-/k8w-extend-native-1.4.6.tgz", "integrity": "sha512-AHTCyFshldMme0s9FKD+QKG+QZdBkHXzl+8kYfNhsSDhcdQ5TYWQwphjecSJjxNdGd78TIbO0fHiOvM+Ei22YA==", + "dev": true, "dependencies": { "k8w-linq-array": "*", "k8w-super-date": "*", @@ -3771,17 +3543,20 @@ "node_modules/k8w-linq-array": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/k8w-linq-array/-/k8w-linq-array-0.2.8.tgz", - "integrity": "sha512-4IAkQN8UJdk804tQi++wuwSZvFWk/Wcl1uG5PR/0c0YvB5hUd2f8tJm3OgOMOxjV9UVByNLvnPYGIwrFQPpjlA==" + "integrity": "sha512-4IAkQN8UJdk804tQi++wuwSZvFWk/Wcl1uG5PR/0c0YvB5hUd2f8tJm3OgOMOxjV9UVByNLvnPYGIwrFQPpjlA==", + "dev": true }, "node_modules/k8w-super-date": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/k8w-super-date/-/k8w-super-date-0.1.3.tgz", - "integrity": "sha512-IBqKOAMAXR/bgzu+rYI30tEMP/Y6Q8HQuqJiTkE2mLJg11yok9guoi8uZTynTahviVBndcfBpOgi1H/zhihv7w==" + "integrity": "sha512-IBqKOAMAXR/bgzu+rYI30tEMP/Y6Q8HQuqJiTkE2mLJg11yok9guoi8uZTynTahviVBndcfBpOgi1H/zhihv7w==", + "dev": true }, "node_modules/k8w-super-object": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/k8w-super-object/-/k8w-super-object-0.3.0.tgz", - "integrity": "sha512-u2jfh4goYXKZmSucaLaOTaNbLRatjv0CSRpzE0KU0732+9XtYZFd5vrdw/mzJfK5fPHb/zyikOSHDX5mJrav+g==" + "integrity": "sha512-u2jfh4goYXKZmSucaLaOTaNbLRatjv0CSRpzE0KU0732+9XtYZFd5vrdw/mzJfK5fPHb/zyikOSHDX5mJrav+g==", + "dev": true }, "node_modules/keyv": { "version": "4.5.4", @@ -5280,27 +5055,6 @@ "node": ">=12" } }, - "node_modules/temp-file/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/temp-file/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/through": { "version": "2.3.8", "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", @@ -5463,6 +5217,7 @@ "version": "2.2.9", "resolved": "https://registry.npmjs.org/tsbuffer/-/tsbuffer-2.2.9.tgz", "integrity": "sha512-PZtbjmtMDziIi1/RPn1LMuMTmNUsZajB+Ziz+HxonAxswXeam0ukTwjQ2eYR6J1JOffz7E8z5ip+NrYZ7wGnBQ==", + "dev": true, "dependencies": { "k8w-extend-native": "^1.4.6", "tsbuffer-validator": "^2.1.2", @@ -5498,12 +5253,14 @@ "node_modules/tsbuffer-schema": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/tsbuffer-schema/-/tsbuffer-schema-2.2.0.tgz", - "integrity": "sha512-I4+5Xfk7G+D++kXdNnYTeY26WQTaf14C84XQwPKteNmrwxRY3CQCkMqASRiCUqtpOuDn43qmoxuXpT+Vo8Wltg==" + "integrity": "sha512-I4+5Xfk7G+D++kXdNnYTeY26WQTaf14C84XQwPKteNmrwxRY3CQCkMqASRiCUqtpOuDn43qmoxuXpT+Vo8Wltg==", + "dev": true }, "node_modules/tsbuffer-validator": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/tsbuffer-validator/-/tsbuffer-validator-2.1.2.tgz", "integrity": "sha512-PrqIYy7aANY7ssr92HJN8ZM+eGc4Qmpvu7nNBv+T2DOAb+eqblKjlDZEhNnzxjs/ddqu9PqPe4Aa+fqYdzo98g==", + "dev": true, "dependencies": { "k8w-extend-native": "^1.4.6", "tsbuffer-schema": "^2.2.0", @@ -5513,32 +5270,8 @@ "node_modules/tslib": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", - "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" - }, - "node_modules/tsrpc": { - "version": "3.4.16", - "resolved": "https://registry.npmjs.org/tsrpc/-/tsrpc-3.4.16.tgz", - "integrity": "sha512-rUiaQNJJwZlOwTwnbZfNb2JJYL0Y/lZ/GVAtRYwFMzq7Z2H7dI4kB3oPakpu4+g3+i8radFPXfTsPkcNF1iAUg==", - "dependencies": { - "@types/ws": "^7.4.7", - "chalk": "^4.1.2", - "tsbuffer": "^2.2.9", - "tsrpc-base-client": "^2.1.15", - "tsrpc-proto": "^1.4.3", - "uuid": "^8.3.2", - "ws": "^7.5.9" - } - }, - "node_modules/tsrpc-base-client": { - "version": "2.1.15", - "resolved": "https://registry.npmjs.org/tsrpc-base-client/-/tsrpc-base-client-2.1.15.tgz", - "integrity": "sha512-ejIsGKF1MtcS2Mqpv1JYjoOmFbkOMaubb0FYglA52Sfl0glnq2UAqbCu5embQISzuIF9DiDeg1Rui9EyOc2hdA==", - "dependencies": { - "k8w-extend-native": "^1.4.6", - "tsbuffer": "^2.2.9", - "tslib": "*", - "tsrpc-proto": "^1.4.3" - } + "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "dev": true }, "node_modules/tsrpc-cli": { "version": "2.4.5", @@ -5582,18 +5315,6 @@ "node": ">=12" } }, - "node_modules/tsrpc-cli/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/tsrpc-cli/node_modules/typescript": { "version": "4.9.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", @@ -5607,52 +5328,16 @@ "node": ">=4.2.0" } }, - "node_modules/tsrpc-cli/node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "dev": true, - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/tsrpc-proto": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/tsrpc-proto/-/tsrpc-proto-1.4.3.tgz", "integrity": "sha512-qtkk5i34m9/K1258EdyXAEikU/ADPELHCCXN/oFJ4XwH+kN3kXnKYmwCDblUuMA73V2+A/EwkgUGyAgPa335Hw==", + "dev": true, "dependencies": { "tsbuffer-schema": "^2.2.0", "tslib": "*" } }, - "node_modules/tsrpc/node_modules/@types/ws": { - "version": "7.4.7", - "resolved": "https://registry.npmjs.org/@types/ws/-/ws-7.4.7.tgz", - "integrity": "sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww==", - "dependencies": { - "@types/node": "*" - } - }, - "node_modules/tsrpc/node_modules/ws": { - "version": "7.5.10", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", - "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", - "engines": { - "node": ">=8.3.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, "node_modules/type-fest": { "version": "0.13.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", @@ -5707,15 +5392,16 @@ "node_modules/undici-types": { "version": "6.19.8", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", - "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==" + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true }, "node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", "dev": true, "engines": { - "node": ">= 4.0.0" + "node": ">= 10.0.0" } }, "node_modules/untildify": { @@ -5748,14 +5434,6 @@ "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, - "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/v8-compile-cache-lib": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", diff --git a/package.json b/package.json index 33e59ef..e571540 100644 --- a/package.json +++ b/package.json @@ -3,18 +3,20 @@ "version": "1.0.0", "main": "dist/electron/main.js", "scripts": { - "start": "electron .", - "build": "tsc && copyfiles -u 1 src/electron/index.html dist/ && copyfiles -u 1 src/electron/index.css dist/", + "start": "cross-env NODE_ENV=dev electron .", + "build": "cross-env NODE_ENV=prod tsc && npm run copyfiles", + "copyfiles": "copyfiles -u 1 src/electron/index.html dist/ && copyfiles -u 1 src/electron/index.css dist/ && copyfiles -u 1 shared/jsons/* dist/shared", "buildexe": "npm run build && electron-builder", - "api": "tsrpc-cli proto && tsrpc-cli api", "watch": "nodemon" }, "build": { "appId": "SDServer", + "productName": "SDServer", "files": [ "dist/**/*", "node_modules/**/*", - "package.json" + "package.json", + ".env.prod" ], "directories": { "output": "release" @@ -24,13 +26,13 @@ "dayjs": "^1.11.13", "dotenv": "^16.4.5", "module-alias": "^2.2.3", - "tsrpc": "^3.4.16", "ws": "^8.18.0" }, "devDependencies": { "@types/node": "^22.5.0", "@types/ws": "^8.5.12", "copyfiles": "^2.4.1", + "cross-env": "^7.0.3", "electron": "^32.0.1", "electron-builder": "^24.7.0", "electron-packager": "^17.1.2", diff --git a/shared/jsons/slot1.json b/shared/jsons/slot1.json new file mode 100644 index 0000000..b335cb1 --- /dev/null +++ b/shared/jsons/slot1.json @@ -0,0 +1,25 @@ +{ + "slotData": [ + {"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,200]]}, + {"slot":[9,6,2,5,4,14,10,9,13,10,4,5,5,2,2]}, + {"slot":[4,3,3,3,9,10,14,14,9,4,7,8,8,5,10],"free":[[1,2,3],3],"scatter":[[[1,2,3],300]]}, + {"slot":[1,2,4,5,6,7,3,3,3,8,9,10,11,12,13],"free":[[6,7,8],10],"scatter":[[[6,7,8],300]]} + ], + "slotFreeData": [ + {"slot":[9,9,10,13,4,5,4,3,4,11,10,14,14,14,5]}, + {"slot":[12,6,8,12,11,7,12,11,5,5,11,5,3,10,9]}, + {"slot":[4,6,11,13,8,12,12,3,4,10,7,5,14,14,4]}, + {"slot":[12,11,9,14,6,7,2,3,8,8,11,10,10,7,14]}, + {"slot":[9,14,13,4,11,4,7,6,14,6,12,13,9,12,12]}, + {"slot":[10,3,12,13,5,6,4,8,4,9,13,14,11,14,4]}, + {"slot":[11,13,9,8,5,8,5,5,13,9,14,9,12,4,7]}, + {"slot":[10,14,13,9,8,6,6,6,4,13,13,12,9,14,4],"line":[[[5,6,7],122,300]]}, + {"slot":[13,9,5,14,4,9,4,12,12,11,4,14,8,7,6],"line":[[[10,6],195,300],[[10,6],213,300]]}, + {"slot":[5,9,9,3,11,10,4,5,12,5,4,14,12,5,9],"line":[[[10,6],195,300],[[10,6],213,300]]}, + {"slot":[2,8,13,2,10,9,12,5,11,4,5,2,12,5,8],"line":[[[0,6,12],49,150],[[0,11,2],61,150],[[0,11,7,13],70,3000],[[0,11,12],79,150],[[10,11,7,13],234,3000]]}, + {"slot":[5,12,13,3,4,10,2,5,8,8,2,9,12,10,9],"line":[[[10,1,12],183,150],[[10,6,2],195,150],[[10,6,12],213,150]]}, + {"slot":[14,4,10,3,11,5,14,3,12,6,10,6,14,5,12],"line":[[[0,6,12],49,750]],"scatter":[[[3,7],300]]}, + {"slot":[6,3,12,4,8,14,10,3,7,9,10,4,10,6,7],"line":[[[10,6,12],213,75]],"scatter":[[[1,7],300]]}, + {"slot":[9,12,3,7,2,6,13,11,3,11,13,3,8,6,6],"free":[[2,8,11],10],"scatter":[[[2,8,11],900]]} + ] +} \ No newline at end of file diff --git a/src/Utils/tools.ts b/src/Utils/tools.ts new file mode 100644 index 0000000..d582088 --- /dev/null +++ b/src/Utils/tools.ts @@ -0,0 +1,12 @@ +import { app } from 'electron'; +import path from 'path'; + +export function getExternalJsonPath(filename: string): string { + if (process.env.NODE_ENV === 'dev') { + // 开发模式下使用相对路径 + return path.join(__dirname, '../../shared/jsons', filename); + } else { + // 生产模式下使用外部路径 + return path.join(app.getPath('userData'), 'jsons', filename); + } +} \ No newline at end of file diff --git a/src/api/slot/SlotInBase.ts b/src/api/slot/SlotInBase.ts index f641ae2..0847874 100644 --- a/src/api/slot/SlotInBase.ts +++ b/src/api/slot/SlotInBase.ts @@ -3,7 +3,6 @@ import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/ import { ClientData } from "../../shared/protocols/define/interface"; import { RpcSlotInRequest, RpcSlotInResponse } from "../../shared/protocols/SlotRequest"; - export default abstract class SlotInBase { protected ver: string = ""; protected abstract db: number; @@ -12,8 +11,8 @@ export default abstract class SlotInBase { public *in(clientData: ClientData, req: INetRequest): IterableIterator { const data: RpcSlotInRequest = req.Data; - const { id } = data; const { ver, db, br, jp } = this; + const response: INetResponse = { Status: 0, Method: req.Method, diff --git a/src/api/slot/spin.ts b/src/api/slot/SlotSpinBase.ts similarity index 80% rename from src/api/slot/spin.ts rename to src/api/slot/SlotSpinBase.ts index 2d3ed37..65adcda 100644 --- a/src/api/slot/spin.ts +++ b/src/api/slot/SlotSpinBase.ts @@ -1,9 +1,10 @@ +import * as fs from 'fs'; import { INetRequest } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetRequest"; import { INetResponse } from "../../script/Engine/CatanEngine/NetManagerV2/Core/INetResponse"; import { ClientData } from "../../shared/protocols/define/interface"; import { RpcSlot1SpinRequest, RpcSlot1SpinResponse } from "../../shared/protocols/Slot1Request"; import { RandomEx } from "../../Utils/Number/RandomEx"; - +import { getExternalJsonPath } from "../../Utils/tools"; export default abstract class SlotSpinBase { protected abstract ID: number; @@ -11,14 +12,30 @@ export default abstract class SlotSpinBase { protected IsHaveReSpin: boolean = false; protected IsHaveRetriggerFreeSpin: boolean = false; protected FreeMax: number = 50; - protected abstract Temps: string[]; - protected abstract FreeTemps: string[]; + protected JsonData: any; + protected get Temps(): string[] { return this.JsonData.slotData }; + protected get FreeTemps(): string[] { return this.JsonData.slotFreeData }; public *spin(clientData: ClientData, req: INetRequest): IterableIterator { + const self = this; const data: RpcSlot1SpinRequest = req.Data + + if (!clientData.jsons[this.ID]) { + let slotData: any; + let AsyncFunction = async function () { + slotData = await self.GetTemps(); + }; + AsyncFunction(); + while (!slotData) { + yield; + } + clientData.jsons[this.ID] = slotData; + } + this.JsonData = clientData.jsons[this.ID]; + clientData.free = null; - const slotData: any = JSON.parse(this.Temps[RandomEx.GetInt(0, this.Temps.length)]); + const slotData: any = this.Temps[RandomEx.GetInt(0, this.Temps.length)]; let totalGet: number = 0; if (slotData.line) { @@ -57,7 +74,7 @@ export default abstract class SlotSpinBase { let freeData = []; let totalFreeGet = 0; for (let i: number = 0; i < count; i++) { - const slotData: any = JSON.parse(this.FreeTemps[RandomEx.GetInt(0, this.FreeTemps.length)]); + const slotData: any = this.FreeTemps[RandomEx.GetInt(0, this.FreeTemps.length)]; freeData.push(slotData); if (slotData.line) { totalFreeGet += this.getLineGet(slotData.line); @@ -90,6 +107,14 @@ export default abstract class SlotSpinBase { let totalGet: number = scatter[0][1]; return totalGet; } + + protected async GetTemps(): Promise { + const filePath = getExternalJsonPath(`slot${this.ID}.json`); + console.log('filePath', filePath); + const data = await fs.promises.readFile(filePath, 'utf-8'); + const jsonData = JSON.parse(data); + return jsonData; + } } diff --git a/src/api/slot1/spin.ts b/src/api/slot1/spin.ts index 9c640ec..0fbabb6 100644 --- a/src/api/slot1/spin.ts +++ b/src/api/slot1/spin.ts @@ -1,32 +1,7 @@ -import SlotSpinBase from "../slot/spin"; - +import SlotSpinBase from "../slot/SlotSpinBase"; export default class SlotSpin1 extends SlotSpinBase { protected ID: number = 1; protected IsHaveFreeSpin: boolean = true; protected IsHaveRetriggerFreeSpin: boolean = true; - - protected Temps: string[] = [ - `{"slot":[11,4,8,9,5,2,13,10,7,9,10,6,6,12,4],"line":[[[5,11,12],161,200]]}`, - `{"slot":[9,6,2,5,4,14,10,9,13,10,4,5,5,2,2]}`, - `{"slot":[4,3,3,3,9,10,14,14,9,4,7,8,8,5,10],"free":[[1,2,3],3],"scatter":[[[1,2,3],300]]}`, - `{"slot":[1,2,4,5,6,7,3,3,3,8,9,10,11,12,13],"free":[[6,7,8],10],"scatter":[[[6,7,8],300]]}`, - ]; - protected FreeTemps: string[] = [ - `{"slot":[9,9,10,13,4,5,4,3,4,11,10,14,14,14,5]}`, - `{"slot":[12,6,8,12,11,7,12,11,5,5,11,5,3,10,9]}`, - `{"slot":[4,6,11,13,8,12,12,3,4,10,7,5,14,14,4]}`, - `{"slot":[12,11,9,14,6,7,2,3,8,8,11,10,10,7,14]}`, - `{"slot":[9,14,13,4,11,4,7,6,14,6,12,13,9,12,12]}`, - `{"slot":[10,3,12,13,5,6,4,8,4,9,13,14,11,14,4]}`, - `{"slot":[11,13,9,8,5,8,5,5,13,9,14,9,12,4,7]}`, - // `{"slot":[10,14,13,9,8,6,6,6,4,13,13,12,9,14,4],"line":[[[5,6,7],122,300]]}`, - // `{"slot":[13,9,5,14,4,9,4,12,12,11,4,14,8,7,6],"line":[[[10,6],195,300],[[10,6],213,300]]}`, - // `{"slot":[5,9,9,3,11,10,4,5,12,5,4,14,12,5,9],"line":[[[10,6],195,300],[[10,6],213,300]]}`, - // `{"slot":[2,8,13,2,10,9,12,5,11,4,5,2,12,5,8],"line":[[[0,6,12],49,150],[[0,11,2],61,150],[[0,11,7,13],70,3000],[[0,11,12],79,150],[[10,11,7,13],234,3000]]}`, - // `{"slot":[5,12,13,3,4,10,2,5,8,8,2,9,12,10,9],"line":[[[10,1,12],183,150],[[10,6,2],195,150],[[10,6,12],213,150]]}`, - `{"slot":[14,4,10,3,11,5,14,3,12,6,10,6,14,5,12],"line":[[[0,6,12],49,750]],"scatter":[[[3,7],300]]}`, - `{"slot":[6,3,12,4,8,14,10,3,7,9,10,4,10,6,7],"line":[[[10,6,12],213,75]],"scatter":[[[1,7],300]]}`, - `{"slot":[9,12,3,7,2,6,13,11,3,11,13,3,8,6,6],"free":[[2,8,11],10],"scatter":[[[2,8,11],900]]}`, - ]; } \ No newline at end of file diff --git a/src/electron/index.html b/src/electron/index.html index bb569a7..175dec0 100644 --- a/src/electron/index.html +++ b/src/electron/index.html @@ -19,6 +19,7 @@ +

Status: Waiting for actions...

diff --git a/src/electron/main.ts b/src/electron/main.ts index d8dc520..af2a6c0 100644 --- a/src/electron/main.ts +++ b/src/electron/main.ts @@ -7,6 +7,7 @@ import "module-alias/register"; import dotenv from 'dotenv'; import { app, BrowserWindow, ipcMain } from 'electron'; +import fs from 'fs'; import * as path from 'path'; import { WebSocketServer } from 'ws'; import { BaseEnumerator } from "../CatanEngine/CoroutineV2/Core/BaseEnumerator"; @@ -16,8 +17,15 @@ onload(); function onload() { BaseEnumerator.Init(); + setLog(); // Load environment variables from .env file - dotenv.config(); + const filePath = ".env.dev"; + // 检查文件是否存在 + if (fs.existsSync(filePath)) { + dotenv.config({ path: `.env.dev` }); + } else { + dotenv.config({ path: path.resolve(__dirname, `../../.env.prod`) }); + } } let server: WebSocketServer | null = null; @@ -61,38 +69,39 @@ app.on('window-all-closed', () => { }); // 启动 WebSocket 服务器 -ipcMain.on('start-websocket', (event, portNumber: number) => { +ipcMain.on('start-websocket', (event: Electron.IpcMainEvent, portNumber: number) => { if (server) { - server.close(); + closeServer(event); } port = portNumber || 8080; - server = new WebSocketServer({ port: port }); + server = new WebSocketServer({ port }); server.on('connection', NetConnector.OnWebSocketConnection); - // server.on('connection', (socket, request) => { - // const ip = request.socket.remoteAddress.replace("::ffff:", "") || 'Unknown IP'; - // console.log(`Client connected from IP: ${ip}`); - // socket.send('Welcome to the WebSocket server'); - - // socket.on('message', (message: string) => { - // console.log(`[RPC] 收到client呼叫: ${message}`); - // socket.send(`Server received your message: ${message}`); - // console.log(`[RPC] 回傳client呼叫: ${message}`); - // }); - - // socket.on('close', () => { - // console.log('Client disconnected'); - // }); - // }); - event.reply('websocket-status', `WebSocket server started on port ${port}`); }); // 关闭 WebSocket 服务器 -ipcMain.on('stop-websocket', (event) => { +ipcMain.on('stop-websocket', (event: Electron.IpcMainEvent) => { + closeServer(event); +}); + +// 打开开发者工具 +ipcMain.on('json-reload', () => { + NetConnector.clients.forEach(client => { + client.jsons = {}; + }); + console.log(`重載成功`); +}); + +// 打开开发者工具 +ipcMain.on('open-devtools', () => { + mainWindow.webContents.openDevTools(); +}); + +function closeServer(event: Electron.IpcMainEvent) { if (server) { server.clients.forEach(client => { if (client.readyState === 1) { @@ -102,51 +111,47 @@ ipcMain.on('stop-websocket', (event) => { server.close((err) => { if (err) { event.reply('websocket-status', 'Failed to stop WebSocket server'); - } else { - event.reply('websocket-status', 'WebSocket server stopped'); } }); + event.reply('websocket-status', 'WebSocket server stopped'); } else { event.reply('websocket-status', 'No WebSocket server is running'); } -}); - -// 打开开发者工具 -ipcMain.on('open-devtools', () => { - mainWindow.webContents.openDevTools(); -}); +} // Create a function to send log messages to the renderer function sendLogToRenderer(window: BrowserWindow, message: string, color: string) { window.webContents.send('log-message', [message, color]); } -// 重寫 console.log 方法以便將訊息發送到渲染進程 -const originalConsoleLog = console.log; -console.log = (...args: any[]) => { - const message = args.join(' '); - originalConsoleLog(message); // 保留原始行為 - if (BrowserWindow.getAllWindows().length > 0) { - sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "green"); // 發送訊息到渲染進程 - } -}; +function setLog() { + // 重寫 console.log 方法以便將訊息發送到渲染進程 + const originalConsoleLog = console.log; + console.log = (...args: any[]) => { + const message = args.join(' '); + originalConsoleLog(message); // 保留原始行為 + if (BrowserWindow.getAllWindows().length > 0) { + sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "green"); // 發送訊息到渲染進程 + } + }; -// 重写 console.warn -const originalConsoleWarn = console.warn; -console.warn = (...args: any[]) => { - const message = args.join(' '); - originalConsoleWarn(message); - if (BrowserWindow.getAllWindows().length > 0) { - sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "yellow"); // 發送訊息到渲染進程 - } -}; + // 重写 console.warn + const originalConsoleWarn = console.warn; + console.warn = (...args: any[]) => { + const message = args.join(' '); + originalConsoleWarn(message); + if (BrowserWindow.getAllWindows().length > 0) { + sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "yellow"); // 發送訊息到渲染進程 + } + }; -// 重写 console.error -const originalConsoleError = console.error; -console.error = (...args: any[]) => { - const message = args.join(' '); - originalConsoleError(message); - if (BrowserWindow.getAllWindows().length > 0) { - sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "red"); // 發送訊息到渲染進程 - } -}; \ No newline at end of file + // 重写 console.error + const originalConsoleError = console.error; + console.error = (...args: any[]) => { + const message = args.join(' '); + originalConsoleError(message); + if (BrowserWindow.getAllWindows().length > 0) { + sendLogToRenderer(BrowserWindow.getAllWindows()[0], message, "red"); // 發送訊息到渲染進程 + } + }; +} \ No newline at end of file diff --git a/src/electron/preload.ts b/src/electron/preload.ts index ececf4d..f9a874a 100644 --- a/src/electron/preload.ts +++ b/src/electron/preload.ts @@ -5,6 +5,7 @@ import { contextBridge, ipcRenderer } from 'electron'; contextBridge.exposeInMainWorld('electron', { startWebSocket: (port: number) => ipcRenderer.send('start-websocket', port), stopWebSocket: () => ipcRenderer.send('stop-websocket'), + jsonReload: () => ipcRenderer.send('json-reload'), openDevTools: () => ipcRenderer.send('open-devtools'), onWebSocketStatus: (callback: (message: string) => void) => ipcRenderer.on('websocket-status', (event, message) => callback(message)), onLogMessage: (callback: (message: string, color: string) => void) => ipcRenderer.on('log-message', (event, [message, color]) => callback(message, color)), diff --git a/src/electron/renderer.ts b/src/electron/renderer.ts index 4ae290d..a17b0b0 100644 --- a/src/electron/renderer.ts +++ b/src/electron/renderer.ts @@ -56,6 +56,10 @@ document.getElementById('stopBtn')?.addEventListener('click', () => { window.electron.stopWebSocket(); }); +document.getElementById('jsonReload')?.addEventListener('click', () => { + window.electron.jsonReload(); +}); + document.getElementById('devToolsBtn')?.addEventListener('click', () => { window.electron.openDevTools(); }); diff --git a/src/global.d.ts b/src/global.d.ts index 5ec2625..12abb2f 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -3,6 +3,7 @@ interface Window { electron: { startWebSocket: (port: number) => void; stopWebSocket: () => void; + jsonReload: () => void; openDevTools: () => void; onWebSocketStatus: (callback: (message: string) => void) => void; onLogMessage: (callback: (message: string, color: string) => void) => void; // 添加這行以處理日誌消息 diff --git a/src/pkg/server.ts b/src/pkg/server.ts index 75f372e..687fe45 100644 --- a/src/pkg/server.ts +++ b/src/pkg/server.ts @@ -16,7 +16,7 @@ ws://127.0.0.1:9005 */ const port: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080; // 默认端口为 8080 -const server = new WebSocketServer({ port: 8080 }); +const server = new WebSocketServer({ port }); // server.on('connection', (socket: WebSocket) => { // console.log('客户端已连接'); diff --git a/src/script/Engine/CatanEngine/NetManagerV2/NetConnector.ts b/src/script/Engine/CatanEngine/NetManagerV2/NetConnector.ts index 5ae85b2..c6c0b9e 100644 --- a/src/script/Engine/CatanEngine/NetManagerV2/NetConnector.ts +++ b/src/script/Engine/CatanEngine/NetManagerV2/NetConnector.ts @@ -19,7 +19,7 @@ export class NetConnector { const ip = request.socket.remoteAddress.replace("::ffff:", "") || 'Unknown IP'; console.log(`Client connected from IP: ${ip}`); - NetConnector.clients.set(socket, { socket, id: id, name: "", money: 0 }); + NetConnector.clients.set(socket, { socket, id: id, name: "", money: 0, jsons: {} }); id++; socket.on('message', (message: Buffer) => NetConnector.OnWebSocketMessage(socket, message)); diff --git a/src/shared/protocols/define/interface.ts b/src/shared/protocols/define/interface.ts index 60f6a6f..09f6c55 100644 --- a/src/shared/protocols/define/interface.ts +++ b/src/shared/protocols/define/interface.ts @@ -6,5 +6,6 @@ export interface ClientData { id: number; name: string; money: number; + jsons: { [key: number]: any; }; free?: { count: number, freeData: any[] }; } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e1e7add..7f00926 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,6 @@ "include": [ "src/**/*.ts" ], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist", "release"] } \ No newline at end of file diff --git a/tsrpc.config.ts b/tsrpc.config.ts deleted file mode 100644 index 8d45a32..0000000 --- a/tsrpc.config.ts +++ /dev/null @@ -1,38 +0,0 @@ -import type { TsrpcConfig } from "tsrpc-cli"; - -export default { - // Generate ServiceProto - proto: [ - { - ptlDir: "src/shared/protocols", // Protocol dir - output: "src/shared/protocols/serviceProto.ts", // Path for generated ServiceProto - apiDir: "src/api", // API dir - docDir: "docs", // API documents dir - ptlTemplate: { baseFile: "src/shared/protocols/base.ts" }, - // msgTemplate: { baseFile: 'src/shared/protocols/base.ts' }, - } - ], - // Sync shared code - sync: [ - { - from: "src/shared", - // to: "../GuessWhoIAm/src/shared", - type: "copy" // Change this to 'copy' if your environment not support symlink - } - ], - // Dev server - dev: { - autoProto: true, // Auto regenerate proto - autoSync: true, // Auto sync when file changed - autoApi: true, // Auto create API when ServiceProto updated - watch: "src", // Restart dev server when these files changed - entry: "src/index.ts", // Dev server command: node -r ts-node/register {entry} - }, - // Build config - build: { - autoProto: true, // Auto generate proto before build - autoSync: true, // Auto sync before build - autoApi: true, // Auto generate API before build - outDir: "dist", // Clean this dir before build - } -}; \ No newline at end of file