koishipro-core.js 1.0.2
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/.eslintignore +6 -0
- package/.eslintrc.js +25 -0
- package/.prettierrc +4 -0
- package/LICENSE +22 -0
- package/README.md +108 -0
- package/dist/index.cjs +2445 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.mjs +2384 -0
- package/dist/index.mjs.map +7 -0
- package/dist/src/adapters/index.d.ts +3 -0
- package/dist/src/adapters/ocgcore-parsers.d.ts +7 -0
- package/dist/src/adapters/script-readers.d.ts +3 -0
- package/dist/src/adapters/start-duel.d.ts +2 -0
- package/dist/src/constants/index.d.ts +1 -0
- package/dist/src/constants/ocgcore.d.ts +6 -0
- package/dist/src/create-ocgcore-wrapper.d.ts +8 -0
- package/dist/src/load-ocgcore-factory.cjs.d.ts +2 -0
- package/dist/src/load-ocgcore-factory.d.ts +1 -0
- package/dist/src/load-ocgcore-factory.esm.d.ts +2 -0
- package/dist/src/ocgcore-duel.d.ts +31 -0
- package/dist/src/ocgcore-wrapper-utils.d.ts +2 -0
- package/dist/src/ocgcore-wrapper.d.ts +48 -0
- package/dist/src/play-yrp.d.ts +3 -0
- package/dist/src/sqljs-card-reader.d.ts +3 -0
- package/dist/src/structs/card-data.d.ts +14 -0
- package/dist/src/structs/index.d.ts +1 -0
- package/dist/src/types/card-data.d.ts +18 -0
- package/dist/src/types/index.d.ts +5 -0
- package/dist/src/types/ocgcore-enums.d.ts +21 -0
- package/dist/src/types/ocgcore-params.d.ts +42 -0
- package/dist/src/types/ocgcore-readers.d.ts +1 -0
- package/dist/src/types/ocgcore-results.d.ts +101 -0
- package/dist/src/utility/binary.d.ts +4 -0
- package/dist/src/utility/index.d.ts +2 -0
- package/dist/src/utility/utf8.d.ts +2 -0
- package/dist/src/vendor/index.d.ts +2 -0
- package/dist/src/vendor/ocgcore-constants.d.ts +360 -0
- package/dist/src/vendor/script-constants.d.ts +836 -0
- package/dist/vendor/libocgcore.shared.d.ts +42 -0
- package/dist/vendor/wasm_cjs/libocgcore.cjs +5557 -0
- package/dist/vendor/wasm_cjs/libocgcore.cjs.d.ts +4 -0
- package/dist/vendor/wasm_cjs/libocgcore.wasm +0 -0
- package/dist/vendor/wasm_esm/libocgcore.mjs +5557 -0
- package/dist/vendor/wasm_esm/libocgcore.mjs.d.ts +4 -0
- package/dist/vendor/wasm_esm/libocgcore.wasm +0 -0
- package/index.ts +17 -0
- package/package.json +80 -0
- package/scripts/download-vendor.js +41 -0
- package/scripts/gen-constants.js +156 -0
- package/tsconfig.json +20 -0
|
Binary file
|
package/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
|
|
3
|
+
if (typeof globalThis !== 'undefined' && !(globalThis as { Buffer?: unknown }).Buffer) {
|
|
4
|
+
(globalThis as { Buffer?: unknown }).Buffer = Buffer;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export * from './src/ocgcore-wrapper';
|
|
8
|
+
export * from './src/ocgcore-duel';
|
|
9
|
+
export * from './src/create-ocgcore-wrapper';
|
|
10
|
+
export * from './src/types';
|
|
11
|
+
export * from './src/structs';
|
|
12
|
+
export * from './src/adapters';
|
|
13
|
+
export * from './src/constants';
|
|
14
|
+
export * from './src/utility';
|
|
15
|
+
export * from './src/vendor';
|
|
16
|
+
export * from './src/sqljs-card-reader';
|
|
17
|
+
export * from './src/play-yrp';
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishipro-core.js",
|
|
3
|
+
"description": "WASM wrapper for YGOPro/ocgcore, designed for both Node and browser runtimes.",
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"lint": "eslint --fix .",
|
|
17
|
+
"build": "node build.js",
|
|
18
|
+
"build:cjs": "node build.js cjs",
|
|
19
|
+
"build:esm": "node build.js esm",
|
|
20
|
+
"build:types": "node build.js types",
|
|
21
|
+
"clean": "node build.js clean",
|
|
22
|
+
"gen-constants": "node scripts/gen-constants.js",
|
|
23
|
+
"test": "jest --passWithNoTests",
|
|
24
|
+
"start": "node dist/index.cjs",
|
|
25
|
+
"fetch-ocgcore": "node scripts/download-vendor.js"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/purerosefallen/koishipro-core.js.git"
|
|
30
|
+
},
|
|
31
|
+
"author": "Nanahira <nanahira@momobako.com>",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"keywords": [],
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/purerosefallen/koishipro-core.js/issues"
|
|
36
|
+
},
|
|
37
|
+
"homepage": "https://github.com/purerosefallen/koishipro-core.js",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@types/emscripten": "^1.41.5",
|
|
40
|
+
"@types/sql.js": "^1.4.9",
|
|
41
|
+
"buffer": "^6.0.3",
|
|
42
|
+
"jszip": "^3.10.1",
|
|
43
|
+
"sql.js": "^1.13.0",
|
|
44
|
+
"typed-struct": "^1.3.0",
|
|
45
|
+
"ygopro-yrp-encode": "^1.0.1"
|
|
46
|
+
},
|
|
47
|
+
"jest": {
|
|
48
|
+
"moduleFileExtensions": [
|
|
49
|
+
"js",
|
|
50
|
+
"json",
|
|
51
|
+
"ts"
|
|
52
|
+
],
|
|
53
|
+
"rootDir": "tests",
|
|
54
|
+
"testRegex": ".*\\.spec\\.ts$",
|
|
55
|
+
"transform": {
|
|
56
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
57
|
+
},
|
|
58
|
+
"collectCoverageFrom": [
|
|
59
|
+
"**/*.(t|j)s"
|
|
60
|
+
],
|
|
61
|
+
"coverageDirectory": "../coverage",
|
|
62
|
+
"testEnvironment": "node"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/jest": "^30.0.0",
|
|
66
|
+
"@types/node": "^25.1.0",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
68
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
69
|
+
"axios": "^1.12.2",
|
|
70
|
+
"esbuild": "^0.27.2",
|
|
71
|
+
"esbuild-register": "^3.6.0",
|
|
72
|
+
"eslint": "8.22.0",
|
|
73
|
+
"eslint-config-prettier": "^9.1.2",
|
|
74
|
+
"eslint-plugin-prettier": "^5.5.5",
|
|
75
|
+
"jest": "^30.2.0",
|
|
76
|
+
"prettier": "^3.8.1",
|
|
77
|
+
"ts-jest": "^29.4.6",
|
|
78
|
+
"typescript": "^5.9.3"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const fs = require("node:fs");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const { pipeline } = require("node:stream/promises");
|
|
4
|
+
const axios = require("axios");
|
|
5
|
+
|
|
6
|
+
const files = [
|
|
7
|
+
{
|
|
8
|
+
url: "https://cdntx.moecube.com/libocgcore-koishi/wasm_cjs/libocgcore.cjs",
|
|
9
|
+
dest: path.join("src", "vendor", "wasm_cjs", "libocgcore.cjs"),
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
url: "https://cdntx.moecube.com/libocgcore-koishi/wasm_cjs/libocgcore.wasm",
|
|
13
|
+
dest: path.join("src", "vendor", "wasm_cjs", "libocgcore.wasm"),
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
url: "https://cdntx.moecube.com/libocgcore-koishi/wasm_esm/libocgcore.mjs",
|
|
17
|
+
dest: path.join("src", "vendor", "wasm_esm", "libocgcore.mjs"),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
url: "https://cdntx.moecube.com/libocgcore-koishi/wasm_esm/libocgcore.wasm",
|
|
21
|
+
dest: path.join("src", "vendor", "wasm_esm", "libocgcore.wasm"),
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
async function download(url, dest) {
|
|
26
|
+
await fs.promises.mkdir(path.dirname(dest), { recursive: true });
|
|
27
|
+
const response = await axios.get(url, { responseType: "stream" });
|
|
28
|
+
const fileStream = fs.createWriteStream(dest);
|
|
29
|
+
await pipeline(response.data, fileStream);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
for (const file of files) {
|
|
34
|
+
await download(file.url, file.dest);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
main().catch((err) => {
|
|
39
|
+
console.error(err);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const ROOT = path.resolve(__dirname, '..');
|
|
5
|
+
const COMMON_H = '/home/nanahira/ygo/ygopro/ocgcore/common.h';
|
|
6
|
+
const SCRIPT_CONSTANT_LUA = '/home/nanahira/ygo/ygopro/script/constant.lua';
|
|
7
|
+
const OUT_OCORE = path.join(ROOT, 'src', 'vendor', 'ocgcore-constants.ts');
|
|
8
|
+
const OUT_SCRIPT = path.join(ROOT, 'src', 'vendor', 'script-constants.ts');
|
|
9
|
+
|
|
10
|
+
function readFileSafe(file) {
|
|
11
|
+
try {
|
|
12
|
+
return fs.readFileSync(file, 'utf8');
|
|
13
|
+
} catch (err) {
|
|
14
|
+
console.error(`[gen-constants] Failed to read: ${file}`);
|
|
15
|
+
throw err;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function parseNumber(raw) {
|
|
20
|
+
const cleaned = raw.replace(/\s+/g, '');
|
|
21
|
+
if (/^0x[0-9a-fA-F]+$/.test(cleaned)) return Number.parseInt(cleaned, 16);
|
|
22
|
+
if (/^\d+$/.test(cleaned)) return Number.parseInt(cleaned, 10);
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function sanitizeExpr(expr) {
|
|
27
|
+
return expr
|
|
28
|
+
.replace(/\/\/.*$/g, '')
|
|
29
|
+
.replace(/\/\*.*?\*\//g, '')
|
|
30
|
+
.replace(/\bU\b/g, '')
|
|
31
|
+
.replace(/\bUL\b/g, '')
|
|
32
|
+
.replace(/\bULL\b/g, '')
|
|
33
|
+
.replace(/\bL\b/g, '')
|
|
34
|
+
.replace(/\s+/g, '');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function evalExpr(expr, constants) {
|
|
38
|
+
const clean = sanitizeExpr(expr);
|
|
39
|
+
const tokens = clean
|
|
40
|
+
.replace(/<<|>>/g, (m) => ` ${m} `)
|
|
41
|
+
.split(/\s+/)
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.flatMap((token) => token.split(/([+\-*/()|&~^<>])/).filter(Boolean));
|
|
44
|
+
|
|
45
|
+
const values = tokens.map((t) => {
|
|
46
|
+
if (
|
|
47
|
+
t === '+' ||
|
|
48
|
+
t === '-' ||
|
|
49
|
+
t === '*' ||
|
|
50
|
+
t === '/' ||
|
|
51
|
+
t === '(' ||
|
|
52
|
+
t === ')' ||
|
|
53
|
+
t === '|' ||
|
|
54
|
+
t === '&' ||
|
|
55
|
+
t === '~' ||
|
|
56
|
+
t === '^' ||
|
|
57
|
+
t === '<' ||
|
|
58
|
+
t === '>' ||
|
|
59
|
+
t === '<<' ||
|
|
60
|
+
t === '>>'
|
|
61
|
+
) {
|
|
62
|
+
return t;
|
|
63
|
+
}
|
|
64
|
+
const num = parseNumber(t);
|
|
65
|
+
if (num !== null) return num;
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(constants, t)) return constants[t];
|
|
67
|
+
return NaN;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
if (values.some((v) => Number.isNaN(v))) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const exprStr = values.join('');
|
|
75
|
+
// eslint-disable-next-line no-new-func
|
|
76
|
+
return Function(`"use strict";return (${exprStr});`)();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseCDefines(source) {
|
|
80
|
+
const lines = source.split(/\r?\n/);
|
|
81
|
+
const constants = {};
|
|
82
|
+
|
|
83
|
+
for (const line of lines) {
|
|
84
|
+
const trimmed = line.trim();
|
|
85
|
+
if (!trimmed.startsWith('#define ')) continue;
|
|
86
|
+
const content = trimmed.slice('#define '.length).trim();
|
|
87
|
+
if (!content) continue;
|
|
88
|
+
const parts = content.split(/\s+/);
|
|
89
|
+
const name = parts.shift();
|
|
90
|
+
if (!name) continue;
|
|
91
|
+
if (name.includes('(')) continue; // macro with args
|
|
92
|
+
const valueRaw = parts.join(' ');
|
|
93
|
+
if (!valueRaw) continue;
|
|
94
|
+
const value = evalExpr(valueRaw, constants);
|
|
95
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
96
|
+
constants[name] = value;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return constants;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function parseLuaConstants(source) {
|
|
104
|
+
const lines = source.split(/\r?\n/);
|
|
105
|
+
const constants = {};
|
|
106
|
+
|
|
107
|
+
for (const line of lines) {
|
|
108
|
+
const trimmed = line.trim();
|
|
109
|
+
if (!trimmed || trimmed.startsWith('--')) continue;
|
|
110
|
+
const match = /^([A-Z0-9_]+)\s*=\s*([^\-]+?)(?:\s+--.*)?$/.exec(trimmed);
|
|
111
|
+
if (!match) continue;
|
|
112
|
+
const name = match[1];
|
|
113
|
+
const valueRaw = match[2].trim();
|
|
114
|
+
const value = evalExpr(valueRaw, constants);
|
|
115
|
+
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
116
|
+
constants[name] = value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return constants;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function emitConstantsTs(objectName, constants, sourcePath) {
|
|
124
|
+
const keys = Object.keys(constants).sort();
|
|
125
|
+
const lines = [];
|
|
126
|
+
lines.push(`// Generated from ${sourcePath}`);
|
|
127
|
+
lines.push(`export const ${objectName} = {`);
|
|
128
|
+
for (const key of keys) {
|
|
129
|
+
const value = constants[key];
|
|
130
|
+
lines.push(` ${key}: ${value},`);
|
|
131
|
+
}
|
|
132
|
+
lines.push(`} as const;`);
|
|
133
|
+
lines.push('');
|
|
134
|
+
return lines.join('\n');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function writeFile(file, content) {
|
|
138
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
139
|
+
fs.writeFileSync(file, content, 'utf8');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function main() {
|
|
143
|
+
const commonSource = readFileSafe(COMMON_H);
|
|
144
|
+
const luaSource = readFileSafe(SCRIPT_CONSTANT_LUA);
|
|
145
|
+
|
|
146
|
+
const ocgcoreConstants = parseCDefines(commonSource);
|
|
147
|
+
const scriptConstants = parseLuaConstants(luaSource);
|
|
148
|
+
|
|
149
|
+
writeFile(OUT_OCORE, emitConstantsTs('OcgcoreCommonConstants', ocgcoreConstants, COMMON_H));
|
|
150
|
+
writeFile(OUT_SCRIPT, emitConstantsTs('OcgcoreScriptConstants', scriptConstants, SCRIPT_CONSTANT_LUA));
|
|
151
|
+
|
|
152
|
+
console.log(`[gen-constants] Wrote ${Object.keys(ocgcoreConstants).length} common.h constants`);
|
|
153
|
+
console.log(`[gen-constants] Wrote ${Object.keys(scriptConstants).length} constant.lua constants`);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
main();
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"outDir": "dist",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"target": "es2021",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"emitDecoratorMetadata": true,
|
|
8
|
+
"experimentalDecorators": true,
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"sourceMap": true
|
|
11
|
+
},
|
|
12
|
+
"compileOnSave": true,
|
|
13
|
+
"allowJs": true,
|
|
14
|
+
"include": [
|
|
15
|
+
"*.ts",
|
|
16
|
+
"src/**/*.ts",
|
|
17
|
+
"test/**/*.ts",
|
|
18
|
+
"tests/**/*.ts"
|
|
19
|
+
]
|
|
20
|
+
}
|