@unboxy/phaser-sdk 0.2.15 → 0.2.16
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 +15 -2
- package/dist/core/UnboxyGame.d.ts +18 -5
- package/dist/core/UnboxyGame.js +6 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/orientation.d.ts +5 -0
- package/dist/orientation.js +4 -0
- package/package.json +1 -1
package/SDK-GUIDE.md
CHANGED
|
@@ -15,16 +15,28 @@ Reference for AI agents building games on the Unboxy platform. Tracks the **inst
|
|
|
15
15
|
|
|
16
16
|
| field | type | note |
|
|
17
17
|
|-------|------|------|
|
|
18
|
-
| `
|
|
19
|
-
| `
|
|
18
|
+
| `orientation` | `'portrait' \| 'landscape'` | mutually exclusive with `width`/`height`. Resolves to preset dims from `ORIENTATION_DIMENSIONS`. **Since 0.2.16.** |
|
|
19
|
+
| `width` | `number` | required if `orientation` is omitted |
|
|
20
|
+
| `height` | `number` | required if `orientation` is omitted |
|
|
20
21
|
| `scenes` | `Phaser.Scene class[]` | required |
|
|
21
22
|
| `backgroundColor` | `string` | defaults to `'#1a1a2e'` |
|
|
22
23
|
| `pixelArt` | `boolean` | defaults to `false` |
|
|
23
24
|
| `physics` | `Phaser.Types.Core.PhysicsConfig` | defaults to arcade physics, no gravity |
|
|
24
25
|
| `plugins` | `Phaser.Types.Core.PluginObject` | forwarded as-is into the Phaser `GameConfig`. **Since 0.2.9.** Earlier versions silently dropped this field. |
|
|
25
26
|
|
|
27
|
+
`orientation` and explicit `width`/`height` are a TypeScript union — pass one or the other, not both. The compiler rejects mixed usage.
|
|
28
|
+
|
|
26
29
|
Any field not listed is ignored. If you need something else (e.g. `callbacks`, custom `render` options), use plain `new Phaser.Game(config)` instead of `createUnboxyGame`.
|
|
27
30
|
|
|
31
|
+
### Orientation presets
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { ORIENTATION_DIMENSIONS } from '@unboxy/phaser-sdk';
|
|
35
|
+
// { landscape: { width: 1280, height: 720 }, portrait: { width: 720, height: 1280 } }
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The orientation a game uses is decided **once at game creation** and baked into the template's `src/config.ts`. There is no runtime API to flip orientation — switching mid-development would invalidate every screen layout.
|
|
39
|
+
|
|
28
40
|
### Registering third-party Phaser plugins (e.g. rexUI)
|
|
29
41
|
|
|
30
42
|
Pass them via the `plugins` option — do NOT try to register them inside a scene's `preload`:
|
|
@@ -544,6 +556,7 @@ Don't blindly apply interpolation to everything. It's wrong for a chess piece an
|
|
|
544
556
|
|
|
545
557
|
## Changelog
|
|
546
558
|
|
|
559
|
+
- **0.2.16** — added orientation presets. `createUnboxyGame` now accepts an `orientation: 'portrait' | 'landscape'` option as an alternative to explicit `width`/`height` (TS union — pass one or the other). New exports: `Orientation` type and `ORIENTATION_DIMENSIONS` map (`landscape: 1280×720`, `portrait: 720×1280`). Lets games declare orientation once and have a single source of truth for canvas dimensions.
|
|
547
560
|
- **0.2.15** — fix: `ChatFacade.subscribeToPlayers` early-returned when `state.players` was `undefined` at construction time, which it always is on a fresh `joinOrCreate` (Colyseus delivers initial state as a separate message a few ms later). The early return meant `onStateChange` never subscribed and `system.joined` / `system.left` stayed silent in production despite the 0.2.14 callback-API fix. Now: always subscribe; treat the first state change as initial hydration (silent), subsequent changes do real diff. Three regression tests cover the deferred-hydration flow.
|
|
548
561
|
- **0.2.14** — fix: `ChatFacade` `system.joined` / `system.left` events were silently no-op'ing in production. The lifecycle subscription used `state.players.onAdd` / `.onRemove` instance methods that Colyseus 0.16 removed in favour of `getStateCallbacks(room)`; the runtime check `typeof players.onAdd === 'function'` evaluated false, so neither system message fired. Now uses `room.onStateChange` + a known-names diff — robust to future Colyseus API changes. Tests updated to match. Patch-only; no API change for game code.
|
|
549
562
|
- **0.2.13** — added `room.chat` helper for in-game chat. New API: `room.chat.send(text)` (returns `Promise<void>`) + `room.chat.onMessage(handler)`, plus exports `ChatMessage`, `ChatMessageKind`, and `MAX_CHAT_TEXT_LEN`. Wraps the existing `'chat'` wildcard relay with local echo (sender sees own message synchronously), stamped `displayName` on every payload, trim + 500-char silent truncate, and auto-emitted `kind: 'system.joined'` / `'system.left'` messages computed locally from `room.state.players` add/remove events (no wire traffic). Replaces the raw `room.send('chat', text)` pattern in the Multiplayer chapter — raw still works but loses local echo, length cap, and join/leave events.
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import Phaser from 'phaser';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
width: number;
|
|
5
|
-
/** Game height in pixels */
|
|
6
|
-
height: number;
|
|
2
|
+
import { type Orientation } from '../orientation.js';
|
|
3
|
+
interface UnboxyGameBaseOptions {
|
|
7
4
|
/** Phaser scene classes to register */
|
|
8
5
|
scenes: (new (...args: any[]) => Phaser.Scene)[];
|
|
9
6
|
/** Background color (default: '#1a1a2e') */
|
|
@@ -15,8 +12,24 @@ export interface UnboxyGameOptions {
|
|
|
15
12
|
/** Phaser plugin registrations (e.g. `phaser3-rex-plugins` virtual joystick) */
|
|
16
13
|
plugins?: Phaser.Types.Core.PluginObject;
|
|
17
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Either pass `orientation` (preset dims from ORIENTATION_DIMENSIONS) OR
|
|
17
|
+
* explicit `width`/`height` — not both. The TS union enforces this at
|
|
18
|
+
* compile time so games can't drift out of the orientation presets by
|
|
19
|
+
* accident.
|
|
20
|
+
*/
|
|
21
|
+
export type UnboxyGameOptions = (UnboxyGameBaseOptions & {
|
|
22
|
+
orientation: Orientation;
|
|
23
|
+
width?: never;
|
|
24
|
+
height?: never;
|
|
25
|
+
}) | (UnboxyGameBaseOptions & {
|
|
26
|
+
width: number;
|
|
27
|
+
height: number;
|
|
28
|
+
orientation?: never;
|
|
29
|
+
});
|
|
18
30
|
/**
|
|
19
31
|
* Create an Unboxy-enhanced Phaser game instance.
|
|
20
32
|
* Includes built-in integrations: screenshot capture, preserveDrawingBuffer, etc.
|
|
21
33
|
*/
|
|
22
34
|
export declare function createUnboxyGame(options: UnboxyGameOptions): Phaser.Game;
|
|
35
|
+
export {};
|
package/dist/core/UnboxyGame.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import Phaser from 'phaser';
|
|
2
2
|
import { setupScreenshotListener } from '../screenshot/ScreenshotManager.js';
|
|
3
3
|
import { setupRecordingListener } from '../recording/RecordingManager.js';
|
|
4
|
+
import { ORIENTATION_DIMENSIONS } from '../orientation.js';
|
|
4
5
|
/**
|
|
5
6
|
* Create an Unboxy-enhanced Phaser game instance.
|
|
6
7
|
* Includes built-in integrations: screenshot capture, preserveDrawingBuffer, etc.
|
|
7
8
|
*/
|
|
8
9
|
export function createUnboxyGame(options) {
|
|
10
|
+
const { width, height } = 'orientation' in options && options.orientation
|
|
11
|
+
? ORIENTATION_DIMENSIONS[options.orientation]
|
|
12
|
+
: { width: options.width, height: options.height };
|
|
9
13
|
const config = {
|
|
10
14
|
type: Phaser.AUTO,
|
|
11
15
|
backgroundColor: options.backgroundColor ?? '#1a1a2e',
|
|
12
16
|
scale: {
|
|
13
17
|
mode: Phaser.Scale.FIT,
|
|
14
18
|
autoCenter: Phaser.Scale.CENTER_BOTH,
|
|
15
|
-
width
|
|
16
|
-
height
|
|
19
|
+
width,
|
|
20
|
+
height,
|
|
17
21
|
},
|
|
18
22
|
render: {
|
|
19
23
|
preserveDrawingBuffer: true,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { createUnboxyGame } from './core/UnboxyGame.js';
|
|
2
2
|
export type { UnboxyGameOptions } from './core/UnboxyGame.js';
|
|
3
3
|
export { UnboxyScene } from './core/UnboxyScene.js';
|
|
4
|
+
export { ORIENTATION_DIMENSIONS } from './orientation.js';
|
|
5
|
+
export type { Orientation } from './orientation.js';
|
|
4
6
|
export { setupScreenshotListener, takeScreenshot } from './screenshot/ScreenshotManager.js';
|
|
5
7
|
export { setupRecordingListener } from './recording/RecordingManager.js';
|
|
6
8
|
export { Unboxy } from './core/Unboxy.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Core
|
|
2
2
|
export { createUnboxyGame } from './core/UnboxyGame.js';
|
|
3
3
|
export { UnboxyScene } from './core/UnboxyScene.js';
|
|
4
|
+
export { ORIENTATION_DIMENSIONS } from './orientation.js';
|
|
4
5
|
// Screenshot
|
|
5
6
|
export { setupScreenshotListener, takeScreenshot } from './screenshot/ScreenshotManager.js';
|
|
6
7
|
// Recording
|