@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.
Files changed (62) hide show
  1. package/SDK-GUIDE.md +1726 -0
  2. package/dist/core/Transport.d.ts +28 -0
  3. package/dist/core/Transport.js +7 -0
  4. package/dist/core/Umicat.d.ts +45 -0
  5. package/dist/core/Umicat.js +60 -0
  6. package/dist/core/UmicatGame.d.ts +43 -0
  7. package/dist/core/UmicatGame.js +64 -0
  8. package/dist/core/UmicatScene.d.ts +19 -0
  9. package/dist/core/UmicatScene.js +38 -0
  10. package/dist/core/transports/LocalStorageTransport.d.ts +22 -0
  11. package/dist/core/transports/LocalStorageTransport.js +78 -0
  12. package/dist/core/transports/PostMessageTransport.d.ts +28 -0
  13. package/dist/core/transports/PostMessageTransport.js +105 -0
  14. package/dist/editor/EditorBridge.d.ts +114 -0
  15. package/dist/editor/EditorBridge.js +2608 -0
  16. package/dist/editor/EditorOverlayScene.d.ts +333 -0
  17. package/dist/editor/EditorOverlayScene.js +1896 -0
  18. package/dist/editor/EditorState.d.ts +251 -0
  19. package/dist/editor/EditorState.js +197 -0
  20. package/dist/gamedata/GameDataModule.d.ts +45 -0
  21. package/dist/gamedata/GameDataModule.js +59 -0
  22. package/dist/index.d.ts +43 -0
  23. package/dist/index.js +43 -0
  24. package/dist/orientation.d.ts +5 -0
  25. package/dist/orientation.js +4 -0
  26. package/dist/protocol.d.ts +807 -0
  27. package/dist/protocol.js +3 -0
  28. package/dist/realtime/RealtimeModule.d.ts +93 -0
  29. package/dist/realtime/RealtimeModule.js +115 -0
  30. package/dist/realtime/UmicatRoom.d.ts +197 -0
  31. package/dist/realtime/UmicatRoom.js +353 -0
  32. package/dist/recording/RecordingManager.d.ts +11 -0
  33. package/dist/recording/RecordingManager.js +59 -0
  34. package/dist/saves/SavesModule.d.ts +23 -0
  35. package/dist/saves/SavesModule.js +37 -0
  36. package/dist/scene/EditorMode.d.ts +17 -0
  37. package/dist/scene/EditorMode.js +22 -0
  38. package/dist/scene/EntityRegistry.d.ts +39 -0
  39. package/dist/scene/EntityRegistry.js +103 -0
  40. package/dist/scene/GameConfig.d.ts +60 -0
  41. package/dist/scene/GameConfig.js +50 -0
  42. package/dist/scene/HudRuntime.d.ts +131 -0
  43. package/dist/scene/HudRuntime.js +1224 -0
  44. package/dist/scene/Prefabs.d.ts +92 -0
  45. package/dist/scene/Prefabs.js +175 -0
  46. package/dist/scene/Rules.d.ts +73 -0
  47. package/dist/scene/Rules.js +164 -0
  48. package/dist/scene/SceneLoader.d.ts +118 -0
  49. package/dist/scene/SceneLoader.js +615 -0
  50. package/dist/scene/Waves.d.ts +85 -0
  51. package/dist/scene/Waves.js +365 -0
  52. package/dist/scene/autotile.d.ts +103 -0
  53. package/dist/scene/autotile.js +321 -0
  54. package/dist/scene/renderScripts.d.ts +53 -0
  55. package/dist/scene/renderScripts.js +67 -0
  56. package/dist/scene/spawnEntity.d.ts +201 -0
  57. package/dist/scene/spawnEntity.js +1326 -0
  58. package/dist/scene/types.d.ts +1166 -0
  59. package/dist/scene/types.js +34 -0
  60. package/dist/screenshot/ScreenshotManager.d.ts +14 -0
  61. package/dist/screenshot/ScreenshotManager.js +33 -0
  62. package/package.json +35 -0
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Scene-as-data types — visual editor foundation (slice 1).
3
+ *
4
+ * Spec: umicat-design/features/visual-editor/01-scene-data-foundation.md
5
+ *
6
+ * v1 schema (`schemaVersion: 1`) supports the entity kinds needed for the
7
+ * read-only scene viewer. HUD entity kinds, tilemap, trigger, and
8
+ * code-rendered visuals will land in later slices.
9
+ */
10
+ export const SCHEMA_VERSION = 1;
11
+ /**
12
+ * Type guard — true when `ninePatch` is the per-frame variant. Lets call
13
+ * sites that only need to handle one shape stay narrow.
14
+ */
15
+ export function isPerFrameNinePatch(np) {
16
+ return !!np && 'perFrame' in np;
17
+ }
18
+ /**
19
+ * Type guard — true when `hitbox` is the per-frame variant. Used by SDK
20
+ * runtime to decide whether to install an `ANIMATION_UPDATE` listener that
21
+ * swaps body shape per frame.
22
+ *
23
+ * <p>Checks `default != null` (handles both `null` and `undefined`) rather
24
+ * than `'default' in h`. The backend stores hitboxes after a mode switch
25
+ * with EXPLICIT NULLS on the alternate shape's fields — `{ kind: 'rect',
26
+ * x, y, w, h, default: null, frames: null }` for Single mode — because
27
+ * OpenSearch's _update API deep-merges nested objects and would otherwise
28
+ * leave stale fields. `'default' in h` would return true on that shape and
29
+ * trip the per-frame path with a null default. The null check is the
30
+ * correct discriminator.
31
+ */
32
+ export function isPerFrameHitbox(h) {
33
+ return !!h && h.default != null;
34
+ }
@@ -0,0 +1,14 @@
1
+ import Phaser from 'phaser';
2
+ /**
3
+ * Sets up a postMessage listener that captures the game canvas
4
+ * when the parent window requests a screenshot.
5
+ *
6
+ * Parent sends: { type: 'screenshot' }
7
+ * Game responds: { type: 'screenshot_result', dataUrl: string }
8
+ */
9
+ export declare function setupScreenshotListener(game: Phaser.Game): void;
10
+ /**
11
+ * Take a screenshot programmatically (e.g., from within a scene).
12
+ * Returns a base64 data URL of the current canvas.
13
+ */
14
+ export declare function takeScreenshot(game: Phaser.Game): string | null;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Sets up a postMessage listener that captures the game canvas
3
+ * when the parent window requests a screenshot.
4
+ *
5
+ * Parent sends: { type: 'screenshot' }
6
+ * Game responds: { type: 'screenshot_result', dataUrl: string }
7
+ */
8
+ export function setupScreenshotListener(game) {
9
+ window.addEventListener('message', (event) => {
10
+ if (event.data?.type === 'screenshot') {
11
+ try {
12
+ const dataUrl = game.canvas.toDataURL('image/png');
13
+ window.parent.postMessage({ type: 'screenshot_result', dataUrl }, '*');
14
+ }
15
+ catch (e) {
16
+ console.error('[UmicatSDK] Screenshot failed:', e);
17
+ }
18
+ }
19
+ });
20
+ }
21
+ /**
22
+ * Take a screenshot programmatically (e.g., from within a scene).
23
+ * Returns a base64 data URL of the current canvas.
24
+ */
25
+ export function takeScreenshot(game) {
26
+ try {
27
+ return game.canvas.toDataURL('image/png');
28
+ }
29
+ catch (e) {
30
+ console.error('[UmicatSDK] Screenshot failed:', e);
31
+ return null;
32
+ }
33
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@umicat/phaser-sdk",
3
+ "version": "1.0.0",
4
+ "description": "Umicat Phaser 3 SDK — game infrastructure for the Umicat platform",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "SDK-GUIDE.md"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "test": "npm run build && node --test scripts/test-chat-facade.mjs",
14
+ "prepublishOnly": "npm run build && [ \"$UMICAT_PUBLISH_VIA_SCRIPT\" = \"1\" ] || (echo '\\nERROR: do not run `npm publish` directly. Use ./publish.sh instead — it gates on the template-sync checklist.\\nSee CLAUDE.md \"Template sync — do not skip\".\\n' >&2 && exit 1)",
15
+ "release": "./publish.sh"
16
+ },
17
+ "dependencies": {
18
+ "colyseus.js": "^0.16.0"
19
+ },
20
+ "peerDependencies": {
21
+ "phaser": "^3.60.0",
22
+ "phaser3-rex-plugins": "^1.80.0"
23
+ },
24
+ "devDependencies": {
25
+ "jose": "^6.2.2",
26
+ "phaser": "^3.80.0",
27
+ "phaser3-rex-plugins": "^1.80.20",
28
+ "typescript": "^5.5.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "license": "UNLICENSED",
34
+ "private": false
35
+ }