@moku-labs/game 0.0.2 → 0.1.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 (35) hide show
  1. package/README.md +107 -31
  2. package/dist/assets.d.mts +58 -6
  3. package/dist/assets.mjs +1630 -234
  4. package/dist/commands-C0BljsM5.d.mts +99 -0
  5. package/dist/control.d.mts +3 -92
  6. package/dist/control.mjs +3 -757
  7. package/dist/define-CjP_4H0G.d.mts +51 -0
  8. package/dist/{registry-DlpRCibU.mjs → dev-CcwFrwok.mjs} +30 -1
  9. package/dist/index.d.mts +362 -303
  10. package/dist/index.mjs +12717 -6654
  11. package/dist/inspect.d.mts +10 -8
  12. package/dist/inspect.mjs +2 -518
  13. package/dist/jsx-dev-runtime.d.mts +1 -1
  14. package/dist/jsx-runtime.d.mts +1 -1
  15. package/dist/{rolldown-runtime-D7D4PA-g.mjs → rolldown-runtime-8H4AJuhK.mjs} +1 -0
  16. package/dist/run-tlcn1w7y.mjs +944 -0
  17. package/dist/{runtime-DiOTkDZz.d.mts → runtime-Bn5TXNxP.d.mts} +1 -1
  18. package/dist/sources-BooL2MsX.mjs +545 -0
  19. package/dist/testing.d.mts +328 -3
  20. package/dist/testing.mjs +2126 -2
  21. package/dist/types-BZ1OLf24.d.mts +5999 -0
  22. package/dist/{types-DWILGrPn.d.mts → types-C47fKNcn.d.mts} +93 -20
  23. package/dist/types-CqkrEY06.d.mts +1734 -0
  24. package/dist/types-CxZy7Pi4.d.mts +1210 -0
  25. package/dist/{define-sFoO3y6X.d.mts → types-DmhTHRVW.d.mts} +180 -51
  26. package/dist/{types-yg_ywtT-.d.mts → types-X9jXjka3.d.mts} +230 -31
  27. package/dist/{visual-BDUHSRvf.mjs → visual-NPrDkvUk.mjs} +19 -13
  28. package/package.json +22 -2
  29. package/dist/headless-CvamCUcR.mjs +0 -186
  30. package/dist/headless-KaSWcd0s.d.mts +0 -181
  31. package/dist/types-BxkNNYul.d.mts +0 -2840
  32. package/dist/types-CTPS9GBu.d.mts +0 -742
  33. package/dist/types-DD-QrG_z.d.mts +0 -588
  34. package/dist/types-DYLnSgMI.d.mts +0 -570
  35. package/dist/types-JNc_UQBo.d.mts +0 -2896
@@ -1,11 +1,10 @@
1
- import { T as Descriptor, k as Api$2, lt as Require, t as Api$1, x as NodeInfo } from "./types-JNc_UQBo.mjs";
2
- import { r as PixiTexture, t as Api$3 } from "./types-BxkNNYul.mjs";
1
+ import { St as Api$3, f as SliceFrame, mt as NodeInfo, nn as Require, o as PixiTexture, q as Api$1, t as Api$2, vt as Descriptor } from "./types-BZ1OLf24.mjs";
3
2
  import { Log } from "@moku-labs/common/browser";
4
3
  import { PluginCtx } from "@moku-labs/core";
5
4
 
6
5
  //#region src/plugins/assets/types.d.ts
7
6
  declare namespace types_d_exports {
8
- export { Api, AssetKind, AssetsCtx, AssetsIo, AtlasFrame, BundleMap, BundleRecord, BundleSpec, BundleUsage, Config, CreateTextureOptions, DecodedImage, DefineBundles, Deps, Events, FetchResponse, FlowRest, FontAsset, FontPage, Inflight, KernelSlice, LoadBundles, LoadReason, LoadResult, LoadedAssets, LoadedFont, Manifest, ManifestBundle, ManifestFile, NineBorders, NineSlice, PreloadQueue, State, Texture, Tier, Usage };
7
+ export { Api, AssetKind, AssetsCtx, AssetsIo, AtlasFrame, AtlasPage, BundleMap, BundleRecord, BundleSpec, BundleUsage, Config, CreateTextureOptions, DecodedImage, DefineBundles, Deps, Events, FetchResponse, FlowRest, FontAsset, FontPage, Inflight, KernelSlice, LoadBundles, LoadReason, LoadResult, LoadedAssets, LoadedFont, Manifest, ManifestBundle, ManifestFile, NineBorders, NineSlice, PreloadQueue, State, Texture, Tier, Usage };
9
8
  }
10
9
  /**
11
10
  * When a bundle is loaded. `boot` and `core` stay for the whole session, `scene` and `feature`
@@ -60,11 +59,15 @@ type CreateTextureOptions = {
60
59
  /**
61
60
  * The part of a fetch response the plugin reads: the manifest is `json`, a texture is a `blob`,
62
61
  * a font file is `text` and an audio file stays the raw `arrayBuffer`. The global `Response`
63
- * fits it.
62
+ * fits it. `headers` gives the `content-type`: on `tauri://` a missing file comes back `200` with
63
+ * `index.html`, so `text/html` for a path that is not `.html` counts as missing.
64
64
  */
65
65
  type FetchResponse = {
66
66
  ok: boolean;
67
67
  status: number;
68
+ headers: {
69
+ get(name: string): string | null;
70
+ };
68
71
  json(): Promise<unknown>;
69
72
  blob(): Promise<Blob>;
70
73
  text(): Promise<string>;
@@ -81,6 +84,7 @@ type FetchResponse = {
81
84
  * fetch: async () => ({
82
85
  * ok: true,
83
86
  * status: 200,
87
+ * headers: { get: () => null },
84
88
  * json: async () => ({}),
85
89
  * blob: async () => blob,
86
90
  * text: async () => 'info face="body"',
@@ -88,6 +92,7 @@ type FetchResponse = {
88
92
  * }),
89
93
  * decode: async () => bitmap,
90
94
  * createTexture: () => ({ id: "t1" }) as unknown as Texture,
95
+ * sliceTexture: (page, frame) => ({ id: "s1", page, frame }) as unknown as Texture,
91
96
  * destroyTexture: texture => destroyed.push(texture)
92
97
  * };
93
98
  *
@@ -122,7 +127,19 @@ type AssetsIo = {
122
127
  */
123
128
  createTexture(image: DecodedImage, options?: CreateTextureOptions): Texture;
124
129
  /**
125
- * Frees one texture and its source.
130
+ * Cuts the texture of one packed file out of its atlas page. The slice shares the page's
131
+ * source: no pixel is copied. Same shape as `renderer.sync.textures.slice`; the manifest's
132
+ * `atlas` frame is passed as it is.
133
+ *
134
+ * @param page - The page texture, made by `createTexture`.
135
+ * @param frame - Where the file lies on the page, in page pixels.
136
+ * @param options - `nine` becomes the default nine-slice borders of the slice.
137
+ * @returns The new texture over the page's source.
138
+ */
139
+ sliceTexture(page: Texture, frame: SliceFrame, options?: CreateTextureOptions): Texture;
140
+ /**
141
+ * Frees one texture. A page frees its source too; a slice frees only itself, so the slices of
142
+ * a bundle go first and its pages after them.
126
143
  *
127
144
  * @param texture - The texture to free.
128
145
  */
@@ -144,11 +161,13 @@ type NineSlice = {
144
161
  bottom: number;
145
162
  };
146
163
  /**
147
- * Reserved atlas placement. V2 never writes it and refuses to load a file that carries it.
164
+ * Where a packed file lies: `page` is the id of a page of the same bundle, never a file name, and
165
+ * the frame is in page pixels. `width` and `height` equal the file's own, so its `nine` stays
166
+ * valid as it is. The packer writes it; the loader cuts the file out of the page.
148
167
  *
149
168
  * @example
150
169
  * ```ts
151
- * const frame: AtlasFrame = { page: "ui-0.png", x: 0, y: 0, width: 128, height: 128 };
170
+ * const frame: AtlasFrame = { page: "ui/main-0", x: 583, y: 595, width: 256, height: 128 };
152
171
  * ```
153
172
  */
154
173
  type AtlasFrame = {
@@ -158,6 +177,29 @@ type AtlasFrame = {
158
177
  width: number;
159
178
  height: number;
160
179
  };
180
+ /**
181
+ * One atlas page of a packed bundle. `id` is `<bundle>/<group>-<index>`, the name an `atlas`
182
+ * frame uses; `path` is the hashed WebP file, read like the `path` of a file. `mb` is
183
+ * `width × height × 4 / 1 048 576`: the page carries the cost of every file packed on it.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * const page: AtlasPage = {
188
+ * id: "ui/main-0",
189
+ * path: "ui/main-0-3b1d55a0c9.webp",
190
+ * width: 966,
191
+ * height: 1365,
192
+ * mb: 5.03
193
+ * };
194
+ * ```
195
+ */
196
+ type AtlasPage = {
197
+ id: string;
198
+ path: string;
199
+ width: number;
200
+ height: number;
201
+ mb: number;
202
+ };
161
203
  /**
162
204
  * One page image of a font. A page has no key of its own: it belongs to the `.fnt` file that
163
205
  * names it, and is loaded and freed with it.
@@ -180,12 +222,15 @@ type FontPage = {
180
222
  };
181
223
  /**
182
224
  * One file of a bundle. `mb` is what it costs: `width × height × 4` bytes for a texture, the sum
183
- * of the pages for a font, the size of the file for audio. `kind` is absent for a texture, which
184
- * is what every manifest written before fonts and audio carries.
225
+ * of the pages for a font, the size of the file for audio, and `0` for a texture packed in an
226
+ * atlas, whose page carries the cost. `kind` is absent for a texture, which is what every
227
+ * manifest written before fonts and audio carries. A loose file has `path`; a packed texture has
228
+ * `atlas` and no `path`.
185
229
  *
186
230
  * @example
187
231
  * ```ts
188
- * const file: ManifestFile = {
232
+ * // The dev manifest of the scanner: a loose file.
233
+ * const loose: ManifestFile = {
189
234
  * key: "ui.panel",
190
235
  * path: "features/ui/assets/panel{nine=48}.png",
191
236
  * width: 256,
@@ -193,11 +238,21 @@ type FontPage = {
193
238
  * mb: 0.125,
194
239
  * nine: { left: 48, top: 48, right: 48, bottom: 48 }
195
240
  * };
241
+ *
242
+ * // The packed manifest: the same key, cut out of the page "ui/main-0".
243
+ * const packed: ManifestFile = {
244
+ * key: "ui.panel",
245
+ * width: 256,
246
+ * height: 128,
247
+ * mb: 0,
248
+ * nine: { left: 48, top: 48, right: 48, bottom: 48 },
249
+ * atlas: { page: "ui/main-0", x: 583, y: 595, width: 256, height: 128 }
250
+ * };
196
251
  * ```
197
252
  */
198
253
  type ManifestFile = {
199
254
  key: string;
200
- path: string;
255
+ path?: string;
201
256
  kind?: AssetKind;
202
257
  width: number;
203
258
  height: number;
@@ -207,7 +262,9 @@ type ManifestFile = {
207
262
  atlas?: AtlasFrame;
208
263
  };
209
264
  /**
210
- * One bundle of the manifest: which feature owns it, when it loads and what it costs.
265
+ * One bundle of the manifest: which feature owns it, when it loads and what it costs. `pages` is
266
+ * written by the packer only, sorted by id; `mb` is then its pages, its loose textures, its font
267
+ * pages and its audio bytes together.
211
268
  *
212
269
  * @example
213
270
  * ```ts
@@ -218,24 +275,37 @@ type ManifestBundle = {
218
275
  feature: string;
219
276
  tier: Tier;
220
277
  mb: number;
278
+ pages?: readonly AtlasPage[];
221
279
  files: readonly ManifestFile[];
222
280
  };
223
281
  /**
224
- * The manifest: the contract between the scanner, this plugin and the editor later. Bundles are
225
- * sorted by name and files by key, so two scans of the same tree give the same bytes.
282
+ * The manifest: the contract between the scanner, the packer, this plugin and the editor. Version
283
+ * `1` is the dev manifest of `bun run assets:keys`, version `2` the packed one of
284
+ * `bun run assets:pack`; the plugin reads both. Bundles are sorted by name, pages by id and files
285
+ * by key, so two runs on the same tree give the same bytes.
226
286
  *
227
287
  * @example
228
288
  * ```ts
289
+ * // A dev build: loose files, straight from the features.
229
290
  * const manifest: Manifest = {
230
291
  * version: 1,
231
292
  * bundles: { ui: { feature: "ui", tier: "core", mb: 0, files: [] } }
232
293
  * };
233
294
  *
234
295
  * createApp({ plugins: [...screen], pluginConfigs: { assets: { manifest } } });
296
+ *
297
+ * // The packed manifest of the same game: the panel is cut out of the page "ui/main-0".
298
+ * const page = { id: "ui/main-0", path: "ui/main-0-3b1d55a0c9.webp", width: 966, height: 1365, mb: 5.03 };
299
+ * const atlas = { page: "ui/main-0", x: 583, y: 595, width: 256, height: 128 };
300
+ * const panel = { key: "ui.panel", width: 256, height: 128, mb: 0, atlas };
301
+ * const packed: Manifest = {
302
+ * version: 2,
303
+ * bundles: { ui: { feature: "ui", tier: "core", mb: 5.03, pages: [page], files: [panel] } }
304
+ * };
235
305
  * ```
236
306
  */
237
307
  type Manifest = {
238
- version: 1;
308
+ version: 1 | 2;
239
309
  bundles: Readonly<Record<string, ManifestBundle>>;
240
310
  };
241
311
  /**
@@ -339,13 +409,15 @@ type LoadedFont = FontAsset & {
339
409
  pages: readonly Texture[];
340
410
  };
341
411
  /**
342
- * What one bundle brought, by asset key: textures, fonts with their pages, and the undecoded
343
- * bytes of the audio files. A running load fills the same three maps before they are published.
412
+ * What one bundle brought: textures by asset key (a packed file's is a slice of its page), fonts
413
+ * with their pages, the undecoded bytes of the audio files, and the atlas pages by page id. A
414
+ * running load fills the same four maps before they are published.
344
415
  */
345
416
  type LoadedAssets = {
346
417
  textures: Map<string, Texture>;
347
418
  fonts: Map<string, LoadedFont>;
348
419
  audio: Map<string, ArrayBuffer>;
420
+ pages: Map<string, Texture>;
349
421
  };
350
422
  /**
351
423
  * What the plugin knows about one bundle. `lastUsed` is the value of `useCounter` at the last
@@ -530,7 +602,8 @@ type Api = {
530
602
  /**
531
603
  * The texture of a loaded asset key. It touches the use counter of the bundle, which is what
532
604
  * the LRU reads. A key of a bundle that is not loaded warns once, starts a background load and
533
- * answers `undefined`; the sprites waiting for it are textured when that load lands.
605
+ * answers `undefined`; the sprites waiting for it are textured when that load lands. A key packed
606
+ * in an atlas answers its slice of the page, so a game never sees the difference.
534
607
  *
535
608
  * @param key - Asset key, as `generated/assets.ts` types it.
536
609
  * @returns The texture, or `undefined` while the bundle is not loaded.
@@ -590,8 +663,8 @@ type Api = {
590
663
  */
591
664
  type Deps = {
592
665
  flow: Api$1;
593
- renderer: Api$3;
594
- time: Api$2;
666
+ renderer: Api$2;
667
+ time: Api$3;
595
668
  };
596
669
  /**
597
670
  * What the kernel context offers before the deps are attached.