koishipro-core.js 1.1.1 → 1.1.3

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/README.md CHANGED
@@ -22,9 +22,9 @@ npm install koishipro-core.js
22
22
  ```ts
23
23
  import {
24
24
  createOcgcoreWrapper,
25
- ZipReader,
26
- DirReader,
27
- createSqljsCardReader,
25
+ ZipScriptReader,
26
+ DirScriptReader,
27
+ SqljsCardReader,
28
28
  } from 'koishipro-core.js';
29
29
  import initSqlJs from 'sql.js';
30
30
 
@@ -33,13 +33,13 @@ const wrapper = await createOcgcoreWrapper();
33
33
  // Provide scripts via zip + local directory fallback (Node only)
34
34
  const zipBytes = await fetch('/script.zip').then((r) => r.arrayBuffer());
35
35
  wrapper
36
- .setScriptReader(await ZipReader(new Uint8Array(zipBytes)), true)
37
- .setScriptReader(DirReader('./ygopro-scripts'));
36
+ .setScriptReader(await ZipScriptReader(new Uint8Array(zipBytes)), true)
37
+ .setScriptReader(DirScriptReader('./ygopro-scripts'));
38
38
 
39
39
  // Provide cards via sql.js
40
40
  const SQL = await initSqlJs();
41
41
  const db = new SQL.Database(await fetch('/cards.cdb').then((r) => r.arrayBuffer()));
42
- wrapper.setCardReader(createSqljsCardReader(db));
42
+ wrapper.setCardReader(SqljsCardReader(db));
43
43
 
44
44
  // Optional: log messages from ocgcore (multiple handlers allowed)
45
45
  wrapper
@@ -202,29 +202,32 @@ Represents a single duel instance with full lifecycle management.
202
202
 
203
203
  ### Script Readers
204
204
 
205
- #### `MapReader(...maps: Map<string, string | Uint8Array>[]): ScriptReader`
205
+ #### `MapScriptReader(...maps: Map<string, string | Uint8Array>[]): ScriptReader`
206
206
  Resolve Lua scripts from one or more Maps with fallback order.
207
207
 
208
208
  ```ts
209
209
  const scripts = new Map([
210
210
  ['c12345.lua', 'function c12345.initial_effect(c) end'],
211
211
  ]);
212
- wrapper.setScriptReader(MapReader(scripts));
212
+ wrapper.setScriptReader(MapScriptReader(scripts));
213
213
  ```
214
214
 
215
- #### `ZipReader(...zipBytes: Uint8Array[]): Promise<ScriptReader>`
215
+ #### `ZipScriptReader(...zipBytes: Uint8Array[]): Promise<ScriptReader>`
216
216
  Load all `.lua` files from one or more zips.
217
217
 
218
218
  ```ts
219
219
  const zipBytes = await fetch('/scripts.zip').then(r => r.arrayBuffer());
220
- wrapper.setScriptReader(await ZipReader(new Uint8Array(zipBytes)));
220
+ wrapper.setScriptReader(await ZipScriptReader(new Uint8Array(zipBytes)));
221
221
  ```
222
222
 
223
- #### `DirReader(...dirs: string[]): ScriptReader`
223
+ #### `DirScriptReader(...dirs: string[]): ScriptReader`
224
224
  Node-only directory reader with fallback order.
225
225
 
226
226
  ```ts
227
- wrapper.setScriptReader(DirReader('./ygopro-scripts', './custom-scripts'));
227
+ wrapper.setScriptReader(DirScriptReader('./ygopro-scripts', './custom-scripts'));
228
+
229
+ #### `DirScriptReaderEx(...dirs: string[]): Promise<ScriptReader>`
230
+ Node-only directory reader with zip/ypk fallback. Zips are scanned in project root and `expansions/` with lower priority than filesystem scripts.
228
231
  ```
229
232
 
230
233
  ### Replay Functions
@@ -266,7 +269,7 @@ for (const { duel, result } of playYrpStep(wrapper, yrpBytes)) {
266
269
 
267
270
  ### Card Reader
268
271
 
269
- #### `createSqljsCardReader(...dbs: Database[]): CardReader`
272
+ #### `SqljsCardReader(...dbs: Database[]): CardReader`
270
273
  Build a `CardReader` from one or more SQL.js databases with fallback order.
271
274
 
272
275
  ```ts
@@ -277,7 +280,10 @@ const db1 = new SQL.Database(officialCards);
277
280
  const db2 = new SQL.Database(customCards);
278
281
 
279
282
  // Try db1 first, fallback to db2
280
- wrapper.setCardReader(createSqljsCardReader(db1, db2));
283
+ wrapper.setCardReader(SqljsCardReader(db1, db2));
284
+
285
+ #### `DirCardReader(sqljs: SqlJsStatic, ...dirs: string[]): Promise<CardReader>`
286
+ Node-only card reader that loads `cards.cdb`, `expansions/*.cdb`, and root-level `.cdb` files inside `*.zip`/`*.ypk` archives under each directory.
281
287
  ```
282
288
 
283
289
  ### Constants