koishipro-core.js 1.0.6 → 1.0.7

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 (2) hide show
  1. package/README.md +26 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -19,24 +19,35 @@ npm install koishipro-core.js
19
19
 
20
20
  ## Quick Start
21
21
  ```ts
22
- import { createOcgcoreWrapper, ZipReader, createSqljsCardReader } from 'koishipro-core.js';
22
+ import {
23
+ createOcgcoreWrapper,
24
+ ZipReader,
25
+ DirReader,
26
+ createSqljsCardReader,
27
+ } from 'koishipro-core.js';
23
28
  import initSqlJs from 'sql.js';
24
29
 
25
30
  const wrapper = await createOcgcoreWrapper();
26
31
 
27
- // Provide scripts via zip
32
+ // Provide scripts via zip + local directory fallback (Node only)
28
33
  const zipBytes = await fetch('/script.zip').then((r) => r.arrayBuffer());
29
- wrapper.setScriptReader(await ZipReader(new Uint8Array(zipBytes)));
34
+ wrapper
35
+ .setScriptReader(await ZipReader(new Uint8Array(zipBytes)), true)
36
+ .setScriptReader(DirReader('./ygopro-scripts'));
30
37
 
31
38
  // Provide cards via sql.js
32
39
  const SQL = await initSqlJs();
33
40
  const db = new SQL.Database(await fetch('/cards.cdb').then((r) => r.arrayBuffer()));
34
41
  wrapper.setCardReader(createSqljsCardReader(db));
35
42
 
36
- // Optional: log messages from ocgcore
37
- wrapper.setMessageHandler((_duel, message, type) => {
38
- console.log(type, message);
39
- });
43
+ // Optional: log messages from ocgcore (multiple handlers allowed)
44
+ wrapper
45
+ .setMessageHandler((_duel, message, type) => {
46
+ console.log(type, message);
47
+ }, true)
48
+ .setMessageHandler((_duel, message, type) => {
49
+ if (type === 1) console.error(message);
50
+ });
40
51
 
41
52
  const duel = wrapper.createDuel(1234);
42
53
  duel.setPlayerInfo({ playerId: 0, lp: 8000, startCount: 5, drawCount: 1 });
@@ -74,15 +85,18 @@ console.log('message count:', messages.length);
74
85
  - `createOcgcoreWrapper(options?)`
75
86
  Load the ocgcore WASM module and return an `OcgcoreWrapper`.
76
87
  - `OcgcoreWrapper`
77
- Manages the WASM module, script/card/message handlers, and duel creation.
88
+ Manages the WASM module, script/card/message handlers, and duel creation.
89
+ Script readers and handlers can be registered multiple times (fallback/fan-out).
78
90
  - `OcgcoreDuel`
79
91
  Duel lifecycle and core engine calls (`startDuel`, `process`, `setResponse`, etc.).
80
92
 
81
93
  ### 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`.
94
+ - `MapReader(...maps)`
95
+ Resolve Lua scripts from one or more `Map<string, string | Uint8Array>` with fallback.
96
+ - `ZipReader(...zipBytes)`
97
+ Load all `.lua` files from one or more zips and expose them via `MapReader` (fallback order).
98
+ - `DirReader(...dirs)`
99
+ Node-only directory reader with the same resolution rules (fallback order).
86
100
 
87
101
  ### Replay
88
102
  - `playYrp(wrapper, yrpOrBytes)`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishipro-core.js",
3
3
  "description": "WASM wrapper for YGOPro/ocgcore, designed for both Node and browser runtimes.",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",