@utsp/core 0.9.0-nightly.20251210150441.b1cbb1e → 0.9.0-nightly.20251211152508.63e8b0d

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/dist/index.d.ts CHANGED
@@ -4,15 +4,49 @@ export { AxisBinding, AxisSource, ButtonBinding, ButtonSource, InputBindingLoadP
4
4
 
5
5
  /**
6
6
  * Font system for UTSP Core
7
- * Supports WebFont (CSS-based) and BitmapFont (pixel-based)
7
+ * Supports WebFont (CSS-based), BitmapFont (pixel-based), and ImageFont (PNG atlas-based)
8
8
  */
9
9
  /**
10
10
  * Font type enumeration
11
11
  */
12
12
  declare enum FontType {
13
13
  Web = "web",
14
- Bitmap = "bitmap"
14
+ Bitmap = "bitmap",
15
+ Image = "image"
15
16
  }
17
+ /**
18
+ * Number of 256-char blocks in an atlas
19
+ * - 1 block = 16×16 grid = 256 chars (8-bit)
20
+ * - 4 blocks = 32×32 grid = 1024 chars (10-bit)
21
+ * - 16 blocks = 64×64 grid = 4096 chars (12-bit)
22
+ */
23
+ type AtlasBlocks = 1 | 4 | 16;
24
+ /**
25
+ * Glyph size in pixels (uniform within an atlas)
26
+ */
27
+ type GlyphSize = 8 | 16 | 32;
28
+ /**
29
+ * Get the number of columns in an atlas grid
30
+ * @param blocks Number of atlas blocks (1, 4, or 16)
31
+ * @returns Number of columns (16, 32, or 64)
32
+ */
33
+ declare function getAtlasColumns(blocks: AtlasBlocks): number;
34
+ /**
35
+ * Get the maximum character code for an atlas configuration
36
+ * @param blocks Number of atlas blocks (1, 4, or 16)
37
+ * @returns Maximum charCode (255, 1023, or 4095)
38
+ */
39
+ declare function getMaxCharCode(blocks: AtlasBlocks): number;
40
+ /**
41
+ * Get atlas dimensions in pixels
42
+ * @param blocks Number of atlas blocks
43
+ * @param glyphSize Size of each glyph in pixels
44
+ * @returns Atlas dimensions { width, height }
45
+ */
46
+ declare function getAtlasDimensions(blocks: AtlasBlocks, glyphSize: GlyphSize): {
47
+ width: number;
48
+ height: number;
49
+ };
16
50
  /**
17
51
  * WebFont configuration
18
52
  * For CSS-based fonts rendered by the browser
@@ -147,6 +181,234 @@ declare class BitmapFont {
147
181
  */
148
182
  getCharCodes(): number[];
149
183
  }
184
+ /**
185
+ * ImageFont configuration
186
+ * For PNG atlas-based fonts with pre-rendered glyphs
187
+ */
188
+ interface ImageFontConfig {
189
+ glyphWidth: number;
190
+ glyphHeight: number;
191
+ cellWidth?: number;
192
+ cellHeight?: number;
193
+ atlasBlocks: AtlasBlocks;
194
+ imageData: Uint8Array;
195
+ }
196
+ /**
197
+ * ImageFont class
198
+ * Represents a PNG atlas-based font for extended character sets
199
+ * Corresponds to LoadType 0x08 (ImageFont) in UTSP protocol
200
+ *
201
+ * Atlas layout for atlasBlocks=4 (1024 chars, 32×32 grid):
202
+ * ```
203
+ * ┌─────────┬─────────┐
204
+ * │ 0-255 │ 256-511 │
205
+ * │ (Bloc 0)│ (Bloc 1)│
206
+ * ├─────────┼─────────┤
207
+ * │ 512-767 │768-1023 │
208
+ * │ (Bloc 2)│ (Bloc 3)│
209
+ * └─────────┴─────────┘
210
+ * ```
211
+ *
212
+ * CharCode to UV mapping:
213
+ * - col = charCode % atlasColumns
214
+ * - row = floor(charCode / atlasColumns)
215
+ * - u = col / atlasColumns
216
+ * - v = row / atlasColumns
217
+ */
218
+ declare class ImageFont {
219
+ private fontId;
220
+ private config;
221
+ private readonly atlasColumns;
222
+ private readonly maxCharCode;
223
+ constructor(fontId: number, config: ImageFontConfig);
224
+ /**
225
+ * Get the unique font ID
226
+ */
227
+ getFontId(): number;
228
+ /**
229
+ * Get the full configuration (copy with new imageData reference)
230
+ */
231
+ getConfig(): ImageFontConfig;
232
+ /**
233
+ * Get the glyph width in pixels
234
+ */
235
+ getGlyphWidth(): number;
236
+ /**
237
+ * Get the glyph height in pixels
238
+ */
239
+ getGlyphHeight(): number;
240
+ /**
241
+ * Get the target cell width in pixels (rendering size)
242
+ */
243
+ getCellWidth(): number;
244
+ /**
245
+ * Get the target cell height in pixels (rendering size)
246
+ */
247
+ getCellHeight(): number;
248
+ /**
249
+ * Get the number of atlas blocks
250
+ */
251
+ getAtlasBlocks(): AtlasBlocks;
252
+ /**
253
+ * Get the number of columns in the atlas grid
254
+ */
255
+ getAtlasColumns(): number;
256
+ /**
257
+ * Get the maximum supported charCode
258
+ */
259
+ getMaxCharCode(): number;
260
+ /**
261
+ * Get the PNG image data
262
+ */
263
+ getImageData(): Uint8Array;
264
+ /**
265
+ * Get the atlas dimensions in pixels
266
+ */
267
+ getAtlasDimensions(): {
268
+ width: number;
269
+ height: number;
270
+ };
271
+ /**
272
+ * Get UV coordinates for a character code
273
+ * @param charCode Character code (0 to maxCharCode)
274
+ * @returns UV coordinates { u1, v1, u2, v2 } or null if out of range
275
+ */
276
+ getCharUV(charCode: number): {
277
+ u1: number;
278
+ v1: number;
279
+ u2: number;
280
+ v2: number;
281
+ } | null;
282
+ /**
283
+ * Check if a charCode is valid for this atlas
284
+ */
285
+ isValidCharCode(charCode: number): boolean;
286
+ }
287
+
288
+ /**
289
+ * ImageFontRegistry - Registry for PNG atlas-based fonts
290
+ */
291
+
292
+ /**
293
+ * Options for loading an ImageFont
294
+ */
295
+ interface ImageFontOptions {
296
+ /** Width of each glyph in pixels (8, 16, or 32) */
297
+ glyphWidth: number;
298
+ /** Height of each glyph in pixels (8, 16, or 32) */
299
+ glyphHeight: number;
300
+ /** Target cell width for rendering (default: glyphWidth) */
301
+ cellWidth?: number;
302
+ /** Target cell height for rendering (default: glyphHeight) */
303
+ cellHeight?: number;
304
+ /** Number of 256-char blocks: 1, 4, or 16 (default: 1) */
305
+ atlasBlocks?: AtlasBlocks;
306
+ }
307
+ /**
308
+ * Registry for managing ImageFont instances
309
+ * Each font is identified by a unique fontId (0-255) and a human-readable name
310
+ * ImageFonts correspond to LoadType 0x08 (ImageFont) in UTSP protocol
311
+ */
312
+ declare class ImageFontRegistry {
313
+ private fonts;
314
+ private nameToId;
315
+ private nextId;
316
+ /**
317
+ * Allocate the next available font ID
318
+ * @param name Font name (for error messages)
319
+ * @returns Allocated font ID
320
+ * @throws Error if no IDs available
321
+ */
322
+ private allocateId;
323
+ /**
324
+ * Register a new ImageFont with auto-assigned ID
325
+ * @param name Human-readable name for the font
326
+ * @param options Font options (glyph size, atlas blocks)
327
+ * @param imageData PNG image data
328
+ * @returns The assigned font ID (0-255)
329
+ * @throws Error if name already exists
330
+ */
331
+ registerFont(name: string, options: ImageFontOptions, imageData: Uint8Array): number;
332
+ /**
333
+ * Load a new ImageFont into the registry with specific ID (low-level API)
334
+ * @param fontId Unique font identifier (0-255)
335
+ * @param config ImageFont configuration
336
+ * @throws Error if font ID already exists
337
+ */
338
+ loadFont(fontId: number, config: ImageFontConfig): void;
339
+ /**
340
+ * Get an ImageFont by ID
341
+ * @param fontId Font identifier
342
+ * @returns ImageFont instance or undefined if not found
343
+ */
344
+ getFont(fontId: number): ImageFont | undefined;
345
+ /**
346
+ * Get an ImageFont by name
347
+ * @param name Font name
348
+ * @returns ImageFont instance or undefined if not found
349
+ */
350
+ getFontByName(name: string): ImageFont | undefined;
351
+ /**
352
+ * Get font ID by name
353
+ * @param name Font name
354
+ * @returns Font ID or undefined if not found
355
+ */
356
+ getFontId(name: string): number | undefined;
357
+ /**
358
+ * Get font name by ID
359
+ * @param fontId Font ID
360
+ * @returns Font name or undefined if not found
361
+ */
362
+ getFontName(fontId: number): string | undefined;
363
+ /**
364
+ * Check if a font exists in the registry by ID
365
+ * @param fontId Font identifier
366
+ * @returns true if font exists, false otherwise
367
+ */
368
+ hasFont(fontId: number): boolean;
369
+ /**
370
+ * Check if a font exists in the registry by name
371
+ * @param name Font name
372
+ * @returns true if font exists, false otherwise
373
+ */
374
+ hasFontByName(name: string): boolean;
375
+ /**
376
+ * Remove an ImageFont from the registry
377
+ * @param fontId Font identifier
378
+ * @returns true if font was removed, false if not found
379
+ */
380
+ unloadFont(fontId: number): boolean;
381
+ /**
382
+ * Remove an ImageFont from the registry by name
383
+ * @param name Font name
384
+ * @returns true if font was removed, false if not found
385
+ */
386
+ unloadFontByName(name: string): boolean;
387
+ /**
388
+ * Remove all fonts from the registry
389
+ */
390
+ clearFonts(): void;
391
+ /**
392
+ * Get all font IDs in the registry
393
+ * @returns Array of font IDs, sorted in ascending order
394
+ */
395
+ getFontIds(): number[];
396
+ /**
397
+ * Get all font names in the registry
398
+ * @returns Array of font names
399
+ */
400
+ getFontNames(): string[];
401
+ /**
402
+ * Get all ImageFont instances in the registry
403
+ * @returns Array of ImageFont instances, sorted by font ID
404
+ */
405
+ getAllFonts(): ImageFont[];
406
+ /**
407
+ * Get the number of fonts in the registry
408
+ * @returns Number of fonts
409
+ */
410
+ getFontCount(): number;
411
+ }
150
412
 
151
413
  /**
152
414
  * Base interface for all network orders
@@ -1023,14 +1285,26 @@ declare function getMacroOrderTypeName(type: MacroOrderType): string;
1023
1285
  */
1024
1286
  declare function getMacroEventTypeName(type: MacroEventType): string;
1025
1287
 
1288
+ /**
1289
+ * CharCode mode for layers
1290
+ * - '8bit': Uses Uint8Array, limited to 256 characters (ASCII/CP437), optimized bandwidth
1291
+ * - '16bit': Uses Uint16Array, supports 65536 characters (Unicode BMP), universal
1292
+ */
1293
+ type CharCodeMode = '8bit' | '16bit';
1026
1294
  interface Cell {
1027
1295
  charCode: number;
1028
1296
  fgColorCode: number;
1029
1297
  bgColorCode: number;
1030
1298
  }
1031
1299
  /**
1032
- * Optimized buffer for 65,536 cells with TypedArray
1033
- * Interleaved structure: [char0, fg0, bg0, char1, fg1, bg1, ...]
1300
+ * Optimized buffer for cells with TypedArray
1301
+ * Separate arrays for charCodes and colors for optimal memory layout
1302
+ *
1303
+ * CharCode storage depends on mode:
1304
+ * - 8-bit mode: Uint8Array (1 byte per charCode) - network optimized
1305
+ * - 16-bit mode: Uint16Array (2 bytes per charCode) - full Unicode BMP
1306
+ *
1307
+ * Colors are always 8-bit (256 palette colors)
1034
1308
  *
1035
1309
  * Performance:
1036
1310
  * - clear(): ~5-10μs (vs 826μs with object array)
@@ -1038,9 +1312,17 @@ interface Cell {
1038
1312
  * - Less GC pressure
1039
1313
  */
1040
1314
  declare class CellBuffer {
1041
- private data;
1315
+ private charCodes;
1316
+ private fgColors;
1317
+ private bgColors;
1042
1318
  private size;
1043
- constructor(size?: number);
1319
+ private is16bit;
1320
+ /**
1321
+ * Creates a new CellBuffer
1322
+ * @param size - Number of cells (default: 65536)
1323
+ * @param is16bit - true for 16-bit charCodes, false for 8-bit (default: false)
1324
+ */
1325
+ constructor(size?: number, is16bit?: boolean);
1044
1326
  /**
1045
1327
  * Optimized clear: fills with "skip" values
1046
1328
  * - charCode = 0 (no character)
@@ -1074,7 +1356,6 @@ declare class CellBuffer {
1074
1356
  * Writes only characters at multiple positions with uniform fg/bg colors
1075
1357
  *
1076
1358
  * Performance: 2-3x faster than individual set() calls for uniform colors
1077
- * Reduces memory writes by 66% (writes chars only, then batch-fills colors)
1078
1359
  *
1079
1360
  * @param indices - Array of cell indices to fill
1080
1361
  * @param charCode - Character to write at all positions
@@ -1117,20 +1398,33 @@ declare class CellBuffer {
1117
1398
  getFgColorCode(index: number): number;
1118
1399
  getBgColorCode(index: number): number;
1119
1400
  /**
1120
- * Direct TypedArray access for batch operations
1401
+ * Direct TypedArray access for charCodes (batch operations)
1121
1402
  */
1122
- getRawData(): Uint8Array;
1403
+ getRawCharCodes(): Uint8Array | Uint16Array;
1404
+ /**
1405
+ * Direct TypedArray access for foreground colors
1406
+ */
1407
+ getRawFgColors(): Uint8Array;
1408
+ /**
1409
+ * Direct TypedArray access for background colors
1410
+ */
1411
+ getRawBgColors(): Uint8Array;
1123
1412
  /**
1124
1413
  * Buffer size (number of cells)
1125
1414
  */
1126
1415
  getSize(): number;
1416
+ /**
1417
+ * Returns true if buffer uses 16-bit charCodes
1418
+ */
1419
+ is16BitMode(): boolean;
1127
1420
  }
1128
1421
  /**
1129
1422
  * Optimized buffer to store only charcodes (unicolor sprites)
1130
1423
  * Simple structure: [char0, char1, char2, ...]
1424
+ * Always uses 16-bit charCodes to support full Unicode BMP
1131
1425
  *
1132
1426
  * Performance:
1133
- * - 3x less memory than CellBuffer (1 byte vs 3 bytes per cell)
1427
+ * - Less memory than CellBuffer (2 bytes vs 4 bytes per cell)
1134
1428
  * - Ideal for unicolor sprites where colors are defined at render time
1135
1429
  * - Cache-friendly with TypedArray
1136
1430
  */
@@ -1153,7 +1447,7 @@ declare class CharCodeBuffer {
1153
1447
  /**
1154
1448
  * Direct TypedArray access for batch operations
1155
1449
  */
1156
- getRawData(): Uint8Array;
1450
+ getRawData(): Uint16Array;
1157
1451
  /**
1158
1452
  * Buffer size (number of cells)
1159
1453
  */
@@ -1208,6 +1502,7 @@ interface MacroLoad {
1208
1502
  * UTSP Load Packet Types
1209
1503
  * Based on UTSP Protocol v0.1 - Section 4: Load Section
1210
1504
  */
1505
+
1211
1506
  /**
1212
1507
  * LoadType enumeration
1213
1508
  */
@@ -1215,10 +1510,11 @@ declare enum LoadType {
1215
1510
  ColorPalette = 1,
1216
1511
  Sprite = 2,
1217
1512
  MulticolorSprite = 3,
1218
- BitmapFont = 4,// Formerly "Charset" - pixel-based fonts
1513
+ BitmapFont = 4,// Formerly "Charset" - pixel-based fonts (bitpacking)
1219
1514
  Sound = 5,
1220
1515
  WebFont = 6,// CSS-based fonts for browser rendering
1221
- Macro = 7
1516
+ Macro = 7,// Macro template for client-side feedback
1517
+ ImageFont = 8
1222
1518
  }
1223
1519
  /**
1224
1520
  * Color definition with RGBA+E values
@@ -1318,11 +1614,34 @@ interface SoundLoad {
1318
1614
  midiData: Uint8Array;
1319
1615
  }>;
1320
1616
  }
1617
+ /**
1618
+ * ImageFont Load (LoadType 0x08)
1619
+ * PNG atlas-based fonts for extended character sets (256, 1024, or 4096 chars)
1620
+ *
1621
+ * Atlas layout (example for 4 blocks = 1024 chars):
1622
+ * ```
1623
+ * ┌─────────┬─────────┐
1624
+ * │ 0-255 │ 256-511 │ 32×32 grid
1625
+ * ├─────────┼─────────┤ = 1024 chars
1626
+ * │ 512-767 │768-1023 │
1627
+ * └─────────┴─────────┘
1628
+ * ```
1629
+ */
1630
+ interface ImageFontLoad {
1631
+ loadType: LoadType.ImageFont;
1632
+ fontId: number;
1633
+ glyphWidth: number;
1634
+ glyphHeight: number;
1635
+ cellWidth: number;
1636
+ cellHeight: number;
1637
+ atlasBlocks: AtlasBlocks;
1638
+ imageData: Uint8Array;
1639
+ }
1321
1640
 
1322
1641
  /**
1323
1642
  * Union type for all load types
1324
1643
  */
1325
- type AnyLoad = ColorPaletteLoad | SpriteLoad | MulticolorSpriteLoad | BitmapFontLoad | SoundLoad | WebFontLoad | MacroLoad;
1644
+ type AnyLoad = ColorPaletteLoad | SpriteLoad | MulticolorSpriteLoad | BitmapFontLoad | SoundLoad | WebFontLoad | MacroLoad | ImageFontLoad;
1326
1645
 
1327
1646
  /**
1328
1647
  * Central registry to manage unicolor and multicolor sprites
@@ -2049,6 +2368,13 @@ interface NetworkLayer {
2049
2368
  height: number;
2050
2369
  orderCount: number;
2051
2370
  orders: AnyNetworkOrder[];
2371
+ /**
2372
+ * CharCode mode for this layer
2373
+ * - false: 8-bit charCodes (0-255)
2374
+ * - true: 16-bit charCodes (0-65535)
2375
+ * Encoded in updateFlags bit 6
2376
+ */
2377
+ is16bit: boolean;
2052
2378
  }
2053
2379
 
2054
2380
  /**
@@ -2342,6 +2668,23 @@ declare class Display {
2342
2668
  setSize(size: Vector2): void;
2343
2669
  }
2344
2670
 
2671
+ /**
2672
+ * Layer configuration options
2673
+ */
2674
+ interface LayerOptions {
2675
+ /**
2676
+ * CharCode mode for this layer (immutable after creation)
2677
+ * - '8bit': Uses Uint8Array, limited to 256 characters (ASCII/CP437), optimized bandwidth
2678
+ * - '16bit': Uses Uint16Array, supports 65536 characters (Unicode BMP), universal
2679
+ * @default '8bit'
2680
+ */
2681
+ charCodeMode?: CharCodeMode;
2682
+ /**
2683
+ * Static layer (sent only once to client)
2684
+ * @default false
2685
+ */
2686
+ isStatic?: boolean;
2687
+ }
2345
2688
  declare class Layer {
2346
2689
  private id;
2347
2690
  private origin;
@@ -2353,13 +2696,35 @@ declare class Layer {
2353
2696
  private isStatic;
2354
2697
  private spriteRegistry?;
2355
2698
  private mode;
2699
+ private charCodeMode;
2356
2700
  private previousOrigin;
2357
2701
  private previousZOrder;
2358
2702
  private enabled;
2359
2703
  private useSetMode;
2360
2704
  private needsCommit;
2361
2705
  private static rasterizer;
2362
- constructor(origin: Vector2, zOrder: number, width: number, height: number, isStatic?: boolean);
2706
+ /**
2707
+ * Creates a new Layer
2708
+ *
2709
+ * @param origin - Layer origin in world space
2710
+ * @param zOrder - Z-order for layer stacking (higher = on top)
2711
+ * @param width - Layer width in cells (1-256)
2712
+ * @param height - Layer height in cells (1-256)
2713
+ * @param options - Layer options (charCodeMode, isStatic)
2714
+ *
2715
+ * @example
2716
+ * // 8-bit layer (default) - optimized for ASCII/CP437 text
2717
+ * const gameLayer = new Layer(new Vector2(0, 0), 0, 80, 25);
2718
+ *
2719
+ * // 16-bit layer - full Unicode support (emoji, CJK, symbols)
2720
+ * const unicodeLayer = new Layer(new Vector2(0, 0), 10, 40, 10, { charCodeMode: '16bit' });
2721
+ */
2722
+ constructor(origin: Vector2, zOrder: number, width: number, height: number, options?: LayerOptions | boolean);
2723
+ /**
2724
+ * Gets the layer's charCode mode (immutable)
2725
+ * @returns '8bit' or '16bit'
2726
+ */
2727
+ getCharCodeMode(): CharCodeMode;
2363
2728
  /**
2364
2729
  * Configures the layer's execution mode (called by User)
2365
2730
  * @internal
@@ -5152,6 +5517,7 @@ declare class Core {
5152
5517
  private spriteRegistry;
5153
5518
  private webFontRegistry;
5154
5519
  private bitmapFontRegistry;
5520
+ private imageFontRegistry;
5155
5521
  private soundRegistry;
5156
5522
  private audioOrderCollector;
5157
5523
  private postProcessOrderCollector;
@@ -5159,6 +5525,7 @@ declare class Core {
5159
5525
  private _renderCallCount;
5160
5526
  private onPaletteChangedCallback?;
5161
5527
  private onBitmapFontChangedCallback?;
5528
+ private onImageFontChangedCallback?;
5162
5529
  /**
5163
5530
  * Creates a new UTSP engine instance
5164
5531
  *
@@ -6591,6 +6958,261 @@ declare class Core {
6591
6958
  * ```
6592
6959
  */
6593
6960
  getBitmapFontIds(): number[];
6961
+ /**
6962
+ * Loads an image font from a PNG file path
6963
+ *
6964
+ * Works identically on server (Node.js) and client (browser).
6965
+ * The PNG is loaded and registered with an auto-assigned ID.
6966
+ *
6967
+ * @param name - Human-readable name for the font (e.g., 'tileset', 'icons')
6968
+ * @param path - Path to the PNG atlas file
6969
+ * @param options - Font configuration options
6970
+ * @returns Promise resolving to the assigned font ID (0-255)
6971
+ *
6972
+ * @example
6973
+ * ```typescript
6974
+ * // In init() - same code works on server and client
6975
+ * async init(core: Core): Promise<void> {
6976
+ * await core.loadImageFont('tileset', './fonts/tileset.png', {
6977
+ * glyphWidth: 16,
6978
+ * glyphHeight: 16,
6979
+ * atlasBlocks: 4, // 1024 chars
6980
+ * });
6981
+ * }
6982
+ *
6983
+ * // Later, use by name or ID
6984
+ * const id = core.getImageFontId('tileset');
6985
+ * ```
6986
+ */
6987
+ loadImageFont(name: string, path: string, options: ImageFontOptions): Promise<number>;
6988
+ /**
6989
+ * Loads multiple image fonts at once
6990
+ *
6991
+ * @param fonts - Object mapping font names to { path, options }
6992
+ * @returns Promise resolving to object mapping names to IDs
6993
+ *
6994
+ * @example
6995
+ * ```typescript
6996
+ * async init(core: Core): Promise<void> {
6997
+ * await core.loadImageFonts({
6998
+ * tileset: {
6999
+ * path: './fonts/tileset.png',
7000
+ * options: { glyphWidth: 16, glyphHeight: 16, atlasBlocks: 4 }
7001
+ * },
7002
+ * icons: {
7003
+ * path: './fonts/icons.png',
7004
+ * options: { glyphWidth: 8, glyphHeight: 8, atlasBlocks: 1 }
7005
+ * }
7006
+ * });
7007
+ * }
7008
+ * ```
7009
+ */
7010
+ loadImageFonts(fonts: Record<string, {
7011
+ path: string;
7012
+ options: ImageFontOptions;
7013
+ }>): Promise<Record<string, number>>;
7014
+ /**
7015
+ * Loads image data from path (isomorphic: Node.js or browser)
7016
+ */
7017
+ private loadImageData;
7018
+ /**
7019
+ * Gets the font ID for a named image font
7020
+ *
7021
+ * @param name - Font name
7022
+ * @returns Font ID or undefined if not found
7023
+ *
7024
+ * @example
7025
+ * ```typescript
7026
+ * const id = core.getImageFontId('tileset');
7027
+ * if (id !== undefined) {
7028
+ * console.log(`Tileset font ID: ${id}`);
7029
+ * }
7030
+ * ```
7031
+ */
7032
+ getImageFontId(name: string): number | undefined;
7033
+ /**
7034
+ * Gets an image font by its name
7035
+ *
7036
+ * @param name - Font name
7037
+ * @returns The ImageFont instance or null if not found
7038
+ *
7039
+ * @example
7040
+ * ```typescript
7041
+ * const font = core.getImageFontByName('tileset');
7042
+ * if (font) {
7043
+ * console.log(`Max charCode: ${font.getMaxCharCode()}`);
7044
+ * }
7045
+ * ```
7046
+ */
7047
+ getImageFontByName(name: string): ImageFont | null;
7048
+ /**
7049
+ * Registers a callback for image font changes
7050
+ *
7051
+ * Called when an image font is loaded.
7052
+ *
7053
+ * @param callback - Function called with the fontId
7054
+ *
7055
+ * @example
7056
+ * ```typescript
7057
+ * core.onImageFontChanged((fontId) => {
7058
+ * const font = core.getImageFont(fontId);
7059
+ * if (font) renderer.setImageFont(font.getImageData(), ...);
7060
+ * });
7061
+ * ```
7062
+ */
7063
+ onImageFontChanged(callback: (fontId: number) => void): void;
7064
+ /**
7065
+ * Gets the image font registry (low-level API)
7066
+ *
7067
+ * @returns The ImageFontRegistry instance
7068
+ *
7069
+ * @example
7070
+ * ```typescript
7071
+ * const registry = engine.getImageFontRegistry();
7072
+ * const font = registry.getFont(1);
7073
+ * ```
7074
+ */
7075
+ getImageFontRegistry(): ImageFontRegistry;
7076
+ /**
7077
+ * Loads an image font (PNG atlas) by ID (low-level API)
7078
+ *
7079
+ * Prefer using loadImageFont() with a name for simpler usage.
7080
+ *
7081
+ * @param fontId - Unique font ID (0-255)
7082
+ * @param config - Image font configuration
7083
+ * @throws Error if fontId is already in use
7084
+ *
7085
+ * @example
7086
+ * ```typescript
7087
+ * engine.loadImageFontById(1, {
7088
+ * glyphWidth: 16,
7089
+ * glyphHeight: 16,
7090
+ * atlasBlocks: 4,
7091
+ * imageData: pngBuffer
7092
+ * });
7093
+ * ```
7094
+ */
7095
+ loadImageFontById(fontId: number, config: ImageFontConfig): void;
7096
+ /**
7097
+ * Gets an image font by its ID
7098
+ *
7099
+ * @param fontId - Font ID (0-255)
7100
+ * @returns The ImageFont instance or null if not found
7101
+ *
7102
+ * @example
7103
+ * ```typescript
7104
+ * const font = engine.getImageFont(1);
7105
+ * if (font) {
7106
+ * console.log(`Atlas blocks: ${font.getAtlasBlocks()}`);
7107
+ * console.log(`Max charCode: ${font.getMaxCharCode()}`);
7108
+ * }
7109
+ * ```
7110
+ */
7111
+ getImageFont(fontId: number): ImageFont | null;
7112
+ /**
7113
+ * Checks if an image font exists by ID
7114
+ *
7115
+ * @param fontId - Font ID (0-255)
7116
+ * @returns true if font exists
7117
+ *
7118
+ * @example
7119
+ * ```typescript
7120
+ * if (engine.hasImageFont(1)) {
7121
+ * console.log("ImageFont 1 is loaded");
7122
+ * }
7123
+ * ```
7124
+ */
7125
+ hasImageFont(fontId: number): boolean;
7126
+ /**
7127
+ * Checks if an image font exists by name
7128
+ *
7129
+ * @param name - Font name
7130
+ * @returns true if font exists
7131
+ *
7132
+ * @example
7133
+ * ```typescript
7134
+ * if (engine.hasImageFontByName('tileset')) {
7135
+ * console.log("Tileset font is loaded");
7136
+ * }
7137
+ * ```
7138
+ */
7139
+ hasImageFontByName(name: string): boolean;
7140
+ /**
7141
+ * Unloads an image font from the registry by ID
7142
+ *
7143
+ * @param fontId - Font ID to unload (0-255)
7144
+ * @returns true if font was unloaded
7145
+ *
7146
+ * @example
7147
+ * ```typescript
7148
+ * const removed = engine.unloadImageFont(1);
7149
+ * if (removed) {
7150
+ * console.log("ImageFont 1 unloaded");
7151
+ * }
7152
+ * ```
7153
+ */
7154
+ unloadImageFont(fontId: number): boolean;
7155
+ /**
7156
+ * Unloads an image font from the registry by name
7157
+ *
7158
+ * @param name - Font name to unload
7159
+ * @returns true if font was unloaded
7160
+ *
7161
+ * @example
7162
+ * ```typescript
7163
+ * const removed = engine.unloadImageFontByName('tileset');
7164
+ * if (removed) {
7165
+ * console.log("Tileset font unloaded");
7166
+ * }
7167
+ * ```
7168
+ */
7169
+ unloadImageFontByName(name: string): boolean;
7170
+ /**
7171
+ * Clears all image fonts
7172
+ *
7173
+ * @example
7174
+ * ```typescript
7175
+ * engine.clearImageFonts();
7176
+ * console.log("All image fonts cleared");
7177
+ * ```
7178
+ */
7179
+ clearImageFonts(): void;
7180
+ /**
7181
+ * Counts the number of loaded image fonts
7182
+ *
7183
+ * @returns Number of image fonts in memory
7184
+ *
7185
+ * @example
7186
+ * ```typescript
7187
+ * const count = engine.getImageFontCount();
7188
+ * console.log(`${count} image fonts loaded`);
7189
+ * ```
7190
+ */
7191
+ getImageFontCount(): number;
7192
+ /**
7193
+ * Gets all loaded image font IDs
7194
+ *
7195
+ * @returns Array of fontIds (0-255)
7196
+ *
7197
+ * @example
7198
+ * ```typescript
7199
+ * const fontIds = engine.getImageFontIds();
7200
+ * console.log(`Loaded image fonts: ${fontIds.join(", ")}`);
7201
+ * ```
7202
+ */
7203
+ getImageFontIds(): number[];
7204
+ /**
7205
+ * Gets all loaded image font names
7206
+ *
7207
+ * @returns Array of font names
7208
+ *
7209
+ * @example
7210
+ * ```typescript
7211
+ * const names = engine.getImageFontNames();
7212
+ * console.log(`Loaded image fonts: ${names.join(", ")}`);
7213
+ * ```
7214
+ */
7215
+ getImageFontNames(): string[];
6594
7216
  }
6595
7217
 
6596
7218
  /**
@@ -6935,13 +7557,14 @@ interface ColorOptions {
6935
7557
  */
6936
7558
  declare class OrderBuilder {
6937
7559
  /**
6938
- * Convert string or number to 8-bit character code
6939
- * @param char - Either a string (first character used) or a number (0-255)
6940
- * @returns 8-bit character code (0-255)
7560
+ * Convert string or number to character code
7561
+ * @param char - Either a string (first character used) or a number (0-65535)
7562
+ * @returns Character code (0-65535)
6941
7563
  * @example
6942
7564
  * toCharCode('#') // → 0x23 (35)
6943
7565
  * toCharCode(0x23) // → 0x23 (35)
6944
7566
  * toCharCode('ABC') // → 0x41 (65, first char only)
7567
+ * toCharCode(256) // → 256 (preserved for 16-bit layers)
6945
7568
  */
6946
7569
  static toCharCode(char: string | number): number;
6947
7570
  /**
@@ -7308,6 +7931,12 @@ declare const LAYER_CELL_COUNT = 65536;
7308
7931
  * - Engine forces ColorID 255 = rgba(0,0,0,0) at startup (transparency)
7309
7932
  */
7310
7933
  declare const COLOR_SKIP = 255;
7934
+ /**
7935
+ * Get byte size for charCode based on layer mode
7936
+ * @param is16bit - true for 16-bit mode, false for 8-bit mode
7937
+ * @returns 2 for 16-bit, 1 for 8-bit
7938
+ */
7939
+ declare const charCodeByteSize: (is16bit: boolean) => number;
7311
7940
  declare const UPDATE_PACKET_HEADER_SIZE = 9;
7312
7941
  declare const DISPLAY_HEADER_SIZE = 5;
7313
7942
  declare const LAYER_HEADER_SIZE = 13;
@@ -8054,5 +8683,5 @@ declare class PostProcessOrderCollector {
8054
8683
  private parseColor;
8055
8684
  }
8056
8685
 
8057
- export { ASCII_8X8_FONT, AUDIO_CONFIGURE_SPATIAL_SIZE, AUDIO_FADEOUT_SOUND_MIN_SIZE, AUDIO_PAUSE_SOUND_MIN_SIZE, AUDIO_PLAY_GLOBAL_SOUND_MIN_SIZE, AUDIO_PLAY_SOUND_MIN_SIZE, AUDIO_RESUME_SOUND_MIN_SIZE, AUDIO_SET_LISTENER_POSITION_SIZE, AUDIO_SET_SOUND_EFFECTS_MIN_SIZE, AUDIO_STOP_SOUND_MIN_SIZE, AudioOrderCollector, AudioOrderDecoder, AudioOrderType, AudioTargetType, BITMASK16_ORDER_MIN_SIZE, BITMASK4_ORDER_MIN_SIZE, BITMASK_ORDER_MIN_SIZE, BitmapFont, BitmapFontRegistry, CHAR_ORDER_SIZE, CIRCLE_SHAPE_SIZE, CLEAR_ORDER_SIZE, COLORMAP_ORDER_MIN_SIZE, COLOR_SKIP, CellBuffer, CharCodeBuffer, Core, CoreStats, DISPLAY_HEADER_SIZE, DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE, DOTCLOUD_ORDER_MIN_SIZE, Display, ELLIPSE_SHAPE_SIZE, FILLCHAR_ORDER_MIN_SIZE, FILLSPRITE_MULTICOLOR_ORDER_SIZE, FILLSPRITE_ORDER_SIZE, FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE, FULLFRAME_ORDER_MIN_SIZE, FontType, InputBindingRegistry, LAYER_CELL_COUNT, LAYER_HEADER_SIZE, LAYER_SIZE, LINE_SHAPE_SIZE, Layer, LoadType, MacroEngine, MacroEventType, MacroOrderType, MacroRegistry, OrderBuilder, OrderType, POLYLINE_ORDER_MIN_SIZE, POSTPROCESS_SET_AMBIENT_EFFECT_SIZE, POSTPROCESS_SET_CONFIG_MIN_SIZE, POSTPROCESS_SET_GRID_SIZE, POSTPROCESS_SET_SCALING_MODE_SIZE, POSTPROCESS_SET_SCANLINES_SIZE, PlaySoundFlags, PostProcessOrderCollector, PostProcessOrderDecoder, PostProcessOrderType, RECTANGLE_SHAPE_SIZE, SHAPE_ORDER_MIN_SIZE, SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE, SPRITECLOUD_ORDER_MIN_SIZE, SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE, SPRITECLOUD_VARIED_ORDER_MIN_SIZE, SPRITE_MULTICOLOR_ORDER_SIZE, SPRITE_ORDER_SIZE, SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE, SUBFRAME_ORDER_MIN_SIZE, ShapeType, SoundEffectsFlags, SoundRegistry, SpriteRegistry, TEXT_MULTILINE_ORDER_MIN_SIZE, TEXT_ORDER_MIN_SIZE, TRIANGLE_SHAPE_SIZE, TRIGGERGLOBALSOUND_ORDER_SIZE, TRIGGERSOUND_ORDER_SIZE, UPDATE_PACKET_HEADER_SIZE, UpdateFlags, UpdateFlagsHelper, UpdatePacketDecoder, User, UserStats, WebFont, WebFontRegistry, createASCII8x8FontLoad, createEmptyCompressedInputPacket, decodeCompressedInput, decodeInt8ToAxis, encodeAxisToInt8, encodeCompressedInput, getASCII8x8FontConfig, getAllCharCodes, getAudioOrderTypeName, getButtonByteCount, getCharBitmap, getCompressedPacketSize, getMacroEventTypeName, getMacroOrderTypeName, getOrderTypeName, hasChar, isValidAudioOrderType, isValidMacroEventType, isValidMacroOrderType, isValidOrderType };
8058
- export type { AnyAudioOrder, AnyLoad, AnyMacroEvent, AnyMacroOrder, AnyPostProcessOrder, AudioOrder, BitmapFontConfig, BitmapFontLoad, Bitmask16Order, Bitmask16Variant, Bitmask4Order, Bitmask4Variant, BitmaskOrder, ButtonBorderStyle, ButtonConfig, ButtonStateColors, Cell, ChangeEvent, CircleShape, ClickEvent, Color, ColorPaletteLoad, CompressedInputPacket, ConfigureSpatialOrder, CoreMode, CoreOptions, CreateInstanceConfig, CreateInstanceOrder, EffectMacroTemplate, EffectTransform, EllipseShape, FadeOutSoundOrder, LineMacroTemplate, LineShape, MacroEntry, MacroEvent, MacroInstanceEntry, MacroLoad, MacroOrder, MacroTemplate, MacroTemplateBase, MacroType, MacroUpdateResult, MulticolorCell, MulticolorSprite, MulticolorSpriteLoad, NetworkDisplay, NetworkLayer, ParticleConfig, ParticleEmitter, ParticleMacroTemplate, PauseSoundOrder, PlayGlobalSoundOrder, PlaySoundOrder, RectangleShape, RemoveInstanceOrder, RenderCommand, ResumeSoundOrder, RevealCellDef, RevealContent, RevealContentType, RevealCursor, RevealDirection, RevealMacroTemplate, RevealPattern, RevealPause, SelectEvent, SetAmbientEffectOrder, SetConfigOrder, SetGridOrder, SetListenerPositionOrder, SetScalingModeOrder, SetScanlinesOrder, SetSoundEffectsOrder, ShapeData, SoundEntry, SoundLoad, SpriteLoad, StopSoundOrder, SubmitEvent, TickStats, TriangleShape, UIMacroTemplate, UIState, UISubtype, UnicolorSprite, UpdateInstanceOrder, UpdatePacket, UserTickStats, WebFontConfig, WebFontLoad };
8686
+ export { ASCII_8X8_FONT, AUDIO_CONFIGURE_SPATIAL_SIZE, AUDIO_FADEOUT_SOUND_MIN_SIZE, AUDIO_PAUSE_SOUND_MIN_SIZE, AUDIO_PLAY_GLOBAL_SOUND_MIN_SIZE, AUDIO_PLAY_SOUND_MIN_SIZE, AUDIO_RESUME_SOUND_MIN_SIZE, AUDIO_SET_LISTENER_POSITION_SIZE, AUDIO_SET_SOUND_EFFECTS_MIN_SIZE, AUDIO_STOP_SOUND_MIN_SIZE, AudioOrderCollector, AudioOrderDecoder, AudioOrderType, AudioTargetType, BITMASK16_ORDER_MIN_SIZE, BITMASK4_ORDER_MIN_SIZE, BITMASK_ORDER_MIN_SIZE, BitmapFont, BitmapFontRegistry, CHAR_ORDER_SIZE, CIRCLE_SHAPE_SIZE, CLEAR_ORDER_SIZE, COLORMAP_ORDER_MIN_SIZE, COLOR_SKIP, CellBuffer, CharCodeBuffer, Core, CoreStats, DISPLAY_HEADER_SIZE, DOTCLOUD_MULTICOLOR_ORDER_MIN_SIZE, DOTCLOUD_ORDER_MIN_SIZE, Display, ELLIPSE_SHAPE_SIZE, FILLCHAR_ORDER_MIN_SIZE, FILLSPRITE_MULTICOLOR_ORDER_SIZE, FILLSPRITE_ORDER_SIZE, FULLFRAME_MULTICOLOR_ORDER_MIN_SIZE, FULLFRAME_ORDER_MIN_SIZE, FontType, ImageFont, ImageFontRegistry, InputBindingRegistry, LAYER_CELL_COUNT, LAYER_HEADER_SIZE, LAYER_SIZE, LINE_SHAPE_SIZE, Layer, LoadType, MacroEngine, MacroEventType, MacroOrderType, MacroRegistry, OrderBuilder, OrderType, POLYLINE_ORDER_MIN_SIZE, POSTPROCESS_SET_AMBIENT_EFFECT_SIZE, POSTPROCESS_SET_CONFIG_MIN_SIZE, POSTPROCESS_SET_GRID_SIZE, POSTPROCESS_SET_SCALING_MODE_SIZE, POSTPROCESS_SET_SCANLINES_SIZE, PlaySoundFlags, PostProcessOrderCollector, PostProcessOrderDecoder, PostProcessOrderType, RECTANGLE_SHAPE_SIZE, SHAPE_ORDER_MIN_SIZE, SPRITECLOUD_MULTICOLOR_ORDER_MIN_SIZE, SPRITECLOUD_ORDER_MIN_SIZE, SPRITECLOUD_VARIED_MULTICOLOR_ORDER_MIN_SIZE, SPRITECLOUD_VARIED_ORDER_MIN_SIZE, SPRITE_MULTICOLOR_ORDER_SIZE, SPRITE_ORDER_SIZE, SUBFRAME_MULTICOLOR_ORDER_MIN_SIZE, SUBFRAME_ORDER_MIN_SIZE, ShapeType, SoundEffectsFlags, SoundRegistry, SpriteRegistry, TEXT_MULTILINE_ORDER_MIN_SIZE, TEXT_ORDER_MIN_SIZE, TRIANGLE_SHAPE_SIZE, TRIGGERGLOBALSOUND_ORDER_SIZE, TRIGGERSOUND_ORDER_SIZE, UPDATE_PACKET_HEADER_SIZE, UpdateFlags, UpdateFlagsHelper, UpdatePacketDecoder, User, UserStats, WebFont, WebFontRegistry, charCodeByteSize, createASCII8x8FontLoad, createEmptyCompressedInputPacket, decodeCompressedInput, decodeInt8ToAxis, encodeAxisToInt8, encodeCompressedInput, getASCII8x8FontConfig, getAllCharCodes, getAtlasColumns, getAtlasDimensions, getAudioOrderTypeName, getButtonByteCount, getCharBitmap, getCompressedPacketSize, getMacroEventTypeName, getMacroOrderTypeName, getMaxCharCode, getOrderTypeName, hasChar, isValidAudioOrderType, isValidMacroEventType, isValidMacroOrderType, isValidOrderType };
8687
+ export type { AnyAudioOrder, AnyLoad, AnyMacroEvent, AnyMacroOrder, AnyPostProcessOrder, AtlasBlocks, AudioOrder, BitmapFontConfig, BitmapFontLoad, Bitmask16Order, Bitmask16Variant, Bitmask4Order, Bitmask4Variant, BitmaskOrder, ButtonBorderStyle, ButtonConfig, ButtonStateColors, Cell, ChangeEvent, CharCodeMode, CircleShape, ClickEvent, Color, ColorPaletteLoad, CompressedInputPacket, ConfigureSpatialOrder, CoreMode, CoreOptions, CreateInstanceConfig, CreateInstanceOrder, EffectMacroTemplate, EffectTransform, EllipseShape, FadeOutSoundOrder, GlyphSize, ImageFontConfig, ImageFontLoad, ImageFontOptions, LineMacroTemplate, LineShape, MacroEntry, MacroEvent, MacroInstanceEntry, MacroLoad, MacroOrder, MacroTemplate, MacroTemplateBase, MacroType, MacroUpdateResult, MulticolorCell, MulticolorSprite, MulticolorSpriteLoad, NetworkDisplay, NetworkLayer, ParticleConfig, ParticleEmitter, ParticleMacroTemplate, PauseSoundOrder, PlayGlobalSoundOrder, PlaySoundOrder, RectangleShape, RemoveInstanceOrder, RenderCommand, ResumeSoundOrder, RevealCellDef, RevealContent, RevealContentType, RevealCursor, RevealDirection, RevealMacroTemplate, RevealPattern, RevealPause, SelectEvent, SetAmbientEffectOrder, SetConfigOrder, SetGridOrder, SetListenerPositionOrder, SetScalingModeOrder, SetScanlinesOrder, SetSoundEffectsOrder, ShapeData, SoundEntry, SoundLoad, SpriteLoad, StopSoundOrder, SubmitEvent, TickStats, TriangleShape, UIMacroTemplate, UIState, UISubtype, UnicolorSprite, UpdateInstanceOrder, UpdatePacket, UserTickStats, WebFontConfig, WebFontLoad };