@datamoc/mw_games 0.14.0 → 0.16.0

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 (71) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/dist/audio/Music.d.ts +27 -0
  3. package/dist/audio/Music.d.ts.map +1 -1
  4. package/dist/audio/Music.js +70 -2
  5. package/dist/audio/Music.js.map +1 -1
  6. package/dist/audio/Orchestrator.d.ts +4 -0
  7. package/dist/audio/Orchestrator.d.ts.map +1 -1
  8. package/dist/audio/Orchestrator.js +12 -0
  9. package/dist/audio/Orchestrator.js.map +1 -1
  10. package/dist/audio/Sound.d.ts +9 -0
  11. package/dist/audio/Sound.d.ts.map +1 -1
  12. package/dist/audio/Sound.js +18 -0
  13. package/dist/audio/Sound.js.map +1 -1
  14. package/dist/core/Settings.d.ts +96 -0
  15. package/dist/core/Settings.d.ts.map +1 -0
  16. package/dist/core/Settings.js +189 -0
  17. package/dist/core/Settings.js.map +1 -0
  18. package/dist/core/index.d.ts +2 -0
  19. package/dist/core/index.d.ts.map +1 -1
  20. package/dist/core/index.js +1 -0
  21. package/dist/core/index.js.map +1 -1
  22. package/dist/mw_games.global.js +115 -115
  23. package/dist/mwl/catalog.d.ts +42 -0
  24. package/dist/mwl/catalog.d.ts.map +1 -1
  25. package/dist/mwl/catalog.js +88 -0
  26. package/dist/mwl/catalog.js.map +1 -1
  27. package/dist/mwl/index.d.ts +1 -1
  28. package/dist/mwl/index.d.ts.map +1 -1
  29. package/dist/two-d/Game.d.ts +40 -0
  30. package/dist/two-d/Game.d.ts.map +1 -1
  31. package/dist/two-d/Game.js +66 -3
  32. package/dist/two-d/Game.js.map +1 -1
  33. package/dist/two-d/QualityScaler.d.ts +63 -0
  34. package/dist/two-d/QualityScaler.d.ts.map +1 -0
  35. package/dist/two-d/QualityScaler.js +92 -0
  36. package/dist/two-d/QualityScaler.js.map +1 -0
  37. package/dist/two-d/index.d.ts +3 -1
  38. package/dist/two-d/index.d.ts.map +1 -1
  39. package/dist/two-d/index.js +1 -0
  40. package/dist/two-d/index.js.map +1 -1
  41. package/dist/two-d/render/RpgmAutotile.d.ts +217 -0
  42. package/dist/two-d/render/RpgmAutotile.d.ts.map +1 -1
  43. package/dist/two-d/render/RpgmAutotile.js +756 -0
  44. package/dist/two-d/render/RpgmAutotile.js.map +1 -1
  45. package/dist/two-d/render/SpriteGroup.d.ts +83 -0
  46. package/dist/two-d/render/SpriteGroup.d.ts.map +1 -0
  47. package/dist/two-d/render/SpriteGroup.js +107 -0
  48. package/dist/two-d/render/SpriteGroup.js.map +1 -0
  49. package/dist/two-d/render/TileMap.d.ts +90 -0
  50. package/dist/two-d/render/TileMap.d.ts.map +1 -1
  51. package/dist/two-d/render/TileMap.js +319 -31
  52. package/dist/two-d/render/TileMap.js.map +1 -1
  53. package/dist/two-d/render/index.d.ts +5 -3
  54. package/dist/two-d/render/index.d.ts.map +1 -1
  55. package/dist/two-d/render/index.js +2 -1
  56. package/dist/two-d/render/index.js.map +1 -1
  57. package/dist/two-d/ui/Meter.d.ts +76 -0
  58. package/dist/two-d/ui/Meter.d.ts.map +1 -0
  59. package/dist/two-d/ui/Meter.js +134 -0
  60. package/dist/two-d/ui/Meter.js.map +1 -0
  61. package/dist/two-d/ui/SettingsScreen.d.ts +112 -0
  62. package/dist/two-d/ui/SettingsScreen.d.ts.map +1 -0
  63. package/dist/two-d/ui/SettingsScreen.js +338 -0
  64. package/dist/two-d/ui/SettingsScreen.js.map +1 -0
  65. package/dist/two-d/ui/index.d.ts +4 -0
  66. package/dist/two-d/ui/index.d.ts.map +1 -1
  67. package/dist/two-d/ui/index.js +2 -0
  68. package/dist/two-d/ui/index.js.map +1 -1
  69. package/dist/version.d.ts +1 -1
  70. package/dist/version.js +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Frame-time-driven quality scaling over item 360's static fit: `fitResolution` answers
3
+ * what a device can afford once, and this watches what actually happens, stepping the
4
+ * backing-store ratio down when frames keep missing their budget and stepping back up
5
+ * only after a much longer streak inside it. Pure numbers in and out - the game (see
6
+ * `Game`'s `qualityScaling` option) applies the returned ratio to its renderer, so this
7
+ * stays renderer-free and headless-testable.
8
+ *
9
+ * Stepping up is deliberately an order of magnitude slower than stepping down: a frame
10
+ * inside budget at a reduced ratio proves nothing about the next ratio up, so recovery
11
+ * needs a sustained streak, not a good moment.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { QualityScaler } from '@datamoc/mw_games/two-d';
16
+ *
17
+ * const scaler = new QualityScaler({ ceiling: 2 });
18
+ * for (let i = 0; i < 60; i++) scaler.observe(1 / 30);
19
+ * console.log(scaler.ratio); // 1.75
20
+ * ```
21
+ */
22
+ export class QualityScaler {
23
+ constructor(options) {
24
+ this.over = 0;
25
+ this.under = 0;
26
+ this.ceiling = normalizeCeiling(options.ceiling);
27
+ const min = options.minRatio ?? 1;
28
+ this.floor = Number.isFinite(min) && min > 0 ? Math.min(min, this.ceiling) : Math.min(1, this.ceiling);
29
+ const fps = options.targetFps ?? 60;
30
+ this.budget = Number.isFinite(fps) && fps > 0 ? 1 / fps : 1 / 60;
31
+ this.downAfter = streakLength(options.overBudgetFrames, 60);
32
+ this.upAfter = streakLength(options.underBudgetFrames, 600);
33
+ this.step = Number.isFinite(options.step) && options.step > 0 ? options.step : 0.25;
34
+ this.ratio_ = this.ceiling;
35
+ }
36
+ /** the ratio the renderer should currently use */
37
+ get ratio() {
38
+ return this.ratio_;
39
+ }
40
+ /**
41
+ * A new device-fitted ceiling (rotation, display change): the current ratio is clamped
42
+ * down to it, never up - stepping back up stays the streak's job. Returns the ratio.
43
+ */
44
+ setCeiling(ceiling) {
45
+ this.ceiling = normalizeCeiling(ceiling);
46
+ if (this.ratio_ > this.ceiling) {
47
+ this.ratio_ = this.ceiling;
48
+ this.over = 0;
49
+ this.under = 0;
50
+ }
51
+ return this.ratio_;
52
+ }
53
+ /**
54
+ * Feeds one frame's seconds; returns the ratio the renderer should use, unchanged most
55
+ * frames. Non-finite or non-positive frames are ignored rather than counted either way,
56
+ * so a parked clock (a `timeScale` 0 pause) can never drive the policy.
57
+ */
58
+ observe(frameSeconds) {
59
+ if (!Number.isFinite(frameSeconds) || frameSeconds <= 0)
60
+ return this.ratio_;
61
+ if (frameSeconds > this.budget) {
62
+ this.over++;
63
+ this.under = 0;
64
+ if (this.over >= this.downAfter && this.ratio_ > this.floor) {
65
+ this.ratio_ = Math.max(this.floor, this.ratio_ - this.step);
66
+ this.over = 0;
67
+ }
68
+ }
69
+ else {
70
+ this.under++;
71
+ this.over = 0;
72
+ if (this.under >= this.upAfter && this.ratio_ < this.ceiling) {
73
+ this.ratio_ = Math.min(this.ceiling, this.ratio_ + this.step);
74
+ this.under = 0;
75
+ }
76
+ }
77
+ return this.ratio_;
78
+ }
79
+ /** back to the ceiling with both streaks cleared */
80
+ reset() {
81
+ this.ratio_ = this.ceiling;
82
+ this.over = 0;
83
+ this.under = 0;
84
+ }
85
+ }
86
+ function normalizeCeiling(ceiling) {
87
+ return Number.isFinite(ceiling) && ceiling > 0 ? ceiling : 1;
88
+ }
89
+ function streakLength(value, fallback) {
90
+ return Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;
91
+ }
92
+ //# sourceMappingURL=QualityScaler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QualityScaler.js","sourceRoot":"","sources":["../../src/two-d/QualityScaler.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,OAAO,aAAa;IAWzB,YAAY,OAA6B;QAHjC,SAAI,GAAG,CAAC,CAAC;QACT,UAAK,GAAG,CAAC,CAAC;QAGjB,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC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,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IAChB,CAAC;CACD;AAED,SAAS,gBAAgB,CAAC,OAAe;IACxC,OAAO,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,YAAY,CAAC,KAAyB,EAAE,QAAgB;IAChE,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,KAAe,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACrF,CAAC"}
@@ -11,7 +11,9 @@
11
11
  * `mwg/two-d/stage`.
12
12
  */
13
13
  export { Game } from './Game.ts';
14
- export type { GameOptions } from './Game.ts';
14
+ export type { GameOptions, AudioSuspendRig } from './Game.ts';
15
+ export { QualityScaler } from './QualityScaler.ts';
16
+ export type { QualityScalerOptions } from './QualityScaler.ts';
15
17
  export { Scene2D } from './Scene2D.ts';
16
18
  export type { Scene2DClass } from './Scene2D.ts';
17
19
  export * from './render/index.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/two-d/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/two-d/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
@@ -11,6 +11,7 @@
11
11
  * `mwg/two-d/stage`.
12
12
  */
13
13
  export { Game } from './Game.js';
14
+ export { QualityScaler } from './QualityScaler.js';
14
15
  export { Scene2D } from './Scene2D.js';
15
16
  export * from './render/index.js';
16
17
  export * from './ui/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/two-d/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/two-d/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAGvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
@@ -62,4 +62,221 @@ export declare class RpgmAutotileAtlas {
62
62
  get(tileId: number, slot: RpgmAutotileSlot, shape: number): RpgmAutotileFrame;
63
63
  clear(): void;
64
64
  }
65
+ /**
66
+ * The first MV tile id of each autotile family (A1-A4): slot 0 covers
67
+ * 2048-2815, slot 1 covers 2816-4351, slot 2 covers 4352-5887 and slot 3
68
+ * covers 5888-8191. Measured against real A-sheets rather than assumed.
69
+ */
70
+ export declare const RPGM_AUTOTILE_SLOT_BASES: readonly [2048, 2816, 4352, 5888];
71
+ /**
72
+ * How many MV tile ids each family holds: 16, 32, 32 and 48 kinds of
73
+ * 48 shapes each. A sheet holding fewer cells than its slot needs is a
74
+ * truncated custom sheet, not a different layout.
75
+ */
76
+ export declare const RPGM_AUTOTILE_SLOT_COUNTS: readonly [768, 1536, 1536, 2304];
77
+ /**
78
+ * Which MV autotile family a raw map tile id belongs to, or null when the id
79
+ * is not an autotile at all (an `EMPTY` cell, a static B-E tile, an A5 tile).
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * import {
84
+ * rpgmAutotileSlot,
85
+ * RPGM_AUTOTILE_SLOT_BASES,
86
+ * RPGM_AUTOTILE_SLOT_COUNTS,
87
+ * } from '@datamoc/mw_games/two-d/render';
88
+ *
89
+ * console.log(rpgmAutotileSlot(2048)); // 0 - the first A1 tile
90
+ * console.log(rpgmAutotileSlot(3000)); // 1 - inside the A2 range
91
+ * console.log(rpgmAutotileSlot(42)); // null - a static tile, not an autotile
92
+ * console.log(rpgmAutotileSlot(-1)); // null - EMPTY reads as blank, never as a slot
93
+ * console.log(RPGM_AUTOTILE_SLOT_BASES[0]); // 2048 - where slot 0 starts
94
+ * console.log(RPGM_AUTOTILE_SLOT_COUNTS[0]); // 768 - 16 kinds times 48 shapes
95
+ * ```
96
+ */
97
+ export declare function rpgmAutotileSlot(tile: number): RpgmAutotileSlot | null;
98
+ /**
99
+ * The standard MV floor-autotile shape table (48 shapes), for slots 0-1:
100
+ * which four atlas quadrants each baked shape assembles, in 24px source
101
+ * cells. Entries are `[x, y]` offsets, row-major `[topLeft, topRight,
102
+ * bottomLeft, bottomRight]`, exactly the shape numbering MV bakes into map
103
+ * tile ids (`shape = (tile - base) % 48`).
104
+ *
105
+ * Functional interop data, the same category as `BLOB_SHAPES`: every game
106
+ * reading MV maps needs these numbers, so they live here once rather than
107
+ * pasted into every port.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { RPGM_FLOOR_AUTOTILE_TABLE, RPGM_WALL_AUTOTILE_TABLE } from '@datamoc/mw_games/two-d/render';
112
+ *
113
+ * console.log(RPGM_FLOOR_AUTOTILE_TABLE.length); // 48 - one entry per baked shape
114
+ * console.log(RPGM_WALL_AUTOTILE_TABLE.length); // 16 - walls cycle every 16 shapes
115
+ * console.log(RPGM_FLOOR_AUTOTILE_TABLE[47]); // [[0,0],[1,0],[0,1],[1,1]] - the full tile
116
+ * ```
117
+ */
118
+ export declare const RPGM_FLOOR_AUTOTILE_TABLE: RpgmAutotileShapeTable;
119
+ /**
120
+ * The standard MV wall-autotile shape table (16 shapes), for slots 2-3.
121
+ * Wall shapes cycle every 16 (`table[shape % 16]`), so a wall family holds
122
+ * three full cycles where a floor family holds one run of 48.
123
+ */
124
+ export declare const RPGM_WALL_AUTOTILE_TABLE: RpgmAutotileShapeTable;
125
+ /** one XP autotile pattern: four 16px mini-block indices, row-major `[topLeft, topRight, bottomLeft, bottomRight]` */
126
+ export type XpAutotilePattern = readonly [number, number, number, number];
127
+ /**
128
+ * The standard XP autotile pattern table (48 patterns). An XP autotile image
129
+ * is a 96 by 128 template: a 6-column grid of 16px mini-blocks, and each
130
+ * baked pattern assembles four of them. `tile % 48` selects the pattern;
131
+ * `tile / 48` (floored) selects which of the map's autotile images.
132
+ *
133
+ * Miniblock entries are 0-based here (block `n` sits at `(n % 6) * 16`,
134
+ * `(n / 6) * 16`). Learned from real XP autotile images and map data rather
135
+ * than assumed: the 6 by 8 mini-grid fits the measured 96 by 128 template
136
+ * exactly, and the neighbor table below reproduces baked map patterns.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * import { XP_AUTOTILE_PATTERNS, XP_NEIGHBORS_TO_PATTERN } from '@datamoc/mw_games/two-d/render';
141
+ *
142
+ * console.log(XP_AUTOTILE_PATTERNS.length); // 48 - one entry per baked pattern
143
+ * console.log(XP_AUTOTILE_PATTERNS[0]); // [26,27,32,33] - the filled interior tile
144
+ * console.log(XP_NEIGHBORS_TO_PATTERN.length); // 256 - one entry per 8-neighbour mask
145
+ * console.log(XP_NEIGHBORS_TO_PATTERN[255]); // 0 - surrounded on all sides is the interior
146
+ * ```
147
+ */
148
+ export declare const XP_AUTOTILE_PATTERNS: readonly XpAutotilePattern[];
149
+ /**
150
+ * Which XP pattern an 8-neighbourhood of same-autotile cells bakes to. Index
151
+ * with a bit mask - north `0x01`, northeast `0x02`, east `0x04`, southeast
152
+ * `0x08`, south `0x10`, southwest `0x20`, west `0x40`, northwest `0x80` - for
153
+ * games computing patterns procedurally instead of reading baked map data.
154
+ */
155
+ export declare const XP_NEIGHBORS_TO_PATTERN: readonly number[];
156
+ /** an XP map cell decoded into its autotile image and baked pattern */
157
+ export interface XpAutotileRef {
158
+ /** which autotile image, 0-7 (`tile / 48` floored) */
159
+ index: number;
160
+ /** which pattern in that image, 0-47 (`tile % 48`) */
161
+ pattern: number;
162
+ }
163
+ /**
164
+ * Decodes a raw XP map cell into its autotile image and pattern, or null
165
+ * when the cell holds no autotile reference: `EMPTY`, a static tileset tile
166
+ * (384 and up), or anything outside the 1-383 autotile range.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import { xpAutotileRef } from '@datamoc/mw_games/two-d/render';
171
+ *
172
+ * console.log(xpAutotileRef(97)); // { index: 2, pattern: 1 } - second image, second pattern
173
+ * console.log(xpAutotileRef(0)); // null - EMPTY is blank, never an autotile
174
+ * console.log(xpAutotileRef(384)); // null - the first static tileset tile
175
+ * ```
176
+ */
177
+ export declare function xpAutotileRef(tile: number): XpAutotileRef | null;
178
+ /**
179
+ * Which XP pattern a cell's 8-neighbourhood bakes to, for maps computed
180
+ * procedurally rather than read from baked data. `sameTerrain` is asked once
181
+ * per direction, with `(dx, dy)` offsets (`(0, -1)` is north); off the map is
182
+ * the caller's to answer (false reads as a border, the edge cell's own value
183
+ * clamps like the editor).
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { xpAutotilePattern } from '@datamoc/mw_games/two-d/render';
188
+ *
189
+ * const filled = new Set(['0,0', '1,0', '0,1', '1,1', '-1,0', '0,-1', '2,1', '1,2']);
190
+ * console.log(xpAutotilePattern((dx, dy) => filled.has(`${dx},${dy}`))); // 0 - the interior
191
+ * console.log(xpAutotilePattern(() => false)); // 46 - isolated on all sides
192
+ * ```
193
+ */
194
+ export declare function xpAutotilePattern(sameTerrain: (dx: number, dy: number) => boolean): number;
195
+ /**
196
+ * One drawn piece of an autotile cell: where to sample the source sheet and
197
+ * where the piece lands on the map tile, the destination in fractions of one
198
+ * tile (quadrant halves at `0`/`0.5` with size `0.5`, or the whole tile at
199
+ * `0` with size `1` for single-tile strips).
200
+ */
201
+ export interface AutotileCellPart {
202
+ sourceX: number;
203
+ sourceY: number;
204
+ sourceWidth: number;
205
+ sourceHeight: number;
206
+ destX: number;
207
+ destY: number;
208
+ destWidth: number;
209
+ destHeight: number;
210
+ }
211
+ /**
212
+ * An autotile source fully described: everything `autotileCellParts` needs
213
+ * except the sheet texture itself (which lives renderer-side, in the layer).
214
+ * `TileMap.addAutotileLayer` resolves a user-facing `AutotileSet` into one
215
+ * of these and validates it once with `assertAutotileLayout`, so per-cell
216
+ * resolution never re-checks the table.
217
+ */
218
+ export type AutotileLayout = {
219
+ format: 'rpgm-mv';
220
+ slot: RpgmAutotileSlot;
221
+ table: RpgmAutotileShapeTable;
222
+ /** kind runs that advance together; a cell whose kind is in no run ignores the frame */
223
+ cycles: ReadonlyArray<ReadonlyArray<number>>;
224
+ } | {
225
+ format: 'rpgm-xp';
226
+ /** which autotile image, 0-7 */
227
+ index: number;
228
+ /** animation stripes in the image; frame wraps around this count */
229
+ frames: number;
230
+ /** a 32px-tall single-tile strip: one whole-tile piece per frame, patterns ignored */
231
+ single: boolean;
232
+ };
233
+ /**
234
+ * Checks a resolved autotile layout once, up front. Throws naming the first
235
+ * problem: a bad slot, an empty shape table, an empty animation cycle, a
236
+ * cycle kind outside its slot's kinds, a bad XP index, or a frame count
237
+ * below one.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * import {
242
+ * assertAutotileLayout,
243
+ * RPGM_FLOOR_AUTOTILE_TABLE,
244
+ * } from '@datamoc/mw_games/two-d/render';
245
+ *
246
+ * assertAutotileLayout({ format: 'rpgm-mv', slot: 0, table: RPGM_FLOOR_AUTOTILE_TABLE, cycles: [[0, 1, 2]] });
247
+ * assertAutotileLayout({ format: 'rpgm-xp', index: 2, frames: 1, single: false });
248
+ * ```
249
+ */
250
+ export declare function assertAutotileLayout(layout: AutotileLayout): void;
251
+ /**
252
+ * Resolves one autotile cell to its drawn pieces: four quadrant halves for a
253
+ * template cell, one whole-tile piece for an XP single-tile strip, or null
254
+ * for a blank cell (`tile <= 0` reads as blank; `EMPTY` is -1).
255
+ *
256
+ * The layout is assumed valid (`assertAutotileLayout`); only the cell and
257
+ * frame are checked here. `tile` must be an integer the layout claims - an
258
+ * MV id in the layout's slot range, an XP id in `index * 48` to
259
+ * `index * 48 + 47` - and `frame` an integer at or above zero, wrapping
260
+ * around the animation cycles (MV) or frame stripes (XP).
261
+ *
262
+ * @example
263
+ * ```ts
264
+ * import {
265
+ * autotileCellParts,
266
+ * RPGM_FLOOR_AUTOTILE_TABLE,
267
+ * } from '@datamoc/mw_games/two-d/render';
268
+ *
269
+ * const parts = autotileCellParts(
270
+ * { format: 'rpgm-mv', slot: 0, table: RPGM_FLOOR_AUTOTILE_TABLE, cycles: [] },
271
+ * 2048, 0,
272
+ * );
273
+ * console.log(parts?.length); // 4 - one piece per quadrant
274
+ * console.log(parts?.[0].sourceWidth); // 24 - MV quadrant halves
275
+ * console.log(autotileCellParts(
276
+ * { format: 'rpgm-xp', index: 2, frames: 1, single: false },
277
+ * 97, 0,
278
+ * )?.[0].sourceWidth); // 16 - XP quadrant halves
279
+ * ```
280
+ */
281
+ export declare function autotileCellParts(layout: AutotileLayout, tile: number, frame: number): AutotileCellPart[] | null;
65
282
  //# sourceMappingURL=RpgmAutotile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RpgmAutotile.d.ts","sourceRoot":"","sources":["../../../src/two-d/render/RpgmAutotile.ts"],"names":[],"mappings":"AAAA,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAE7C,2EAA2E;AAC3E,MAAM,WAAW,oBAAoB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACrB;AAED,8EAA8E;AAC9E,MAAM,WAAW,iBAAiB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,gBAAgB,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;CAC7G;AAED,6EAA6E;AAC7E,MAAM,MAAM,iBAAiB,GAAG,SAAS;IACxC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,SAAS,iBAAiB,EAAE,CAAC;AA2ClE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,gB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