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.
Files changed (51) hide show
  1. package/.eslintignore +6 -0
  2. package/.eslintrc.js +25 -0
  3. package/.prettierrc +4 -0
  4. package/LICENSE +22 -0
  5. package/README.md +108 -0
  6. package/dist/index.cjs +2445 -0
  7. package/dist/index.cjs.map +7 -0
  8. package/dist/index.d.ts +11 -0
  9. package/dist/index.mjs +2384 -0
  10. package/dist/index.mjs.map +7 -0
  11. package/dist/src/adapters/index.d.ts +3 -0
  12. package/dist/src/adapters/ocgcore-parsers.d.ts +7 -0
  13. package/dist/src/adapters/script-readers.d.ts +3 -0
  14. package/dist/src/adapters/start-duel.d.ts +2 -0
  15. package/dist/src/constants/index.d.ts +1 -0
  16. package/dist/src/constants/ocgcore.d.ts +6 -0
  17. package/dist/src/create-ocgcore-wrapper.d.ts +8 -0
  18. package/dist/src/load-ocgcore-factory.cjs.d.ts +2 -0
  19. package/dist/src/load-ocgcore-factory.d.ts +1 -0
  20. package/dist/src/load-ocgcore-factory.esm.d.ts +2 -0
  21. package/dist/src/ocgcore-duel.d.ts +31 -0
  22. package/dist/src/ocgcore-wrapper-utils.d.ts +2 -0
  23. package/dist/src/ocgcore-wrapper.d.ts +48 -0
  24. package/dist/src/play-yrp.d.ts +3 -0
  25. package/dist/src/sqljs-card-reader.d.ts +3 -0
  26. package/dist/src/structs/card-data.d.ts +14 -0
  27. package/dist/src/structs/index.d.ts +1 -0
  28. package/dist/src/types/card-data.d.ts +18 -0
  29. package/dist/src/types/index.d.ts +5 -0
  30. package/dist/src/types/ocgcore-enums.d.ts +21 -0
  31. package/dist/src/types/ocgcore-params.d.ts +42 -0
  32. package/dist/src/types/ocgcore-readers.d.ts +1 -0
  33. package/dist/src/types/ocgcore-results.d.ts +101 -0
  34. package/dist/src/utility/binary.d.ts +4 -0
  35. package/dist/src/utility/index.d.ts +2 -0
  36. package/dist/src/utility/utf8.d.ts +2 -0
  37. package/dist/src/vendor/index.d.ts +2 -0
  38. package/dist/src/vendor/ocgcore-constants.d.ts +360 -0
  39. package/dist/src/vendor/script-constants.d.ts +836 -0
  40. package/dist/vendor/libocgcore.shared.d.ts +42 -0
  41. package/dist/vendor/wasm_cjs/libocgcore.cjs +5557 -0
  42. package/dist/vendor/wasm_cjs/libocgcore.cjs.d.ts +4 -0
  43. package/dist/vendor/wasm_cjs/libocgcore.wasm +0 -0
  44. package/dist/vendor/wasm_esm/libocgcore.mjs +5557 -0
  45. package/dist/vendor/wasm_esm/libocgcore.mjs.d.ts +4 -0
  46. package/dist/vendor/wasm_esm/libocgcore.wasm +0 -0
  47. package/index.ts +17 -0
  48. package/package.json +80 -0
  49. package/scripts/download-vendor.js +41 -0
  50. package/scripts/gen-constants.js +156 -0
  51. package/tsconfig.json +20 -0
package/.eslintignore ADDED
@@ -0,0 +1,6 @@
1
+ webpack.config.js
2
+ dist/*
3
+ build/*
4
+ *.js
5
+
6
+ /src/vendor
package/.eslintrc.js ADDED
@@ -0,0 +1,25 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ parserOptions: {
4
+ project: 'tsconfig.json',
5
+ tsconfigRootDir : __dirname,
6
+ sourceType: 'module',
7
+ },
8
+ plugins: ['@typescript-eslint/eslint-plugin'],
9
+ extends: [
10
+ 'plugin:@typescript-eslint/recommended',
11
+ 'plugin:prettier/recommended',
12
+ ],
13
+ root: true,
14
+ env: {
15
+ node: true,
16
+ jest: true,
17
+ },
18
+ ignorePatterns: ['.eslintrc.js'],
19
+ rules: {
20
+ '@typescript-eslint/interface-name-prefix': 'off',
21
+ '@typescript-eslint/explicit-function-return-type': 'off',
22
+ '@typescript-eslint/explicit-module-boundary-types': 'off',
23
+ '@typescript-eslint/no-explicit-any': 'off',
24
+ },
25
+ };
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Nanahira
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # koishipro-core.js
2
+
3
+ WASM wrapper for YGOPro/ocgcore, designed for both Node and browser runtimes.
4
+ Provides a clean TypeScript API around the Emscripten module, replay playback, and
5
+ helpers for loading scripts/cards.
6
+
7
+ ## Features
8
+ - Load ocgcore WASM (CJS or ESM) and create duels
9
+ - TypeScript-friendly wrapper around duel APIs
10
+ - Script readers (Map/Zip) for loading Lua scripts
11
+ - SQL.js card reader helper
12
+ - Replay (YRP/YRP2) playback to raw message streams
13
+ - Constants auto-generated from upstream YGOPro sources
14
+
15
+ ## Install
16
+ ```bash
17
+ npm install koishipro-core.js
18
+ ```
19
+
20
+ ## Quick Start
21
+ ```ts
22
+ import { createOcgcoreWrapper, ZipReader, createSqljsCardReader } from 'koishipro-core.js';
23
+ import initSqlJs from 'sql.js';
24
+
25
+ const wrapper = await createOcgcoreWrapper();
26
+
27
+ // Provide scripts via zip
28
+ const zipBytes = await fetch('/script.zip').then((r) => r.arrayBuffer());
29
+ wrapper.setScriptReader(await ZipReader(new Uint8Array(zipBytes)));
30
+
31
+ // Provide cards via sql.js
32
+ const SQL = await initSqlJs();
33
+ const db = new SQL.Database(await fetch('/cards.cdb').then((r) => r.arrayBuffer()));
34
+ wrapper.setCardReader(createSqljsCardReader(db));
35
+
36
+ // Optional: log messages from ocgcore
37
+ wrapper.setMessageHandler((_duel, message, type) => {
38
+ console.log(type, message);
39
+ });
40
+
41
+ const duel = wrapper.createDuel(1234);
42
+ duel.setPlayerInfo({ playerId: 0, lp: 8000, startCount: 5, drawCount: 1 });
43
+ duel.setPlayerInfo({ playerId: 1, lp: 8000, startCount: 5, drawCount: 1 });
44
+ duel.startDuel(0);
45
+
46
+ const { raw, status } = duel.process();
47
+ console.log(raw, status);
48
+
49
+ duel.endDuel();
50
+ wrapper.finalize();
51
+ ```
52
+
53
+ ## Replay Playback
54
+ `playYrp` replays a `.yrp/.yrp2` file by feeding responses back to ocgcore and
55
+ collecting each engine message as `Uint8Array`. You can pass a parsed `YGOProYrp`
56
+ instance or raw bytes.
57
+
58
+ ```ts
59
+ import { createOcgcoreWrapper, playYrp } from 'koishipro-core.js';
60
+ import { YGOProYrp } from 'ygopro-yrp-encode';
61
+
62
+ const wrapper = await createOcgcoreWrapper();
63
+
64
+ // ...setScriptReader / setCardReader / setMessageHandler...
65
+
66
+ const yrpBytes = await fetch('/replay.yrp').then((r) => r.arrayBuffer());
67
+ const messages = playYrp(wrapper, new Uint8Array(yrpBytes));
68
+ console.log('message count:', messages.length);
69
+ ```
70
+
71
+
72
+ ## API Overview
73
+ ### Core
74
+ - `createOcgcoreWrapper(options?)`
75
+ Load the ocgcore WASM module and return an `OcgcoreWrapper`.
76
+ - `OcgcoreWrapper`
77
+ Manages the WASM module, script/card/message handlers, and duel creation.
78
+ - `OcgcoreDuel`
79
+ Duel lifecycle and core engine calls (`startDuel`, `process`, `setResponse`, etc.).
80
+
81
+ ### Script Readers
82
+ - `MapReader(map)`
83
+ Resolve Lua scripts from a `Map<string, string | Uint8Array>`.
84
+ - `ZipReader(zipBytes)`
85
+ Load all `.lua` files from a zip and expose them via `MapReader`.
86
+
87
+ ### Replay
88
+ - `playYrp(wrapper, yrpOrBytes)`
89
+ Run a replay and return a list of raw message `Uint8Array`s.
90
+ Accepts `YGOProYrp` or raw `.yrp/.yrp2` bytes.
91
+ Throws `Got MSG_RETRY` if a retry is encountered.
92
+
93
+ ### Card Reader
94
+ - `createSqljsCardReader(...dbs)`
95
+ Build a `CardReader` from one or more SQL.js databases.
96
+
97
+ ### Constants
98
+ - `OcgcoreCommonConstants`, `OcgcoreScriptConstants`
99
+ Pre-generated constants from upstream sources.
100
+
101
+ ## Build / Scripts
102
+ - `npm run build` – build CJS + ESM + types
103
+ - `npm run fetch-ocgcore` – download vendor WASM and JS
104
+ - `npm run gen-constants` – regenerate constants from upstream sources
105
+
106
+ ## Notes
107
+ - This package ships both CJS and ESM builds.
108
+ - WASM binaries are bundled under `dist/vendor`.