@umicat/phaser-sdk 1.0.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.
- package/SDK-GUIDE.md +1726 -0
- package/dist/core/Transport.d.ts +28 -0
- package/dist/core/Transport.js +7 -0
- package/dist/core/Umicat.d.ts +45 -0
- package/dist/core/Umicat.js +60 -0
- package/dist/core/UmicatGame.d.ts +43 -0
- package/dist/core/UmicatGame.js +64 -0
- package/dist/core/UmicatScene.d.ts +19 -0
- package/dist/core/UmicatScene.js +38 -0
- package/dist/core/transports/LocalStorageTransport.d.ts +22 -0
- package/dist/core/transports/LocalStorageTransport.js +78 -0
- package/dist/core/transports/PostMessageTransport.d.ts +28 -0
- package/dist/core/transports/PostMessageTransport.js +105 -0
- package/dist/editor/EditorBridge.d.ts +114 -0
- package/dist/editor/EditorBridge.js +2608 -0
- package/dist/editor/EditorOverlayScene.d.ts +333 -0
- package/dist/editor/EditorOverlayScene.js +1896 -0
- package/dist/editor/EditorState.d.ts +251 -0
- package/dist/editor/EditorState.js +197 -0
- package/dist/gamedata/GameDataModule.d.ts +45 -0
- package/dist/gamedata/GameDataModule.js +59 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/orientation.d.ts +5 -0
- package/dist/orientation.js +4 -0
- package/dist/protocol.d.ts +807 -0
- package/dist/protocol.js +3 -0
- package/dist/realtime/RealtimeModule.d.ts +93 -0
- package/dist/realtime/RealtimeModule.js +115 -0
- package/dist/realtime/UmicatRoom.d.ts +197 -0
- package/dist/realtime/UmicatRoom.js +353 -0
- package/dist/recording/RecordingManager.d.ts +11 -0
- package/dist/recording/RecordingManager.js +59 -0
- package/dist/saves/SavesModule.d.ts +23 -0
- package/dist/saves/SavesModule.js +37 -0
- package/dist/scene/EditorMode.d.ts +17 -0
- package/dist/scene/EditorMode.js +22 -0
- package/dist/scene/EntityRegistry.d.ts +39 -0
- package/dist/scene/EntityRegistry.js +103 -0
- package/dist/scene/GameConfig.d.ts +60 -0
- package/dist/scene/GameConfig.js +50 -0
- package/dist/scene/HudRuntime.d.ts +131 -0
- package/dist/scene/HudRuntime.js +1224 -0
- package/dist/scene/Prefabs.d.ts +92 -0
- package/dist/scene/Prefabs.js +175 -0
- package/dist/scene/Rules.d.ts +73 -0
- package/dist/scene/Rules.js +164 -0
- package/dist/scene/SceneLoader.d.ts +118 -0
- package/dist/scene/SceneLoader.js +615 -0
- package/dist/scene/Waves.d.ts +85 -0
- package/dist/scene/Waves.js +365 -0
- package/dist/scene/autotile.d.ts +103 -0
- package/dist/scene/autotile.js +321 -0
- package/dist/scene/renderScripts.d.ts +53 -0
- package/dist/scene/renderScripts.js +67 -0
- package/dist/scene/spawnEntity.d.ts +201 -0
- package/dist/scene/spawnEntity.js +1326 -0
- package/dist/scene/types.d.ts +1166 -0
- package/dist/scene/types.js +34 -0
- package/dist/screenshot/ScreenshotManager.d.ts +14 -0
- package/dist/screenshot/ScreenshotManager.js +33 -0
- package/package.json +35 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Game config — top-level game settings as data.
|
|
3
|
+
*
|
|
4
|
+
* Slice 11 (Phase B.3, 2026-05-12). `public/game.json` carries the
|
|
5
|
+
* orientation / dimensions / physics defaults / controls hints that
|
|
6
|
+
* today live as TS `const` exports in `src/config.ts`. Extracting them
|
|
7
|
+
* to data lets the visual editor's eventual "Game settings" panel
|
|
8
|
+
* (Phase B.5) tweak canvas size, gravity, controls without code edits.
|
|
9
|
+
*
|
|
10
|
+
* Design: umicat-design/features/visual-editor/11-game-data-foundation.md §3
|
|
11
|
+
*
|
|
12
|
+
* Public API:
|
|
13
|
+
* - `loadGameConfig(path?)` — async fetch of `public/game.json`.
|
|
14
|
+
* Resolves to `GameConfig` on success, `null` on missing file
|
|
15
|
+
* (callers fall back to in-code defaults).
|
|
16
|
+
*
|
|
17
|
+
* Pattern in `main.ts`:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createUmicatGame, loadGameConfig } from '@umicat/phaser-sdk';
|
|
21
|
+
*
|
|
22
|
+
* const cfg = await loadGameConfig();
|
|
23
|
+
* createUmicatGame({
|
|
24
|
+
* orientation: cfg?.orientation ?? 'portrait',
|
|
25
|
+
* pixelArt: cfg?.pixelArt ?? false,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* `main.ts` needs top-level await (Vite's default target supports it).
|
|
30
|
+
*/
|
|
31
|
+
import { Orientation } from '../orientation.js';
|
|
32
|
+
export interface GameConfig {
|
|
33
|
+
orientation?: Orientation;
|
|
34
|
+
/** Explicit canvas width — only when not using `orientation`. */
|
|
35
|
+
width?: number;
|
|
36
|
+
/** Explicit canvas height — only when not using `orientation`. */
|
|
37
|
+
height?: number;
|
|
38
|
+
/** Renders pixel-art at integer scale — matches `createUmicatGame.pixelArt`. */
|
|
39
|
+
pixelArt?: boolean;
|
|
40
|
+
/** Physics defaults applied to Arcade physics if no explicit physics options. */
|
|
41
|
+
physics?: {
|
|
42
|
+
gravity?: {
|
|
43
|
+
x?: number;
|
|
44
|
+
y?: number;
|
|
45
|
+
};
|
|
46
|
+
debug?: boolean;
|
|
47
|
+
};
|
|
48
|
+
/** Free-form controls hint surfaced to the user / editor. */
|
|
49
|
+
controls?: {
|
|
50
|
+
primary?: string;
|
|
51
|
+
fire?: string;
|
|
52
|
+
[key: string]: string | undefined;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Fetch the game config JSON from `public/game.json` (or a custom path).
|
|
57
|
+
* Resolves to `null` on 404 / parse error so callers can fall back to
|
|
58
|
+
* in-code defaults cleanly.
|
|
59
|
+
*/
|
|
60
|
+
export declare function loadGameConfig(path?: string): Promise<GameConfig | null>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Game config — top-level game settings as data.
|
|
3
|
+
*
|
|
4
|
+
* Slice 11 (Phase B.3, 2026-05-12). `public/game.json` carries the
|
|
5
|
+
* orientation / dimensions / physics defaults / controls hints that
|
|
6
|
+
* today live as TS `const` exports in `src/config.ts`. Extracting them
|
|
7
|
+
* to data lets the visual editor's eventual "Game settings" panel
|
|
8
|
+
* (Phase B.5) tweak canvas size, gravity, controls without code edits.
|
|
9
|
+
*
|
|
10
|
+
* Design: umicat-design/features/visual-editor/11-game-data-foundation.md §3
|
|
11
|
+
*
|
|
12
|
+
* Public API:
|
|
13
|
+
* - `loadGameConfig(path?)` — async fetch of `public/game.json`.
|
|
14
|
+
* Resolves to `GameConfig` on success, `null` on missing file
|
|
15
|
+
* (callers fall back to in-code defaults).
|
|
16
|
+
*
|
|
17
|
+
* Pattern in `main.ts`:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createUmicatGame, loadGameConfig } from '@umicat/phaser-sdk';
|
|
21
|
+
*
|
|
22
|
+
* const cfg = await loadGameConfig();
|
|
23
|
+
* createUmicatGame({
|
|
24
|
+
* orientation: cfg?.orientation ?? 'portrait',
|
|
25
|
+
* pixelArt: cfg?.pixelArt ?? false,
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* `main.ts` needs top-level await (Vite's default target supports it).
|
|
30
|
+
*/
|
|
31
|
+
const DEFAULT_PATH = 'game.json';
|
|
32
|
+
/**
|
|
33
|
+
* Fetch the game config JSON from `public/game.json` (or a custom path).
|
|
34
|
+
* Resolves to `null` on 404 / parse error so callers can fall back to
|
|
35
|
+
* in-code defaults cleanly.
|
|
36
|
+
*/
|
|
37
|
+
export async function loadGameConfig(path = DEFAULT_PATH) {
|
|
38
|
+
try {
|
|
39
|
+
// Resolve relative to the page's base URL — same logic Phaser's loader uses.
|
|
40
|
+
// No leading slash so the iframe under `/preview/<id>/` works.
|
|
41
|
+
const url = path;
|
|
42
|
+
const res = await fetch(url);
|
|
43
|
+
if (!res.ok)
|
|
44
|
+
return null;
|
|
45
|
+
return (await res.json());
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
* `UmicatHudScene` 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
|
+
* - HUD text widgets reference the registry key via `source.binding` (flat,
|
|
16
|
+
* at the widget root — SDK 0.3.0).
|
|
17
|
+
*/
|
|
18
|
+
export declare const UMICAT_HUD_SCENE_KEY = "UmicatHud";
|
|
19
|
+
interface HudSceneInit {
|
|
20
|
+
/** HUD id from manifest.huds[]. */
|
|
21
|
+
hudId?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a HUD anchor + offset against the current canvas size to a
|
|
25
|
+
* concrete pixel position. Called per widget on (a) initial spawn and (b)
|
|
26
|
+
* scale resize so widgets re-anchor when the viewport changes.
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveAnchor(scene: Phaser.Scene, anchor: Anchor, safeArea?: {
|
|
29
|
+
top: number;
|
|
30
|
+
right: number;
|
|
31
|
+
bottom: number;
|
|
32
|
+
left: number;
|
|
33
|
+
}): {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
};
|
|
37
|
+
interface SpawnContext {
|
|
38
|
+
scene: Phaser.Scene;
|
|
39
|
+
registry: EntityRegistry;
|
|
40
|
+
safeArea: {
|
|
41
|
+
top: number;
|
|
42
|
+
right: number;
|
|
43
|
+
bottom: number;
|
|
44
|
+
left: number;
|
|
45
|
+
};
|
|
46
|
+
resolveAsset: (id: string) => AssetRecord;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Spawn a HUD widget into the scene. The returned GameObject is recorded in
|
|
50
|
+
* the entity registry so the editor + behavior code can find it by id.
|
|
51
|
+
*/
|
|
52
|
+
export declare function spawnHudEntity(ctx: SpawnContext, entity: HudEntity): Phaser.GameObjects.GameObject;
|
|
53
|
+
/**
|
|
54
|
+
* Walk a HudScene's entities and queue Phaser loads for any image / icon
|
|
55
|
+
* assets it references. Idempotent — relies on `manifestState.requestedAssetIds`
|
|
56
|
+
* if SceneLoader's preload helpers have already touched this scene.
|
|
57
|
+
*/
|
|
58
|
+
export declare function preloadHudAssets(scene: Phaser.Scene, hudScene: HudScene, manifest: Manifest): void;
|
|
59
|
+
/**
|
|
60
|
+
* Load and spawn a HUD scene into the given Phaser scene. Symmetric to
|
|
61
|
+
* `loadWorldScene`. Returns the parsed scene file + entity registry.
|
|
62
|
+
*
|
|
63
|
+
* Pattern (in `UmicatHudScene.create`):
|
|
64
|
+
* const result = await loadHudScene(this, hudId);
|
|
65
|
+
* // widgets live; agent's behavior code can subscribe to events via
|
|
66
|
+
* // `this.events.on('hud:press', id => ...)`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function loadHudScene(scene: Phaser.Scene, hudId: string): Promise<{
|
|
69
|
+
hudScene: HudScene;
|
|
70
|
+
registry: EntityRegistry;
|
|
71
|
+
}>;
|
|
72
|
+
/** Find the HUD scene's entity registry, if a HUD scene is currently active. */
|
|
73
|
+
export declare function findHudRegistry(game: Phaser.Game): EntityRegistry | undefined;
|
|
74
|
+
/** Find the HUD scene file from the JSON cache, if loaded. */
|
|
75
|
+
export declare function findHudSceneFile(game: Phaser.Game): HudScene | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Look up a HUD entity record from the cached scene file. Used by the bridge
|
|
78
|
+
* during drag (to read anchor side / current offset) and applyEdit (to
|
|
79
|
+
* resolve the new anchor when side changes).
|
|
80
|
+
*/
|
|
81
|
+
export declare function findHudEntity(game: Phaser.Game, entityId: string): HudEntity | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Compute the canvas-pixel base position for an entity's anchor side
|
|
84
|
+
* (without offset). Used on drag-end to derive the new offset from the
|
|
85
|
+
* GameObject's final position.
|
|
86
|
+
*/
|
|
87
|
+
export declare function getHudAnchorBase(game: Phaser.Game, entity: HudEntity): {
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Apply an editor patch to a live HUD widget. Mirrors the spawn function's
|
|
93
|
+
* logic but operates on the existing GameObject — anchor changes
|
|
94
|
+
* re-resolve position; text source changes rewire the registry subscription;
|
|
95
|
+
* visual style changes setText / setColor / etc. directly.
|
|
96
|
+
*
|
|
97
|
+
* Returns true if a known field was patched, false if nothing applied.
|
|
98
|
+
*/
|
|
99
|
+
export declare function applyHudPatch(game: Phaser.Game, entityId: string, patch: {
|
|
100
|
+
anchor?: {
|
|
101
|
+
side?: string;
|
|
102
|
+
offsetX?: number;
|
|
103
|
+
offsetY?: number;
|
|
104
|
+
};
|
|
105
|
+
layer?: string;
|
|
106
|
+
z?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Flat render-field patch (SDK 0.3.0). Field names match the HUD entity
|
|
109
|
+
* root: `source` / `fontFamily` / `color` / `assetId` / `width` / `tint` /
|
|
110
|
+
* `label` / `fillColor` / `backgroundAssetId` / etc.
|
|
111
|
+
*/
|
|
112
|
+
fields?: Record<string, unknown>;
|
|
113
|
+
role?: string | null;
|
|
114
|
+
properties?: Record<string, unknown>;
|
|
115
|
+
}): boolean;
|
|
116
|
+
/** Spawn a fresh HUD entity into the active HUD scene. Used by editor's create-entity path. */
|
|
117
|
+
export declare function createHudEntityInScene(game: Phaser.Game, entity: HudEntity): boolean;
|
|
118
|
+
/** Destroy a HUD entity. */
|
|
119
|
+
export declare function deleteHudEntityFromScene(game: Phaser.Game, entityId: string): boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Per-game HUD scene. Auto-launched by `createUmicatGame` when the world
|
|
122
|
+
* scene's manifest entry sets `hud: '<id>'`. Renders above the world via
|
|
123
|
+
* Phaser's scene rendering order; takes input independently.
|
|
124
|
+
*/
|
|
125
|
+
export declare class UmicatHudScene extends Phaser.Scene {
|
|
126
|
+
private hudId;
|
|
127
|
+
constructor();
|
|
128
|
+
init(data: HudSceneInit): void;
|
|
129
|
+
create(): Promise<void>;
|
|
130
|
+
}
|
|
131
|
+
export {};
|