@unboxy/phaser-sdk 0.2.28 → 0.2.30

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.
@@ -0,0 +1,125 @@
1
+ import Phaser from 'phaser';
2
+ import { Anchor, AssetRecord, HudEntity, HudScene, Manifest } from './types.js';
3
+ import { EntityRegistry } from './EntityRegistry.js';
4
+ /**
5
+ * HUD runtime — slice 5.
6
+ *
7
+ * `UnboxyHudScene` is a Phaser scene class that runs in parallel with the
8
+ * world scene, draws anchor-positioned widgets above the gameplay, and
9
+ * subscribes dynamic-text widgets to the game registry so they live-update
10
+ * when the agent's behavior code calls `this.registry.set(key, value)`.
11
+ *
12
+ * Agent contract (taught by the `hud-dynamic-binding` skill):
13
+ * - Use `scene.registry.set(key, value)` to drive HUD bindings. The HUD
14
+ * scene picks up the change via `registry.events.on('changedata-<key>')`.
15
+ * - The HUD widget JSON references the key via `visual.source.binding`.
16
+ */
17
+ export declare const UNBOXY_HUD_SCENE_KEY = "UnboxyHud";
18
+ interface HudSceneInit {
19
+ /** HUD id from manifest.huds[]. */
20
+ hudId?: string;
21
+ }
22
+ /**
23
+ * Resolve a HUD anchor + offset against the current canvas size to a
24
+ * concrete pixel position. Called per widget on (a) initial spawn and (b)
25
+ * scale resize so widgets re-anchor when the viewport changes.
26
+ */
27
+ export declare function resolveAnchor(scene: Phaser.Scene, anchor: Anchor, safeArea?: {
28
+ top: number;
29
+ right: number;
30
+ bottom: number;
31
+ left: number;
32
+ }): {
33
+ x: number;
34
+ y: number;
35
+ };
36
+ interface SpawnContext {
37
+ scene: Phaser.Scene;
38
+ registry: EntityRegistry;
39
+ safeArea: {
40
+ top: number;
41
+ right: number;
42
+ bottom: number;
43
+ left: number;
44
+ };
45
+ resolveAsset: (id: string) => AssetRecord;
46
+ }
47
+ /**
48
+ * Spawn a HUD widget into the scene. The returned GameObject is recorded in
49
+ * the entity registry so the editor + behavior code can find it by id.
50
+ */
51
+ export declare function spawnHudEntity(ctx: SpawnContext, entity: HudEntity): Phaser.GameObjects.GameObject;
52
+ /**
53
+ * Walk a HudScene's entities and queue Phaser loads for any image / icon
54
+ * assets it references. Idempotent — relies on `manifestState.requestedAssetIds`
55
+ * if SceneLoader's preload helpers have already touched this scene.
56
+ */
57
+ export declare function preloadHudAssets(scene: Phaser.Scene, hudScene: HudScene, manifest: Manifest): void;
58
+ /**
59
+ * Load and spawn a HUD scene into the given Phaser scene. Symmetric to
60
+ * `loadWorldScene`. Returns the parsed scene file + entity registry.
61
+ *
62
+ * Pattern (in `UnboxyHudScene.create`):
63
+ * const result = await loadHudScene(this, hudId);
64
+ * // widgets live; agent's behavior code can subscribe to events via
65
+ * // `this.events.on('hud:press', id => ...)`.
66
+ */
67
+ export declare function loadHudScene(scene: Phaser.Scene, hudId: string): Promise<{
68
+ hudScene: HudScene;
69
+ registry: EntityRegistry;
70
+ }>;
71
+ /** Find the HUD scene's entity registry, if a HUD scene is currently active. */
72
+ export declare function findHudRegistry(game: Phaser.Game): EntityRegistry | undefined;
73
+ /** Find the HUD scene file from the JSON cache, if loaded. */
74
+ export declare function findHudSceneFile(game: Phaser.Game): HudScene | undefined;
75
+ /**
76
+ * Look up a HUD entity record from the cached scene file. Used by the bridge
77
+ * during drag (to read anchor side / current offset) and applyEdit (to
78
+ * resolve the new anchor when side changes).
79
+ */
80
+ export declare function findHudEntity(game: Phaser.Game, entityId: string): HudEntity | undefined;
81
+ /**
82
+ * Compute the canvas-pixel base position for an entity's anchor side
83
+ * (without offset). Used on drag-end to derive the new offset from the
84
+ * GameObject's final position.
85
+ */
86
+ export declare function getHudAnchorBase(game: Phaser.Game, entity: HudEntity): {
87
+ x: number;
88
+ y: number;
89
+ };
90
+ /**
91
+ * Apply an editor patch to a live HUD widget. Mirrors the spawn function's
92
+ * logic but operates on the existing GameObject — anchor changes
93
+ * re-resolve position; text source changes rewire the registry subscription;
94
+ * visual style changes setText / setColor / etc. directly.
95
+ *
96
+ * Returns true if a known field was patched, false if nothing applied.
97
+ */
98
+ export declare function applyHudPatch(game: Phaser.Game, entityId: string, patch: {
99
+ anchor?: {
100
+ side?: string;
101
+ offsetX?: number;
102
+ offsetY?: number;
103
+ };
104
+ layer?: string;
105
+ z?: number;
106
+ visual?: Record<string, unknown>;
107
+ role?: string | null;
108
+ properties?: Record<string, unknown>;
109
+ }): boolean;
110
+ /** Spawn a fresh HUD entity into the active HUD scene. Used by editor's create-entity path. */
111
+ export declare function createHudEntityInScene(game: Phaser.Game, entity: HudEntity): boolean;
112
+ /** Destroy a HUD entity. */
113
+ export declare function deleteHudEntityFromScene(game: Phaser.Game, entityId: string): boolean;
114
+ /**
115
+ * Per-game HUD scene. Auto-launched by `createUnboxyGame` when the world
116
+ * scene's manifest entry sets `hud: '<id>'`. Renders above the world via
117
+ * Phaser's scene rendering order; takes input independently.
118
+ */
119
+ export declare class UnboxyHudScene extends Phaser.Scene {
120
+ private hudId;
121
+ constructor();
122
+ init(data: HudSceneInit): void;
123
+ create(): Promise<void>;
124
+ }
125
+ export {};