@unboxy/phaser-sdk 0.2.19 → 0.2.20
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.
|
@@ -43,6 +43,12 @@ interface EditorOverlayInitData {
|
|
|
43
43
|
x: number;
|
|
44
44
|
y: number;
|
|
45
45
|
}) => void;
|
|
46
|
+
/**
|
|
47
|
+
* Forward an editor keyboard shortcut to the host. Set when the iframe has
|
|
48
|
+
* focus (which is always after the user clicks the canvas to select);
|
|
49
|
+
* native Cmd+Z otherwise can't reach the host.
|
|
50
|
+
*/
|
|
51
|
+
postShortcut: (action: 'undo' | 'redo' | 'save') => void;
|
|
46
52
|
}
|
|
47
53
|
export declare class EditorOverlayScene extends Phaser.Scene {
|
|
48
54
|
private graphics;
|
|
@@ -50,9 +56,11 @@ export declare class EditorOverlayScene extends Phaser.Scene {
|
|
|
50
56
|
private hitTest;
|
|
51
57
|
private postPick;
|
|
52
58
|
private postDragEnd;
|
|
59
|
+
private postShortcut;
|
|
53
60
|
constructor();
|
|
54
61
|
init(data: EditorOverlayInitData): void;
|
|
55
62
|
create(): void;
|
|
63
|
+
private handleShortcut;
|
|
56
64
|
private handlePointerDown;
|
|
57
65
|
private handlePointerMove;
|
|
58
66
|
private handlePointerUp;
|
|
@@ -26,12 +26,40 @@ const WORLD_BOUNDS_ALPHA = 0.5;
|
|
|
26
26
|
export class EditorOverlayScene extends Phaser.Scene {
|
|
27
27
|
constructor() {
|
|
28
28
|
super({ key: EDITOR_OVERLAY_KEY });
|
|
29
|
+
this.handleShortcut = (e) => {
|
|
30
|
+
if (!(e.metaKey || e.ctrlKey))
|
|
31
|
+
return;
|
|
32
|
+
// Don't swallow keys when the user is typing in a real form control —
|
|
33
|
+
// shouldn't happen inside the iframe, but be defensive.
|
|
34
|
+
const target = e.target;
|
|
35
|
+
if (target) {
|
|
36
|
+
const tag = target.tagName;
|
|
37
|
+
if (tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT')
|
|
38
|
+
return;
|
|
39
|
+
if (target.isContentEditable)
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const k = e.key.toLowerCase();
|
|
43
|
+
if (k === 'z') {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
this.postShortcut(e.shiftKey ? 'redo' : 'undo');
|
|
46
|
+
}
|
|
47
|
+
else if (k === 'y') {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
this.postShortcut('redo');
|
|
50
|
+
}
|
|
51
|
+
else if (k === 's') {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
this.postShortcut('save');
|
|
54
|
+
}
|
|
55
|
+
};
|
|
29
56
|
}
|
|
30
57
|
init(data) {
|
|
31
58
|
this.worldBounds = data.worldBounds;
|
|
32
59
|
this.hitTest = data.hitTest;
|
|
33
60
|
this.postPick = data.postPick;
|
|
34
61
|
this.postDragEnd = data.postDragEnd;
|
|
62
|
+
this.postShortcut = data.postShortcut;
|
|
35
63
|
}
|
|
36
64
|
create() {
|
|
37
65
|
this.graphics = this.add.graphics();
|
|
@@ -45,6 +73,19 @@ export class EditorOverlayScene extends Phaser.Scene {
|
|
|
45
73
|
this.input.on('pointerdown', this.handlePointerDown, this);
|
|
46
74
|
this.input.on('pointermove', this.handlePointerMove, this);
|
|
47
75
|
this.input.on('pointerup', this.handlePointerUp, this);
|
|
76
|
+
// Forward editor shortcuts back to the host. The user clicks the canvas
|
|
77
|
+
// to select an entity, which moves focus into the iframe — after that,
|
|
78
|
+
// native Cmd+Z lands here, not on the host's window. We catch it before
|
|
79
|
+
// Phaser's keyboard plugin gets it (DOM phase is fine because Phaser
|
|
80
|
+
// listens via its own KeyboardManager), preventDefault'ing browser
|
|
81
|
+
// back-nav-on-Cmd+Left etc. is unnecessary; we only intercept the few
|
|
82
|
+
// editor keys we care about.
|
|
83
|
+
if (typeof document !== 'undefined') {
|
|
84
|
+
document.addEventListener('keydown', this.handleShortcut, true);
|
|
85
|
+
this.events.once(Phaser.Scenes.Events.SHUTDOWN, () => {
|
|
86
|
+
document.removeEventListener('keydown', this.handleShortcut, true);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
48
89
|
}
|
|
49
90
|
handlePointerDown(pointer) {
|
|
50
91
|
const state = getEditorState(this.game);
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export { EntityRegistry, attachEntityRegistry, getEntityRegistry, } from './scen
|
|
|
24
24
|
export { setupEditorModeListener, isEditMode } from './scene/EditorMode.js';
|
|
25
25
|
export { setupEditorBridge } from './editor/EditorBridge.js';
|
|
26
26
|
export { EditorOverlayScene, EDITOR_OVERLAY_KEY } from './editor/EditorOverlayScene.js';
|
|
27
|
-
export type { EditorEntityPatch, EditorEnterMessage, EditorExitMessage, EditorGetSceneMessage, EditorApplyEditMessage, EditorSetSelectionMessage, EditorPanZoomMessage, EditorHostToSdkMessage, EditorSceneLoadedMessage, EditorSelectionPickedMessage, EditorDragEndMessage, EditorSdkToHostMessage, } from './protocol.js';
|
|
27
|
+
export type { EditorEntityPatch, EditorEnterMessage, EditorExitMessage, EditorGetSceneMessage, EditorApplyEditMessage, EditorSetSelectionMessage, EditorPanZoomMessage, EditorHostToSdkMessage, EditorSceneLoadedMessage, EditorSelectionPickedMessage, EditorDragEndMessage, EditorShortcutMessage, EditorSdkToHostMessage, } from './protocol.js';
|
|
28
28
|
export { SCHEMA_VERSION, } from './scene/types.js';
|
|
29
29
|
export type { Manifest, SceneRef, HudRef, AssetRecord, AssetKind, SceneType, SceneFile, WorldScene, HudScene, WorldSceneConfig, CameraConfig, WorldEntity, WorldEntityKind, NonGroupWorldEntity, SpriteEntity, PrimitiveEntity, CodeRenderedEntity, GroupEntity, TilemapEntity, TriggerEntity, WorldVisual, SpriteVisual, PrimitiveVisual, PrimitiveRectVisual, PrimitiveCircleVisual, CodeRenderedVisual, Transform, Anchor, AnchorSide, } from './scene/types.js';
|
|
30
30
|
export { PROTOCOL_VERSION, type HelloMessage, type InitMessage, type RpcRequestMessage, type RpcResultOk, type RpcResultError, type HostToSdkMessage, type SdkToHostMessage, type RpcErrorPayload, type RpcMethod, type SavesGetParams, type SavesGetResult, type SavesSetParams, type SavesSetResult, type SavesDeleteParams, type SavesDeleteResult, type SavesListResult, type GameDataGetParams, type GameDataGetResult, type GameDataSetParams, type GameDataSetResult, type GameDataDeleteParams, type GameDataDeleteResult, type GameDataListResult, type RealtimeGetTokenParams, type RealtimeGetTokenResult, } from './protocol.js';
|
package/dist/protocol.d.ts
CHANGED
|
@@ -141,7 +141,16 @@ export interface EditorDragEndMessage {
|
|
|
141
141
|
y: number;
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Editor keyboard shortcut intercepted inside the iframe (user clicked the
|
|
146
|
+
* canvas, so focus is on the iframe and the host window doesn't see the
|
|
147
|
+
* native keydown). The SDK forwards a small allowlist back to the host.
|
|
148
|
+
*/
|
|
149
|
+
export interface EditorShortcutMessage {
|
|
150
|
+
type: 'unboxy:editor:shortcut';
|
|
151
|
+
action: 'undo' | 'redo' | 'save';
|
|
152
|
+
}
|
|
153
|
+
export type EditorSdkToHostMessage = EditorSceneLoadedMessage | EditorSelectionPickedMessage | EditorDragEndMessage | EditorShortcutMessage;
|
|
145
154
|
export type RpcMethod = 'saves.get' | 'saves.set' | 'saves.delete' | 'saves.list' | 'gameData.get' | 'gameData.set' | 'gameData.delete' | 'gameData.list' | 'realtime.getToken';
|
|
146
155
|
export interface SavesGetParams {
|
|
147
156
|
key: string;
|