@unboxy/phaser-sdk 0.2.27 → 0.2.29

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.
@@ -187,6 +187,15 @@ export async function loadWorldScene(scene, sceneId, options = {}) {
187
187
  spawnEntity(ctx, entity);
188
188
  // Configure camera.
189
189
  applyCamera(scene, sceneFile, registry);
190
+ // Auto-launch the HUD scene attached to this world (slice 5). Imported
191
+ // lazily to avoid pulling HudRuntime into worlds that don't need it.
192
+ if (ref.hud) {
193
+ const { UNBOXY_HUD_SCENE_KEY } = await import('./HudRuntime.js');
194
+ if (scene.scene.isActive(UNBOXY_HUD_SCENE_KEY)) {
195
+ scene.scene.stop(UNBOXY_HUD_SCENE_KEY);
196
+ }
197
+ scene.scene.launch(UNBOXY_HUD_SCENE_KEY, { hudId: ref.hud });
198
+ }
190
199
  return { sceneFile, registry };
191
200
  }
192
201
  async function loadSceneJson(scene, ref) {
@@ -260,17 +260,114 @@ export interface WorldScene {
260
260
  updatedAt?: string;
261
261
  };
262
262
  }
263
+ export type HudLayer = 'base' | 'overlay' | 'modal';
263
264
  /**
264
- * HUD scene schema slot v1 reserves the shape for slice 5. The loader
265
- * throws if it encounters one in slice 1; the type lives here so the
266
- * manifest's `huds[]` list is well-typed.
265
+ * Text content source`static` is a literal string the user typed;
266
+ * `dynamic` reads a value from `unboxy.gameData` at runtime, with optional
267
+ * prefix/suffix formatting. The Inspector only edits the static path; the
268
+ * agent flips a widget to `dynamic` via the inline AI popover when the user
269
+ * asks for live values ("show current score"). The variable registry +
270
+ * picker UX from design 04 §4.7 is intentionally NOT implemented — Unboxy's
271
+ * thesis is users don't see "variables", agent handles bindings.
267
272
  */
273
+ export type HudTextSource = {
274
+ mode: 'static';
275
+ text: string;
276
+ } | {
277
+ mode: 'dynamic';
278
+ /** Key in `unboxy.gameData` whose value drives the text. */
279
+ binding: string;
280
+ prefix?: string;
281
+ suffix?: string;
282
+ /** Fallback value rendered when the binding is unset. */
283
+ fallback?: string;
284
+ };
285
+ export interface HudTextVisual {
286
+ kind: 'text';
287
+ source: HudTextSource;
288
+ fontFamily?: string;
289
+ fontSize?: number;
290
+ color?: string;
291
+ align?: 'left' | 'center' | 'right';
292
+ }
293
+ export interface HudImageVisual {
294
+ kind: 'image';
295
+ assetId: string;
296
+ /** Atlas frame name OR sprite-sheet frame index. */
297
+ frame?: string | number;
298
+ /** CSS pixel size on the HUD scene's logical canvas. */
299
+ width?: number;
300
+ height?: number;
301
+ tint?: string;
302
+ alpha?: number;
303
+ }
304
+ export interface HudIconButtonVisual {
305
+ kind: 'icon-button';
306
+ /** Optional displayed label. */
307
+ label?: string;
308
+ /** Optional icon asset shown inside the button. */
309
+ iconAssetId?: string;
310
+ /** Button shape. Default `rounded-rect`. */
311
+ shape?: 'rounded-rect' | 'circle';
312
+ width?: number;
313
+ height?: number;
314
+ fillColor?: string;
315
+ strokeColor?: string | null;
316
+ strokeWidth?: number;
317
+ pressedFillColor?: string;
318
+ textColor?: string;
319
+ fontSize?: number;
320
+ }
321
+ export type HudVisual = HudTextVisual | HudImageVisual | HudIconButtonVisual;
322
+ export type HudEntityKind = 'text' | 'image' | 'icon-button';
323
+ export interface HudEntityBase {
324
+ id: string;
325
+ /** Optional semantic tag. Behavior code keys off this. */
326
+ role?: string;
327
+ /** Free-form per-entity data the agent's behavior code reads. */
328
+ properties?: Record<string, unknown>;
329
+ anchor: Anchor;
330
+ /** Render layer (base < overlay < modal). Defaults to `base`. */
331
+ layer?: HudLayer;
332
+ /**
333
+ * Z-order within the same layer. Higher = on top. Optional; defaults to
334
+ * insertion order if absent.
335
+ */
336
+ z?: number;
337
+ /** When false, the widget is hidden at runtime. Useful for modal panels
338
+ * that the agent toggles via gameData / scene events. */
339
+ visible?: boolean;
340
+ }
341
+ export interface HudTextEntity extends HudEntityBase {
342
+ kind: 'text';
343
+ visual: HudTextVisual;
344
+ }
345
+ export interface HudImageEntity extends HudEntityBase {
346
+ kind: 'image';
347
+ visual: HudImageVisual;
348
+ }
349
+ /**
350
+ * Icon button. v1 has no built-in onPress wiring — clicks emit a Phaser
351
+ * scene event `hud:press` with the entity id, and the agent's behavior code
352
+ * subscribes (`scene.events.on('hud:press', id => ...)`). The slice-4
353
+ * popover is the user's path to wire one up: select the button, ✨, "pause
354
+ * the game when this is pressed". design 04 §6 / §7's bind-to-action +
355
+ * built-in-presets system is reserved for slice 5.5.
356
+ */
357
+ export interface HudIconButtonEntity extends HudEntityBase {
358
+ kind: 'icon-button';
359
+ visual: HudIconButtonVisual;
360
+ }
361
+ export type HudEntity = HudTextEntity | HudImageEntity | HudIconButtonEntity;
268
362
  export interface HudScene {
269
363
  schemaVersion: number;
270
364
  id: string;
271
365
  name: string;
272
366
  type: 'hud';
273
367
  design?: {
368
+ /** e.g. `"16:9"`, `"9:16"`. Free-form for now; the editor uses it for the
369
+ * preview-frame visualization (design 04 §2.1). v1 doesn't enforce it
370
+ * at runtime — anchors resolve against the actual canvas size. */
274
371
  designAspectRatio?: string;
275
372
  safeArea?: {
276
373
  top: number;
@@ -279,7 +376,7 @@ export interface HudScene {
279
376
  left: number;
280
377
  };
281
378
  };
282
- entities: unknown[];
379
+ entities: HudEntity[];
283
380
  metadata?: WorldScene['metadata'];
284
381
  }
285
382
  export type SceneFile = WorldScene | HudScene;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboxy/phaser-sdk",
3
- "version": "0.2.27",
3
+ "version": "0.2.29",
4
4
  "description": "Unboxy Phaser 3 SDK — game infrastructure for the Unboxy platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",