@rpgjs/map-builder 0.0.0-stage → 5.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/LICENSE +19 -0
- package/README.md +341 -2
- package/dist/authority/authority.d.ts +118 -0
- package/dist/authority/authority.d.ts.map +1 -0
- package/dist/authority/authority.js +289 -0
- package/dist/authority/authority.js.map +1 -0
- package/dist/authority/index.d.ts +3 -0
- package/dist/authority/index.d.ts.map +1 -0
- package/dist/authority/index.js +3 -0
- package/dist/authority/store.d.ts +36 -0
- package/dist/authority/store.d.ts.map +1 -0
- package/dist/authority/store.js +35 -0
- package/dist/authority/store.js.map +1 -0
- package/dist/client/index.d.ts +72 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +200 -0
- package/dist/client/index.js.map +1 -0
- package/dist/embed/client.d.ts +85 -0
- package/dist/embed/client.d.ts.map +1 -0
- package/dist/embed/client.js +255 -0
- package/dist/embed/client.js.map +1 -0
- package/dist/embed/host.d.ts +112 -0
- package/dist/embed/host.d.ts.map +1 -0
- package/dist/embed/host.js +278 -0
- package/dist/embed/host.js.map +1 -0
- package/dist/embed/index.d.ts +4 -0
- package/dist/embed/index.d.ts.map +1 -0
- package/dist/embed/index.js +4 -0
- package/dist/embed/protocol.d.ts +137 -0
- package/dist/embed/protocol.d.ts.map +1 -0
- package/dist/embed/protocol.js +161 -0
- package/dist/embed/protocol.js.map +1 -0
- package/dist/features/index.d.ts +66 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +157 -0
- package/dist/features/index.js.map +1 -0
- package/dist/features/skin.d.ts +9 -0
- package/dist/features/skin.d.ts.map +1 -0
- package/dist/features/skin.js +43 -0
- package/dist/features/skin.js.map +1 -0
- package/dist/features/terrain.d.ts +66 -0
- package/dist/features/terrain.d.ts.map +1 -0
- package/dist/features/terrain.js +291 -0
- package/dist/features/terrain.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/interaction/builtin-intents.d.ts +9 -0
- package/dist/interaction/builtin-intents.d.ts.map +1 -0
- package/dist/interaction/builtin-intents.js +61 -0
- package/dist/interaction/builtin-intents.js.map +1 -0
- package/dist/interaction/catalog.d.ts +24 -0
- package/dist/interaction/catalog.d.ts.map +1 -0
- package/dist/interaction/catalog.js +20 -0
- package/dist/interaction/catalog.js.map +1 -0
- package/dist/interaction/controller.d.ts +137 -0
- package/dist/interaction/controller.d.ts.map +1 -0
- package/dist/interaction/controller.js +215 -0
- package/dist/interaction/controller.js.map +1 -0
- package/dist/interaction/index.d.ts +14 -0
- package/dist/interaction/index.d.ts.map +1 -0
- package/dist/interaction/index.js +13 -0
- package/dist/interaction/input.d.ts +26 -0
- package/dist/interaction/input.d.ts.map +1 -0
- package/dist/interaction/input.js +33 -0
- package/dist/interaction/input.js.map +1 -0
- package/dist/interaction/intents.d.ts +80 -0
- package/dist/interaction/intents.d.ts.map +1 -0
- package/dist/interaction/keyboard.d.ts +26 -0
- package/dist/interaction/keyboard.d.ts.map +1 -0
- package/dist/interaction/keyboard.js +32 -0
- package/dist/interaction/keyboard.js.map +1 -0
- package/dist/interaction/picking.d.ts +33 -0
- package/dist/interaction/picking.d.ts.map +1 -0
- package/dist/interaction/picking.js +35 -0
- package/dist/interaction/picking.js.map +1 -0
- package/dist/interaction/pipeline.d.ts +45 -0
- package/dist/interaction/pipeline.d.ts.map +1 -0
- package/dist/interaction/pipeline.js +26 -0
- package/dist/interaction/pipeline.js.map +1 -0
- package/dist/interaction/placement.d.ts +76 -0
- package/dist/interaction/placement.d.ts.map +1 -0
- package/dist/interaction/placement.js +238 -0
- package/dist/interaction/placement.js.map +1 -0
- package/dist/interaction/selection-tool.d.ts +29 -0
- package/dist/interaction/selection-tool.d.ts.map +1 -0
- package/dist/interaction/selection-tool.js +190 -0
- package/dist/interaction/selection-tool.js.map +1 -0
- package/dist/interaction/steps.d.ts +62 -0
- package/dist/interaction/steps.d.ts.map +1 -0
- package/dist/interaction/steps.js +126 -0
- package/dist/interaction/steps.js.map +1 -0
- package/dist/interaction/store.d.ts +10 -0
- package/dist/interaction/store.d.ts.map +1 -0
- package/dist/interaction/store.js +28 -0
- package/dist/interaction/store.js.map +1 -0
- package/dist/interaction/tools.d.ts +26 -0
- package/dist/interaction/tools.d.ts.map +1 -0
- package/dist/interaction/tools.js +41 -0
- package/dist/interaction/tools.js.map +1 -0
- package/dist/model/assets.d.ts +36 -0
- package/dist/model/assets.d.ts.map +1 -0
- package/dist/model/assets.js +18 -0
- package/dist/model/assets.js.map +1 -0
- package/dist/model/committer.d.ts +66 -0
- package/dist/model/committer.d.ts.map +1 -0
- package/dist/model/committer.js +38 -0
- package/dist/model/committer.js.map +1 -0
- package/dist/model/core-patches.d.ts +2 -0
- package/dist/model/core-patches.d.ts.map +1 -0
- package/dist/model/core-patches.js +193 -0
- package/dist/model/core-patches.js.map +1 -0
- package/dist/model/define-map.d.ts +52 -0
- package/dist/model/define-map.d.ts.map +1 -0
- package/dist/model/define-map.js +66 -0
- package/dist/model/define-map.js.map +1 -0
- package/dist/model/definition.d.ts +57 -0
- package/dist/model/definition.d.ts.map +1 -0
- package/dist/model/definition.js +6 -0
- package/dist/model/definition.js.map +1 -0
- package/dist/model/errors.d.ts +21 -0
- package/dist/model/errors.d.ts.map +1 -0
- package/dist/model/errors.js +14 -0
- package/dist/model/errors.js.map +1 -0
- package/dist/model/history.d.ts +43 -0
- package/dist/model/history.d.ts.map +1 -0
- package/dist/model/history.js +141 -0
- package/dist/model/history.js.map +1 -0
- package/dist/model/index.d.ts +14 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +14 -0
- package/dist/model/json.d.ts +15 -0
- package/dist/model/json.d.ts.map +1 -0
- package/dist/model/json.js +35 -0
- package/dist/model/json.js.map +1 -0
- package/dist/model/model.d.ts +68 -0
- package/dist/model/model.d.ts.map +1 -0
- package/dist/model/model.js +170 -0
- package/dist/model/model.js.map +1 -0
- package/dist/model/parse.d.ts +24 -0
- package/dist/model/parse.d.ts.map +1 -0
- package/dist/model/parse.js +165 -0
- package/dist/model/parse.js.map +1 -0
- package/dist/model/patches.d.ts +100 -0
- package/dist/model/patches.d.ts.map +1 -0
- package/dist/model/patches.js +21 -0
- package/dist/model/patches.js.map +1 -0
- package/dist/model/result.d.ts +22 -0
- package/dist/model/result.d.ts.map +1 -0
- package/dist/model/result.js +10 -0
- package/dist/model/result.js.map +1 -0
- package/dist/model/source.d.ts +52 -0
- package/dist/model/source.d.ts.map +1 -0
- package/dist/model/source.js +75 -0
- package/dist/model/source.js.map +1 -0
- package/dist/protocol/index.d.ts +92 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +106 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/remote/committer.d.ts +43 -0
- package/dist/remote/committer.d.ts.map +1 -0
- package/dist/remote/committer.js +206 -0
- package/dist/remote/committer.js.map +1 -0
- package/dist/remote/index.d.ts +4 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +4 -0
- package/dist/remote/join.d.ts +30 -0
- package/dist/remote/join.d.ts.map +1 -0
- package/dist/remote/join.js +36 -0
- package/dist/remote/join.js.map +1 -0
- package/dist/remote/memory-transport.d.ts +20 -0
- package/dist/remote/memory-transport.d.ts.map +1 -0
- package/dist/remote/memory-transport.js +48 -0
- package/dist/remote/memory-transport.js.map +1 -0
- package/dist/renderer/effects.d.ts +52 -0
- package/dist/renderer/effects.d.ts.map +1 -0
- package/dist/renderer/effects.js +111 -0
- package/dist/renderer/effects.js.map +1 -0
- package/dist/renderer/feature.d.ts +79 -0
- package/dist/renderer/feature.d.ts.map +1 -0
- package/dist/renderer/feature.js +50 -0
- package/dist/renderer/feature.js.map +1 -0
- package/dist/renderer/geometry.d.ts +59 -0
- package/dist/renderer/geometry.d.ts.map +1 -0
- package/dist/renderer/geometry.js +114 -0
- package/dist/renderer/geometry.js.map +1 -0
- package/dist/renderer/index.d.ts +7 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +7 -0
- package/dist/renderer/scene.d.ts +77 -0
- package/dist/renderer/scene.d.ts.map +1 -0
- package/dist/renderer/scene.js +125 -0
- package/dist/renderer/scene.js.map +1 -0
- package/dist/renderer/textures.d.ts +20 -0
- package/dist/renderer/textures.d.ts.map +1 -0
- package/dist/renderer/textures.js +61 -0
- package/dist/renderer/textures.js.map +1 -0
- package/dist/renderer/view.d.ts +139 -0
- package/dist/renderer/view.d.ts.map +1 -0
- package/dist/renderer/view.js +349 -0
- package/dist/renderer/view.js.map +1 -0
- package/dist/rpgjs/shared.d.ts +41 -0
- package/dist/rpgjs/shared.d.ts.map +1 -0
- package/dist/rpgjs/shared.js +77 -0
- package/dist/rpgjs/shared.js.map +1 -0
- package/dist/server/index.d.ts +64 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +205 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/storage.d.ts +16 -0
- package/dist/server/storage.d.ts.map +1 -0
- package/dist/server/storage.js +52 -0
- package/dist/server/storage.js.map +1 -0
- package/dist/skins/default.d.ts +27 -0
- package/dist/skins/default.d.ts.map +1 -0
- package/dist/skins/default.js +144 -0
- package/dist/skins/default.js.map +1 -0
- package/dist/skins/frames.d.ts +19 -0
- package/dist/skins/frames.d.ts.map +1 -0
- package/dist/skins/frames.js +49 -0
- package/dist/skins/frames.js.map +1 -0
- package/dist/skins/game.d.ts +21 -0
- package/dist/skins/game.d.ts.map +1 -0
- package/dist/skins/game.js +21 -0
- package/dist/skins/game.js.map +1 -0
- package/dist/skins/index.d.ts +5 -0
- package/dist/skins/index.d.ts.map +1 -0
- package/dist/skins/index.js +5 -0
- package/dist/skins/types.d.ts +46 -0
- package/dist/skins/types.d.ts.map +1 -0
- package/dist/skins/types.js +12 -0
- package/dist/skins/types.js.map +1 -0
- package/dist/terrain/data.d.ts +10 -0
- package/dist/terrain/data.d.ts.map +1 -0
- package/dist/terrain/data.js +83 -0
- package/dist/terrain/data.js.map +1 -0
- package/dist/terrain/define.d.ts +72 -0
- package/dist/terrain/define.d.ts.map +1 -0
- package/dist/terrain/define.js +91 -0
- package/dist/terrain/define.js.map +1 -0
- package/dist/terrain/editing.d.ts +54 -0
- package/dist/terrain/editing.d.ts.map +1 -0
- package/dist/terrain/editing.js +169 -0
- package/dist/terrain/editing.js.map +1 -0
- package/dist/terrain/index.d.ts +10 -0
- package/dist/terrain/index.d.ts.map +1 -0
- package/dist/terrain/index.js +10 -0
- package/dist/terrain/kernel.d.ts +57 -0
- package/dist/terrain/kernel.d.ts.map +1 -0
- package/dist/terrain/kernel.js +198 -0
- package/dist/terrain/kernel.js.map +1 -0
- package/dist/terrain/mask.d.ts +37 -0
- package/dist/terrain/mask.d.ts.map +1 -0
- package/dist/terrain/mask.js +244 -0
- package/dist/terrain/mask.js.map +1 -0
- package/dist/terrain/patches.d.ts +32 -0
- package/dist/terrain/patches.d.ts.map +1 -0
- package/dist/terrain/patches.js +135 -0
- package/dist/terrain/patches.js.map +1 -0
- package/dist/terrain/rle.d.ts +4 -0
- package/dist/terrain/rle.d.ts.map +1 -0
- package/dist/terrain/rle.js +68 -0
- package/dist/terrain/rle.js.map +1 -0
- package/dist/terrain/scheduler.d.ts +46 -0
- package/dist/terrain/scheduler.d.ts.map +1 -0
- package/dist/terrain/scheduler.js +148 -0
- package/dist/terrain/scheduler.js.map +1 -0
- package/dist/terrain/types.d.ts +110 -0
- package/dist/terrain/types.d.ts.map +1 -0
- package/dist/terrain/types.js +11 -0
- package/dist/terrain/types.js.map +1 -0
- package/dist/terrain-render/backend.d.ts +66 -0
- package/dist/terrain-render/backend.d.ts.map +1 -0
- package/dist/terrain-render/backend.js +96 -0
- package/dist/terrain-render/backend.js.map +1 -0
- package/dist/terrain-render/host.d.ts +21 -0
- package/dist/terrain-render/host.d.ts.map +1 -0
- package/dist/terrain-render/host.js +62 -0
- package/dist/terrain-render/host.js.map +1 -0
- package/dist/terrain-render/index.d.ts +3 -0
- package/dist/terrain-render/index.d.ts.map +1 -0
- package/dist/terrain-render/index.js +3 -0
- package/dist/terrain-render/worker.d.ts +2 -0
- package/dist/terrain-render/worker.d.ts.map +1 -0
- package/dist/terrain-render/worker.js +34 -0
- package/dist/terrain-render/worker.js.map +1 -0
- package/package.json +124 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { AuthorityConnection, AuthoritySession } from '../authority/authority';
|
|
2
|
+
import { TargetRef } from '../interaction/picking';
|
|
3
|
+
import { JsonValue } from '../model/json';
|
|
4
|
+
import { TargetLike, WindowLike } from './protocol';
|
|
5
|
+
/** The part of a map's authority the editor host needs. A `MapAuthority` fits. */
|
|
6
|
+
export interface EditorAuthorityLike {
|
|
7
|
+
connect(session: AuthoritySession): AuthorityConnection;
|
|
8
|
+
}
|
|
9
|
+
/** The part of a map view the editor host drives. A `MapView` with the editing features fits. */
|
|
10
|
+
export interface EditorViewLike {
|
|
11
|
+
readonly interaction: {
|
|
12
|
+
readonly modes: readonly string[];
|
|
13
|
+
setModes(modes: readonly string[]): void;
|
|
14
|
+
readonly pointer: {
|
|
15
|
+
readonly x: number;
|
|
16
|
+
readonly y: number;
|
|
17
|
+
} | null;
|
|
18
|
+
readonly state: {
|
|
19
|
+
get(): {
|
|
20
|
+
readonly selection: readonly TargetRef[];
|
|
21
|
+
readonly lastRejection: {
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
readonly message?: string;
|
|
24
|
+
} | null;
|
|
25
|
+
};
|
|
26
|
+
subscribe(listener: () => void): () => void;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly selection?: {
|
|
30
|
+
select(targets: readonly TargetRef[]): void;
|
|
31
|
+
clear(): void;
|
|
32
|
+
};
|
|
33
|
+
readonly placement?: {
|
|
34
|
+
start(id: string): void;
|
|
35
|
+
cancel(): void;
|
|
36
|
+
};
|
|
37
|
+
readonly terrain?: {
|
|
38
|
+
readonly brush?: {
|
|
39
|
+
start(options: {
|
|
40
|
+
material: string | null;
|
|
41
|
+
radius: number;
|
|
42
|
+
}): void;
|
|
43
|
+
stop(): void;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export interface EditorHostOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Origins that may embed this game as an editor, e.g. `["https://studio.rpgjs.dev"]`. `"*"` lets any page do it:
|
|
50
|
+
* for development only. An empty list lets nobody.
|
|
51
|
+
*/
|
|
52
|
+
readonly allowedOrigins: readonly string[];
|
|
53
|
+
/** The authority of the map the player is on. Read each time the map changes (`notifyMap`). */
|
|
54
|
+
readonly authority: () => {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly authority: EditorAuthorityLike;
|
|
57
|
+
} | undefined;
|
|
58
|
+
/** The view of that map, when there is one. */
|
|
59
|
+
readonly view?: () => EditorViewLike | undefined;
|
|
60
|
+
/** Pauses or resumes the game (server loop and client display). */
|
|
61
|
+
readonly setPaused?: (paused: boolean) => void;
|
|
62
|
+
/** Moves the camera to a world position. */
|
|
63
|
+
readonly camera?: (x: number, y: number) => void;
|
|
64
|
+
/** Who the Studio acts as in the pipelines. The authority must trust it for raw patches (`trustPatches`). Defaults to `{ editor: true }`. */
|
|
65
|
+
readonly actor?: unknown;
|
|
66
|
+
readonly window?: WindowLike & {
|
|
67
|
+
readonly parent?: TargetLike;
|
|
68
|
+
readonly location?: {
|
|
69
|
+
readonly ancestorOrigins?: {
|
|
70
|
+
readonly [index: number]: string | undefined;
|
|
71
|
+
readonly length?: number;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Origin of the page that embeds the game, when the browser says (`location.ancestorOrigins`). Announcing only
|
|
77
|
+
* to it keeps the console clean; without it the game announces to every allowed origin.
|
|
78
|
+
*/
|
|
79
|
+
readonly parentOrigin?: () => string | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* What the game can be asked to do beyond the tools of the view: `{ copy: () => … }`. The Studio calls them by
|
|
82
|
+
* name (`frame.command("copy")`) with JSON arguments. A command that throws is reported as an error, not obeyed twice.
|
|
83
|
+
*/
|
|
84
|
+
readonly commands?: Readonly<Record<string, (args: JsonValue | undefined) => void>>;
|
|
85
|
+
/**
|
|
86
|
+
* The window the Studio is in, when it is not the direct parent: a game that runs in a sandbox frame inside a
|
|
87
|
+
* wrapper page talks to the top window. Defaults to the parent.
|
|
88
|
+
*/
|
|
89
|
+
readonly parent?: TargetLike;
|
|
90
|
+
/** How often the pointer position is reported, in milliseconds. Defaults to 100. 0 turns it off. */
|
|
91
|
+
readonly pointerEveryMs?: number;
|
|
92
|
+
readonly onError?: (error: unknown) => void;
|
|
93
|
+
}
|
|
94
|
+
export interface EditorHost {
|
|
95
|
+
/** Whether a Studio is connected. */
|
|
96
|
+
readonly connected: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Tells the Studio a value the game keeps (`publish("canUndo", true)`). Sent at once, and again to any Studio that
|
|
99
|
+
* connects later: it always has the last value of every key.
|
|
100
|
+
*/
|
|
101
|
+
publish(key: string, value: JsonValue): void;
|
|
102
|
+
/** The player is on another map, or the view of this one now exists: bind to them. */
|
|
103
|
+
notifyMap(): void;
|
|
104
|
+
dispose(): void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The game's end of the editor channels. It lets a Studio that is allowed to (origin checked) join the authority of
|
|
108
|
+
* the map the player is on as a trusted session, drive the tools of the view, and pause the game.
|
|
109
|
+
* Create it only when the game runs as an editor (`?editor`, or in a build the Studio makes): a player never has one.
|
|
110
|
+
*/
|
|
111
|
+
export declare function createEditorHost(options: EditorHostOptions): EditorHost;
|
|
112
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/embed/host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;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,CAAA;KAAE,CAAC;IAC/L;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,MAAM,GAAG,SAAS,CAAC;IACjD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,SAAS,GAAG,SAAS,KAAK,IAAI,CAAC,CAAC,CAAC;IACpF;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAC7B,oGAAoG;IACpG,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C;AAED,MAAM,WAAW,UAAU;IACzB,qCAAqC;IACrC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IAC7C,sFAAsF;IACtF,SAAS,IAAI,IAAI,CAAC;IAClB,OAAO,IAAI,IAAI,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CA2NvE"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { EDITOR_SOURCE, parseControl, parseEnvelope, parseHandshake } from "./protocol.js";
|
|
2
|
+
//#region src/embed/host.ts
|
|
3
|
+
var DEFAULT_ACTOR = Object.freeze({ editor: true });
|
|
4
|
+
/**
|
|
5
|
+
* The game's end of the editor channels. It lets a Studio that is allowed to (origin checked) join the authority of
|
|
6
|
+
* the map the player is on as a trusted session, drive the tools of the view, and pause the game.
|
|
7
|
+
* Create it only when the game runs as an editor (`?editor`, or in a build the Studio makes): a player never has one.
|
|
8
|
+
*/
|
|
9
|
+
function createEditorHost(options) {
|
|
10
|
+
const win = options.window ?? globalThis.window;
|
|
11
|
+
const parent = options.parent ?? win?.parent;
|
|
12
|
+
if (!win || !parent) throw new Error("createEditorHost needs a window and a parent to talk to");
|
|
13
|
+
const report = options.onError ?? ((error) => console.error("[map-builder editor]", error));
|
|
14
|
+
const allowed = (origin) => options.allowedOrigins.includes("*") || options.allowedOrigins.includes(origin);
|
|
15
|
+
let port;
|
|
16
|
+
let connection;
|
|
17
|
+
let mapId;
|
|
18
|
+
let stopView;
|
|
19
|
+
let paused = false;
|
|
20
|
+
let tool = { tool: "none" };
|
|
21
|
+
let pointerTimer;
|
|
22
|
+
let disposed = false;
|
|
23
|
+
const published = /* @__PURE__ */ new Map();
|
|
24
|
+
const post = (message) => {
|
|
25
|
+
try {
|
|
26
|
+
port?.postMessage(message);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
report(error);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const emit = (event) => post({
|
|
32
|
+
ch: "event",
|
|
33
|
+
message: event
|
|
34
|
+
});
|
|
35
|
+
const announce = () => {
|
|
36
|
+
const known = (options.parentOrigin ?? (() => {
|
|
37
|
+
const ancestors = win.location?.ancestorOrigins;
|
|
38
|
+
for (let i = 0; ancestors && i < (ancestors.length ?? 0); i += 1) {
|
|
39
|
+
const origin = ancestors[i];
|
|
40
|
+
if (origin && allowed(origin)) return origin;
|
|
41
|
+
}
|
|
42
|
+
}))();
|
|
43
|
+
const targets = known && allowed(known) ? [known] : [...options.allowedOrigins];
|
|
44
|
+
for (const origin of targets) try {
|
|
45
|
+
parent.postMessage({
|
|
46
|
+
source: EDITOR_SOURCE,
|
|
47
|
+
type: "ready",
|
|
48
|
+
version: 1
|
|
49
|
+
}, origin);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
report(error);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const view = () => options.view?.();
|
|
55
|
+
const interactionEvent = (v) => {
|
|
56
|
+
const rejection = v.interaction.state.get().lastRejection;
|
|
57
|
+
return {
|
|
58
|
+
type: "interaction",
|
|
59
|
+
modes: [...v.interaction.modes],
|
|
60
|
+
tool,
|
|
61
|
+
rejection: rejection ? {
|
|
62
|
+
reason: rejection.reason,
|
|
63
|
+
...rejection.message ? { message: rejection.message } : {}
|
|
64
|
+
} : null
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const unbind = () => {
|
|
68
|
+
stopView?.();
|
|
69
|
+
stopView = void 0;
|
|
70
|
+
connection?.disconnect();
|
|
71
|
+
connection = void 0;
|
|
72
|
+
mapId = void 0;
|
|
73
|
+
};
|
|
74
|
+
/** Joins the authority of the map the player is on, and follows its view. */
|
|
75
|
+
const bind = () => {
|
|
76
|
+
unbind();
|
|
77
|
+
if (!port) return;
|
|
78
|
+
const found = options.authority();
|
|
79
|
+
if (!found) return;
|
|
80
|
+
mapId = found.id;
|
|
81
|
+
const id = found.id;
|
|
82
|
+
emit({
|
|
83
|
+
type: "map",
|
|
84
|
+
id
|
|
85
|
+
});
|
|
86
|
+
connection = found.authority.connect({
|
|
87
|
+
id: "studio",
|
|
88
|
+
actor: options.actor ?? DEFAULT_ACTOR,
|
|
89
|
+
send: (message) => post({
|
|
90
|
+
ch: "map",
|
|
91
|
+
map: id,
|
|
92
|
+
message
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
const v = view();
|
|
96
|
+
if (!v) return;
|
|
97
|
+
let lastSelection = "";
|
|
98
|
+
const push = () => {
|
|
99
|
+
const selection = v.interaction.state.get().selection;
|
|
100
|
+
const key = selection.map((target) => `${target.type}:${target.id}`).join("|");
|
|
101
|
+
if (key !== lastSelection) {
|
|
102
|
+
lastSelection = key;
|
|
103
|
+
emit({
|
|
104
|
+
type: "selection",
|
|
105
|
+
targets: selection.map((target) => ({
|
|
106
|
+
type: target.type,
|
|
107
|
+
id: target.id
|
|
108
|
+
}))
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
emit(interactionEvent(v));
|
|
112
|
+
};
|
|
113
|
+
stopView = v.interaction.state.subscribe(push);
|
|
114
|
+
push();
|
|
115
|
+
};
|
|
116
|
+
const control = (message) => {
|
|
117
|
+
const v = view();
|
|
118
|
+
switch (message.type) {
|
|
119
|
+
case "pause":
|
|
120
|
+
paused = message.paused;
|
|
121
|
+
options.setPaused?.(paused);
|
|
122
|
+
emit({
|
|
123
|
+
type: "paused",
|
|
124
|
+
paused
|
|
125
|
+
});
|
|
126
|
+
return;
|
|
127
|
+
case "camera":
|
|
128
|
+
options.camera?.(message.x, message.y);
|
|
129
|
+
return;
|
|
130
|
+
case "command": {
|
|
131
|
+
const run = options.commands && Object.hasOwn(options.commands, message.name) ? options.commands[message.name] : void 0;
|
|
132
|
+
if (!run) return emit({
|
|
133
|
+
type: "error",
|
|
134
|
+
message: `Unknown command "${message.name}"`
|
|
135
|
+
});
|
|
136
|
+
try {
|
|
137
|
+
run(message.args);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
emit({
|
|
140
|
+
type: "error",
|
|
141
|
+
message: error instanceof Error ? error.message : String(error)
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
default: break;
|
|
147
|
+
}
|
|
148
|
+
if (!v) return emit({
|
|
149
|
+
type: "error",
|
|
150
|
+
message: "No map is shown yet"
|
|
151
|
+
});
|
|
152
|
+
try {
|
|
153
|
+
if (message.type === "modes") v.interaction.setModes(message.modes);
|
|
154
|
+
else if (message.type === "select") {
|
|
155
|
+
if (!v.selection) return emit({
|
|
156
|
+
type: "error",
|
|
157
|
+
message: "This game has no selection"
|
|
158
|
+
});
|
|
159
|
+
if (message.targets.length === 0) v.selection.clear();
|
|
160
|
+
else v.selection.select(message.targets);
|
|
161
|
+
} else if (message.type === "tool") {
|
|
162
|
+
v.terrain?.brush?.stop();
|
|
163
|
+
v.placement?.cancel();
|
|
164
|
+
if (message.tool === "brush") {
|
|
165
|
+
if (!v.terrain?.brush) return emit({
|
|
166
|
+
type: "error",
|
|
167
|
+
message: "This map has no terrain to paint"
|
|
168
|
+
});
|
|
169
|
+
v.terrain.brush.start({
|
|
170
|
+
material: message.material,
|
|
171
|
+
radius: message.radius
|
|
172
|
+
});
|
|
173
|
+
} else if (message.tool === "place") {
|
|
174
|
+
if (!v.placement) return emit({
|
|
175
|
+
type: "error",
|
|
176
|
+
message: "This game has nothing to place"
|
|
177
|
+
});
|
|
178
|
+
v.placement.start(message.catalogId);
|
|
179
|
+
}
|
|
180
|
+
const { type: _type, ...next } = message;
|
|
181
|
+
tool = next;
|
|
182
|
+
}
|
|
183
|
+
emit(interactionEvent(v));
|
|
184
|
+
} catch (error) {
|
|
185
|
+
emit({
|
|
186
|
+
type: "error",
|
|
187
|
+
message: error instanceof Error ? error.message : String(error)
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
const onPort = (event) => {
|
|
192
|
+
const envelope = parseEnvelope(event.data);
|
|
193
|
+
if (!envelope) return;
|
|
194
|
+
if (envelope.ch === "map") {
|
|
195
|
+
if (envelope.map === mapId) connection?.receive(envelope.message);
|
|
196
|
+
} else if (envelope.ch === "control") {
|
|
197
|
+
const parsed = parseControl(envelope.message);
|
|
198
|
+
if (parsed) control(parsed);
|
|
199
|
+
else emit({
|
|
200
|
+
type: "error",
|
|
201
|
+
message: "Unknown or invalid control message"
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const connect = (next) => {
|
|
206
|
+
unbind();
|
|
207
|
+
port?.close();
|
|
208
|
+
port = next;
|
|
209
|
+
port.addEventListener("message", onPort);
|
|
210
|
+
port.start?.();
|
|
211
|
+
bind();
|
|
212
|
+
for (const [key, value] of published) emit({
|
|
213
|
+
type: "state",
|
|
214
|
+
key,
|
|
215
|
+
value
|
|
216
|
+
});
|
|
217
|
+
if (pointerTimer) clearInterval(pointerTimer);
|
|
218
|
+
if ((options.pointerEveryMs ?? 100) > 0) {
|
|
219
|
+
let last = "";
|
|
220
|
+
pointerTimer = setInterval(() => {
|
|
221
|
+
const pointer = view()?.interaction.pointer;
|
|
222
|
+
if (!pointer) return;
|
|
223
|
+
const key = `${Math.round(pointer.x)},${Math.round(pointer.y)}`;
|
|
224
|
+
if (key === last) return;
|
|
225
|
+
last = key;
|
|
226
|
+
emit({
|
|
227
|
+
type: "pointer",
|
|
228
|
+
x: Math.round(pointer.x),
|
|
229
|
+
y: Math.round(pointer.y)
|
|
230
|
+
});
|
|
231
|
+
}, options.pointerEveryMs ?? 100);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
const onWindow = (event) => {
|
|
235
|
+
if (disposed) return;
|
|
236
|
+
if (event.source !== parent || !allowed(event.origin)) return;
|
|
237
|
+
const handshake = parseHandshake(event.data);
|
|
238
|
+
if (!handshake) return;
|
|
239
|
+
if (handshake.type === "hello") return announce();
|
|
240
|
+
if (handshake.type !== "connect") return;
|
|
241
|
+
if (handshake.version !== 1) {
|
|
242
|
+
report(/* @__PURE__ */ new Error(`The Studio speaks editor protocol ${handshake.version}, this game speaks 1`));
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
const given = event.ports?.[0];
|
|
246
|
+
if (given) connect(given);
|
|
247
|
+
};
|
|
248
|
+
win.addEventListener("message", onWindow);
|
|
249
|
+
announce();
|
|
250
|
+
return {
|
|
251
|
+
get connected() {
|
|
252
|
+
return port !== void 0;
|
|
253
|
+
},
|
|
254
|
+
publish(key, value) {
|
|
255
|
+
published.set(key, value);
|
|
256
|
+
emit({
|
|
257
|
+
type: "state",
|
|
258
|
+
key,
|
|
259
|
+
value
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
notifyMap: () => {
|
|
263
|
+
if (port && !disposed) bind();
|
|
264
|
+
},
|
|
265
|
+
dispose() {
|
|
266
|
+
disposed = true;
|
|
267
|
+
win.removeEventListener("message", onWindow);
|
|
268
|
+
if (pointerTimer) clearInterval(pointerTimer);
|
|
269
|
+
unbind();
|
|
270
|
+
port?.close();
|
|
271
|
+
port = void 0;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { createEditorHost };
|
|
277
|
+
|
|
278
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../../src/embed/host.ts"],"sourcesContent":["import type { AuthorityConnection, AuthoritySession } from \"../authority/authority\";\nimport type { TargetRef } from \"../interaction/picking\";\nimport type { JsonValue } from \"../model/json\";\nimport type { ServerMessage } from \"../protocol\";\nimport {\n EDITOR_PROTOCOL_VERSION,\n EDITOR_SOURCE,\n parseControl,\n parseEnvelope,\n parseHandshake,\n type ControlMessage,\n type EditorEvent,\n type EditorTool,\n type MessageEventLike,\n type PortLike,\n type TargetLike,\n type WindowLike,\n} from \"./protocol\";\n\n/** The part of a map's authority the editor host needs. A `MapAuthority` fits. */\nexport interface EditorAuthorityLike {\n connect(session: AuthoritySession): AuthorityConnection;\n}\n\n/** The part of a map view the editor host drives. A `MapView` with the editing features fits. */\nexport interface EditorViewLike {\n readonly interaction: {\n readonly modes: readonly string[];\n setModes(modes: readonly string[]): void;\n readonly pointer: { readonly x: number; readonly y: number } | null;\n readonly state: {\n get(): { readonly selection: readonly TargetRef[]; readonly lastRejection: { readonly reason: string; readonly message?: string } | null };\n subscribe(listener: () => void): () => void;\n };\n };\n readonly selection?: { select(targets: readonly TargetRef[]): void; clear(): void };\n readonly placement?: { start(id: string): void; cancel(): void };\n readonly terrain?: { readonly brush?: { start(options: { material: string | null; radius: number }): void; stop(): void } };\n}\n\nexport interface EditorHostOptions {\n /**\n * Origins that may embed this game as an editor, e.g. `[\"https://studio.rpgjs.dev\"]`. `\"*\"` lets any page do it:\n * for development only. An empty list lets nobody.\n */\n readonly allowedOrigins: readonly string[];\n /** The authority of the map the player is on. Read each time the map changes (`notifyMap`). */\n readonly authority: () => { readonly id: string; readonly authority: EditorAuthorityLike } | undefined;\n /** The view of that map, when there is one. */\n readonly view?: () => EditorViewLike | undefined;\n /** Pauses or resumes the game (server loop and client display). */\n readonly setPaused?: (paused: boolean) => void;\n /** Moves the camera to a world position. */\n readonly camera?: (x: number, y: number) => void;\n /** Who the Studio acts as in the pipelines. The authority must trust it for raw patches (`trustPatches`). Defaults to `{ editor: true }`. */\n readonly actor?: unknown;\n readonly window?: WindowLike & { readonly parent?: TargetLike; readonly location?: { readonly ancestorOrigins?: { readonly [index: number]: string | undefined; readonly length?: number } } };\n /**\n * Origin of the page that embeds the game, when the browser says (`location.ancestorOrigins`). Announcing only\n * to it keeps the console clean; without it the game announces to every allowed origin.\n */\n readonly parentOrigin?: () => string | undefined;\n /**\n * What the game can be asked to do beyond the tools of the view: `{ copy: () => … }`. The Studio calls them by\n * name (`frame.command(\"copy\")`) with JSON arguments. A command that throws is reported as an error, not obeyed twice.\n */\n readonly commands?: Readonly<Record<string, (args: JsonValue | undefined) => void>>;\n /**\n * The window the Studio is in, when it is not the direct parent: a game that runs in a sandbox frame inside a\n * wrapper page talks to the top window. Defaults to the parent.\n */\n readonly parent?: TargetLike;\n /** How often the pointer position is reported, in milliseconds. Defaults to 100. 0 turns it off. */\n readonly pointerEveryMs?: number;\n readonly onError?: (error: unknown) => void;\n}\n\nexport interface EditorHost {\n /** Whether a Studio is connected. */\n readonly connected: boolean;\n /**\n * Tells the Studio a value the game keeps (`publish(\"canUndo\", true)`). Sent at once, and again to any Studio that\n * connects later: it always has the last value of every key.\n */\n publish(key: string, value: JsonValue): void;\n /** The player is on another map, or the view of this one now exists: bind to them. */\n notifyMap(): void;\n dispose(): void;\n}\n\nconst DEFAULT_ACTOR = Object.freeze({ editor: true });\n\n/**\n * The game's end of the editor channels. It lets a Studio that is allowed to (origin checked) join the authority of\n * the map the player is on as a trusted session, drive the tools of the view, and pause the game.\n * Create it only when the game runs as an editor (`?editor`, or in a build the Studio makes): a player never has one.\n */\nexport function createEditorHost(options: EditorHostOptions): EditorHost {\n const win = options.window ?? (globalThis as unknown as { window?: EditorHostOptions[\"window\"] }).window;\n const parent = options.parent ?? win?.parent;\n if (!win || !parent) throw new Error(\"createEditorHost needs a window and a parent to talk to\");\n const report = options.onError ?? ((error: unknown) => console.error(\"[map-builder editor]\", error));\n const allowed = (origin: string): boolean => options.allowedOrigins.includes(\"*\") || options.allowedOrigins.includes(origin);\n\n let port: PortLike | undefined;\n let connection: AuthorityConnection | undefined;\n let mapId: string | undefined;\n let stopView: (() => void) | undefined;\n let paused = false;\n let tool: EditorTool = { tool: \"none\" };\n let pointerTimer: ReturnType<typeof setInterval> | undefined;\n let disposed = false;\n const published = new Map<string, JsonValue>();\n\n const post = (message: unknown): void => {\n try {\n port?.postMessage(message);\n } catch (error) {\n report(error);\n }\n };\n const emit = (event: EditorEvent): void => post({ ch: \"event\", message: event });\n\n const announce = (): void => {\n const known = (options.parentOrigin ?? (() => {\n // The first ancestor that is allowed: the wrapper page of a sandbox is not, the Studio above it is.\n const ancestors = win.location?.ancestorOrigins;\n for (let i = 0; ancestors && i < (ancestors.length ?? 0); i += 1) {\n const origin = ancestors[i];\n if (origin && allowed(origin)) return origin;\n }\n return undefined;\n }))();\n const targets = known && allowed(known) ? [known] : [...options.allowedOrigins];\n for (const origin of targets) {\n try {\n parent.postMessage({ source: EDITOR_SOURCE, type: \"ready\", version: EDITOR_PROTOCOL_VERSION }, origin);\n } catch (error) {\n report(error);\n }\n }\n };\n\n const view = (): EditorViewLike | undefined => options.view?.();\n\n const interactionEvent = (v: EditorViewLike): EditorEvent => {\n const rejection = v.interaction.state.get().lastRejection;\n return { type: \"interaction\", modes: [...v.interaction.modes], tool, rejection: rejection ? { reason: rejection.reason, ...(rejection.message ? { message: rejection.message } : {}) } : null };\n };\n\n const unbind = (): void => {\n stopView?.();\n stopView = undefined;\n connection?.disconnect();\n connection = undefined;\n mapId = undefined;\n };\n\n /** Joins the authority of the map the player is on, and follows its view. */\n const bind = (): void => {\n unbind();\n if (!port) return;\n const found = options.authority();\n if (!found) return;\n mapId = found.id;\n const id = found.id;\n // Said first, so that the Studio is ready for the snapshot the authority sends as soon as it is connected.\n emit({ type: \"map\", id });\n connection = found.authority.connect({\n id: \"studio\",\n actor: options.actor ?? DEFAULT_ACTOR,\n send: (message) => post({ ch: \"map\", map: id, message: message as ServerMessage }),\n });\n const v = view();\n if (!v) return;\n let lastSelection = \"\";\n const push = (): void => {\n const selection = v.interaction.state.get().selection;\n const key = selection.map((target) => `${target.type}:${target.id}`).join(\"|\");\n if (key !== lastSelection) {\n lastSelection = key;\n emit({ type: \"selection\", targets: selection.map((target) => ({ type: target.type, id: target.id })) });\n }\n emit(interactionEvent(v));\n };\n const stop = v.interaction.state.subscribe(push);\n stopView = stop;\n push();\n };\n\n const control = (message: ControlMessage): void => {\n const v = view();\n switch (message.type) {\n case \"pause\":\n paused = message.paused;\n options.setPaused?.(paused);\n emit({ type: \"paused\", paused });\n return;\n case \"camera\":\n options.camera?.(message.x, message.y);\n return;\n case \"command\": {\n const run = options.commands && Object.hasOwn(options.commands, message.name) ? options.commands[message.name] : undefined;\n if (!run) return emit({ type: \"error\", message: `Unknown command \"${message.name}\"` });\n try {\n run(message.args);\n } catch (error) {\n emit({ type: \"error\", message: error instanceof Error ? error.message : String(error) });\n }\n return;\n }\n default:\n break;\n }\n if (!v) return emit({ type: \"error\", message: \"No map is shown yet\" });\n try {\n if (message.type === \"modes\") {\n v.interaction.setModes(message.modes);\n } else if (message.type === \"select\") {\n if (!v.selection) return emit({ type: \"error\", message: \"This game has no selection\" });\n if (message.targets.length === 0) v.selection.clear();\n else v.selection.select(message.targets);\n } else if (message.type === \"tool\") {\n // One tool at a time: whatever was in hand is put away.\n v.terrain?.brush?.stop();\n v.placement?.cancel();\n if (message.tool === \"brush\") {\n if (!v.terrain?.brush) return emit({ type: \"error\", message: \"This map has no terrain to paint\" });\n v.terrain.brush.start({ material: message.material, radius: message.radius });\n } else if (message.tool === \"place\") {\n if (!v.placement) return emit({ type: \"error\", message: \"This game has nothing to place\" });\n v.placement.start(message.catalogId);\n }\n const { type: _type, ...next } = message;\n tool = next as EditorTool;\n }\n emit(interactionEvent(v));\n } catch (error) {\n emit({ type: \"error\", message: error instanceof Error ? error.message : String(error) });\n }\n };\n\n const onPort = (event: { data: unknown }): void => {\n const envelope = parseEnvelope(event.data);\n if (!envelope) return;\n if (envelope.ch === \"map\") {\n if (envelope.map === mapId) connection?.receive(envelope.message);\n } else if (envelope.ch === \"control\") {\n const parsed = parseControl(envelope.message);\n if (parsed) control(parsed);\n else emit({ type: \"error\", message: \"Unknown or invalid control message\" });\n }\n };\n\n const connect = (next: PortLike): void => {\n unbind();\n port?.close();\n port = next;\n port.addEventListener(\"message\", onPort);\n port.start?.();\n bind();\n // A Studio that connects late learns what the game already keeps.\n for (const [key, value] of published) emit({ type: \"state\", key, value });\n if (pointerTimer) clearInterval(pointerTimer);\n if ((options.pointerEveryMs ?? 100) > 0) {\n let last = \"\";\n pointerTimer = setInterval(() => {\n const pointer = view()?.interaction.pointer;\n if (!pointer) return;\n const key = `${Math.round(pointer.x)},${Math.round(pointer.y)}`;\n if (key === last) return;\n last = key;\n emit({ type: \"pointer\", x: Math.round(pointer.x), y: Math.round(pointer.y) });\n }, options.pointerEveryMs ?? 100);\n }\n };\n\n const onWindow = (event: MessageEventLike): void => {\n if (disposed) return;\n // Only the page that embeds us, and only if it is allowed to.\n if (event.source !== parent || !allowed(event.origin)) return;\n const handshake = parseHandshake(event.data);\n if (!handshake) return;\n if (handshake.type === \"hello\") return announce();\n if (handshake.type !== \"connect\") return;\n if (handshake.version !== EDITOR_PROTOCOL_VERSION) {\n report(new Error(`The Studio speaks editor protocol ${handshake.version}, this game speaks ${EDITOR_PROTOCOL_VERSION}`));\n return;\n }\n const given = event.ports?.[0];\n if (given) connect(given);\n };\n\n win.addEventListener(\"message\", onWindow);\n announce();\n\n return {\n get connected() {\n return port !== undefined;\n },\n publish(key, value) {\n published.set(key, value);\n emit({ type: \"state\", key, value });\n },\n notifyMap: () => {\n if (port && !disposed) bind();\n },\n dispose() {\n disposed = true;\n win.removeEventListener(\"message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C3B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { EDITOR_PROTOCOL_VERSION, EDITOR_SOURCE, LIMITS, parseControl, parseEnvelope, parseEvent, parseHandshake, parseTargets } from "./protocol.js";
|
|
2
|
+
import { createEditorHost } from "./host.js";
|
|
3
|
+
import { connectEditorFrame } from "./client.js";
|
|
4
|
+
export { EDITOR_PROTOCOL_VERSION, EDITOR_SOURCE, LIMITS, connectEditorFrame, createEditorHost, parseControl, parseEnvelope, parseEvent, parseHandshake, parseTargets };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { JsonValue } from '../model/json';
|
|
2
|
+
import { TargetRef } from '../interaction/picking';
|
|
3
|
+
/** Version of the messages between the Studio and a game. Both ends say theirs in the handshake. */
|
|
4
|
+
export declare const EDITOR_PROTOCOL_VERSION: 1;
|
|
5
|
+
/** Marks the window messages of the handshake, so that the page ignores everybody else's. */
|
|
6
|
+
export declare const EDITOR_SOURCE: "rpgjs-map-builder-editor";
|
|
7
|
+
/** The tool that is in hand. */
|
|
8
|
+
export type EditorTool = {
|
|
9
|
+
readonly tool: "none";
|
|
10
|
+
} | {
|
|
11
|
+
readonly tool: "brush";
|
|
12
|
+
readonly material: string | null;
|
|
13
|
+
readonly radius: number;
|
|
14
|
+
} | {
|
|
15
|
+
readonly tool: "place";
|
|
16
|
+
readonly catalogId: string;
|
|
17
|
+
};
|
|
18
|
+
/** What the Studio asks of the game. */
|
|
19
|
+
export type ControlMessage = {
|
|
20
|
+
readonly type: "modes";
|
|
21
|
+
readonly modes: readonly string[];
|
|
22
|
+
} | ({
|
|
23
|
+
readonly type: "tool";
|
|
24
|
+
} & EditorTool) | {
|
|
25
|
+
readonly type: "select";
|
|
26
|
+
readonly targets: readonly TargetRef[];
|
|
27
|
+
} | {
|
|
28
|
+
readonly type: "pause";
|
|
29
|
+
readonly paused: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
readonly type: "camera";
|
|
32
|
+
readonly x: number;
|
|
33
|
+
readonly y: number;
|
|
34
|
+
}
|
|
35
|
+
/** Something only the game knows how to do: a command it registered (`copy`, `place`…). */
|
|
36
|
+
| {
|
|
37
|
+
readonly type: "command";
|
|
38
|
+
readonly name: string;
|
|
39
|
+
readonly args?: JsonValue;
|
|
40
|
+
};
|
|
41
|
+
/** What the game tells the Studio. */
|
|
42
|
+
export type EditorEvent = {
|
|
43
|
+
readonly type: "map";
|
|
44
|
+
readonly id: string;
|
|
45
|
+
} | {
|
|
46
|
+
readonly type: "selection";
|
|
47
|
+
readonly targets: readonly TargetRef[];
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "interaction";
|
|
50
|
+
readonly modes: readonly string[];
|
|
51
|
+
readonly tool: EditorTool;
|
|
52
|
+
/** Why the last intent was refused, until another is accepted. */
|
|
53
|
+
readonly rejection: {
|
|
54
|
+
readonly reason: string;
|
|
55
|
+
readonly message?: string;
|
|
56
|
+
} | null;
|
|
57
|
+
} | {
|
|
58
|
+
readonly type: "paused";
|
|
59
|
+
readonly paused: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
readonly type: "pointer";
|
|
62
|
+
readonly x: number;
|
|
63
|
+
readonly y: number;
|
|
64
|
+
}
|
|
65
|
+
/** A value the game keeps and the Studio shows (`tool`, `canUndo`, `layer`…). */
|
|
66
|
+
| {
|
|
67
|
+
readonly type: "state";
|
|
68
|
+
readonly key: string;
|
|
69
|
+
readonly value: JsonValue;
|
|
70
|
+
} | {
|
|
71
|
+
readonly type: "error";
|
|
72
|
+
readonly message: string;
|
|
73
|
+
};
|
|
74
|
+
/** Messages of the handshake, sent with `window.postMessage`. */
|
|
75
|
+
export type HandshakeMessage = {
|
|
76
|
+
readonly source: typeof EDITOR_SOURCE;
|
|
77
|
+
readonly type: "hello";
|
|
78
|
+
readonly version: number;
|
|
79
|
+
} | {
|
|
80
|
+
readonly source: typeof EDITOR_SOURCE;
|
|
81
|
+
readonly type: "ready";
|
|
82
|
+
readonly version: number;
|
|
83
|
+
} | {
|
|
84
|
+
readonly source: typeof EDITOR_SOURCE;
|
|
85
|
+
readonly type: "connect";
|
|
86
|
+
readonly version: number;
|
|
87
|
+
};
|
|
88
|
+
export declare const LIMITS: {
|
|
89
|
+
/** Targets in one selection. */
|
|
90
|
+
readonly maxTargets: 10000;
|
|
91
|
+
readonly maxModes: 16;
|
|
92
|
+
readonly maxStringLength: 256;
|
|
93
|
+
};
|
|
94
|
+
export declare function parseTargets(raw: unknown): TargetRef[] | undefined;
|
|
95
|
+
/** Reads a control message that came through the port. Anything with another shape is `undefined`. */
|
|
96
|
+
export declare function parseControl(raw: unknown): ControlMessage | undefined;
|
|
97
|
+
/** Reads an event from the game. */
|
|
98
|
+
export declare function parseEvent(raw: unknown): EditorEvent | undefined;
|
|
99
|
+
export declare function parseHandshake(raw: unknown): HandshakeMessage | undefined;
|
|
100
|
+
/** What goes through the port. The map channel carries the authority protocol, tagged with the map. */
|
|
101
|
+
export type Envelope = {
|
|
102
|
+
readonly ch: "map";
|
|
103
|
+
readonly map: string;
|
|
104
|
+
readonly message: unknown;
|
|
105
|
+
} | {
|
|
106
|
+
readonly ch: "control";
|
|
107
|
+
readonly message: unknown;
|
|
108
|
+
} | {
|
|
109
|
+
readonly ch: "event";
|
|
110
|
+
readonly message: unknown;
|
|
111
|
+
};
|
|
112
|
+
export declare function parseEnvelope(raw: unknown): Envelope | undefined;
|
|
113
|
+
/** What a `MessagePort` offers, so that tests and other carriers can stand in. */
|
|
114
|
+
export interface PortLike {
|
|
115
|
+
postMessage(message: unknown): void;
|
|
116
|
+
addEventListener(type: "message", listener: (event: {
|
|
117
|
+
data: unknown;
|
|
118
|
+
}) => void): void;
|
|
119
|
+
start?(): void;
|
|
120
|
+
close(): void;
|
|
121
|
+
}
|
|
122
|
+
/** What a window offers to listen to messages. */
|
|
123
|
+
export interface WindowLike {
|
|
124
|
+
addEventListener(type: "message", listener: (event: MessageEventLike) => void): void;
|
|
125
|
+
removeEventListener(type: "message", listener: (event: MessageEventLike) => void): void;
|
|
126
|
+
}
|
|
127
|
+
export interface MessageEventLike {
|
|
128
|
+
readonly data: unknown;
|
|
129
|
+
readonly origin: string;
|
|
130
|
+
readonly source: unknown;
|
|
131
|
+
readonly ports?: readonly PortLike[];
|
|
132
|
+
}
|
|
133
|
+
/** Something a message can be posted to: a frame's window, or `window.parent`. */
|
|
134
|
+
export interface TargetLike {
|
|
135
|
+
postMessage(message: unknown, targetOrigin: string, transfer?: Transferable[]): void;
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/embed/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,oGAAoG;AACpG,eAAO,MAAM,uBAAuB,EAAG,CAAU,CAAC;AAElD,6FAA6F;AAC7F,eAAO,MAAM,aAAa,EAAG,0BAAmC,CAAC;AAEjE,gCAAgC;AAChC,MAAM,MAAM,UAAU,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACrF;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3D,wCAAwC;AACxC,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAAE,GAC7D,CAAC;I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