@gedit/editor-2d 0.2.46 → 0.2.48
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/lib/browser/model/editor2d-document.d.ts +11 -2
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +44 -8
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-model-container.d.ts.map +1 -1
- package/lib/browser/model/editor2d-model-container.js +1 -1
- package/lib/browser/model/editor2d-model-container.js.map +1 -1
- package/lib/browser/model/editor2d-model.d.ts +2 -0
- package/lib/browser/model/editor2d-model.d.ts.map +1 -1
- package/lib/browser/model/editor2d-model.js +5 -0
- package/lib/browser/model/editor2d-model.js.map +1 -1
- package/lib/browser/model/editor2d.d.ts +2 -0
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +4 -2
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts +6 -2
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +174 -49
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +15 -3
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +134 -72
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/index.d.ts +2 -0
- package/lib/browser/playground/index.d.ts.map +1 -1
- package/lib/browser/playground/index.js +2 -0
- package/lib/browser/playground/index.js.map +1 -1
- package/lib/browser/playground/path-edit/index.d.ts +4 -0
- package/lib/browser/playground/path-edit/index.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/index.js +20 -0
- package/lib/browser/playground/path-edit/index.js.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts +18 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js +52 -0
- package/lib/browser/playground/path-edit/path-edit-layer-move-point.js.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts +21 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js +158 -0
- package/lib/browser/playground/path-edit/path-edit-layer-svg-path.js.map +1 -0
- package/lib/browser/playground/path-edit/utils.d.ts +37 -0
- package/lib/browser/playground/path-edit/utils.d.ts.map +1 -0
- package/lib/browser/playground/path-edit/utils.js +236 -0
- package/lib/browser/playground/path-edit/utils.js.map +1 -0
- package/lib/browser/playground/path-edit-layer.d.ts +32 -12
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -1
- package/lib/browser/playground/path-edit-layer.js +460 -146
- package/lib/browser/playground/path-edit-layer.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +5 -2
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +13 -2
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +4 -1
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +23 -23
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts +1 -1
- package/lib/browser/playground/selection-entity-manager.d.ts.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +40 -10
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.d.ts +2 -1
- package/lib/browser/playground/selector-extend-renderer.d.ts.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.js +50 -21
- package/lib/browser/playground/selector-extend-renderer.js.map +1 -1
- package/lib/browser/utils/snapshot.d.ts +1 -0
- package/lib/browser/utils/snapshot.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +12 -1
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -7
- package/src/browser/model/editor2d-document.ts +44 -6
- package/src/browser/model/editor2d-model-container.ts +2 -0
- package/src/browser/model/editor2d-model.ts +2 -0
- package/src/browser/model/editor2d.ts +4 -1
- package/src/browser/playground/canvas-draw.ts +331 -112
- package/src/browser/playground/canvas-layer.ts +120 -59
- package/src/browser/playground/index.ts +2 -0
- package/src/browser/playground/path-edit/index.ts +3 -0
- package/src/browser/playground/path-edit/path-edit-layer-move-point.tsx +108 -0
- package/src/browser/playground/path-edit/path-edit-layer-svg-path.tsx +283 -0
- package/src/browser/playground/path-edit/utils.tsx +285 -0
- package/src/browser/playground/path-edit-layer.tsx +563 -216
- package/src/browser/playground/playground-context.ts +7 -1
- package/src/browser/playground/playground-contribution.ts +17 -24
- package/src/browser/playground/selection-entity-manager.tsx +48 -8
- package/src/browser/playground/selector-extend-renderer.tsx +69 -37
- package/src/browser/style/index.less +6 -0
- package/src/browser/style/path-edit-layer.less +17 -30
- package/src/browser/svg/pen_close.svg +24 -0
- package/src/browser/utils/snapshot.ts +12 -1
- package/LICENSE +0 -21
- package/lib/browser/playground/path-edit-layer-move-point.d.ts +0 -15
- package/lib/browser/playground/path-edit-layer-move-point.d.ts.map +0 -1
- package/lib/browser/playground/path-edit-layer-move-point.js +0 -47
- package/lib/browser/playground/path-edit-layer-move-point.js.map +0 -1
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts +0 -11
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts.map +0 -1
- package/lib/browser/playground/path-edit-layer-svg-path.js +0 -21
- package/lib/browser/playground/path-edit-layer-svg-path.js.map +0 -1
- package/src/browser/playground/path-edit-layer-move-point.tsx +0 -71
- package/src/browser/playground/path-edit-layer-svg-path.tsx +0 -50
|
@@ -1,67 +1,102 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ComponentGameObjectData,
|
|
3
|
+
GameConfig,
|
|
4
|
+
GameObject,
|
|
5
|
+
GameObjectBaseType,
|
|
6
|
+
GameObjectData,
|
|
7
|
+
GameObjectError,
|
|
8
|
+
} from '@gedit/render-engine';
|
|
2
9
|
import { Editor2dNode } from '../model/editor2d';
|
|
3
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
GameSceneIDE,
|
|
12
|
+
GameWidgetIDE,
|
|
13
|
+
RenderEngineIDEService,
|
|
14
|
+
} from '@gedit/render-engine-ide';
|
|
4
15
|
import { AppConfigData } from '@gedit/app-config/lib/common';
|
|
5
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
Disposable,
|
|
18
|
+
DisposableImpl,
|
|
19
|
+
Emitter,
|
|
20
|
+
omit,
|
|
21
|
+
SizeSchema,
|
|
22
|
+
URI,
|
|
23
|
+
} from '@gedit/utils';
|
|
24
|
+
import { EntityManager, SnaplineConfigEntity } from '@gedit/playground';
|
|
6
25
|
|
|
7
26
|
const WAIT_TO_DISPOSE_TIME = 30000; // 延迟删除, 这样tab在频繁切换时候不会有延迟
|
|
8
27
|
const SCENE_KEY = 'boot';
|
|
9
28
|
interface GameObjectState {
|
|
10
|
-
selectable: boolean
|
|
11
|
-
adsorbable: boolean
|
|
12
|
-
isInside: boolean
|
|
29
|
+
selectable: boolean;
|
|
30
|
+
adsorbable: boolean;
|
|
31
|
+
isInside: boolean;
|
|
13
32
|
}
|
|
14
33
|
|
|
15
34
|
export interface CanvasDrawOpts {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
entityManager?: EntityManager;
|
|
36
|
+
host: HTMLElement;
|
|
37
|
+
renderEngine: RenderEngineIDEService;
|
|
38
|
+
assetsURI: string; // 资源地址
|
|
39
|
+
getComponentContent: (
|
|
40
|
+
compId: string,
|
|
41
|
+
parentNode?: Editor2dNode,
|
|
42
|
+
getParent?: boolean
|
|
43
|
+
) => Editor2dNode[] | undefined;
|
|
44
|
+
isSnapshot?: boolean;
|
|
45
|
+
isTemplate?: boolean;
|
|
22
46
|
}
|
|
23
47
|
export interface CanvasDrawData {
|
|
24
|
-
visible: boolean
|
|
25
|
-
engineName: string
|
|
26
|
-
appConfig?: GameConfig
|
|
27
|
-
content?: Editor2dNode // 画布数据
|
|
28
|
-
uri?: string
|
|
29
|
-
configVersion?: number | string // 配置版本,用于控制刷新
|
|
48
|
+
visible: boolean;
|
|
49
|
+
engineName: string;
|
|
50
|
+
appConfig?: GameConfig; // 应用配置
|
|
51
|
+
content?: Editor2dNode; // 画布数据
|
|
52
|
+
uri?: string; // 画布文档uri
|
|
53
|
+
configVersion?: number | string; // 配置版本,用于控制刷新
|
|
30
54
|
}
|
|
31
55
|
export enum GameObjectEventType {
|
|
32
56
|
CREATE,
|
|
33
57
|
CREATE_READY,
|
|
34
58
|
DESTROY,
|
|
35
59
|
UPDATE,
|
|
36
|
-
ERROR
|
|
60
|
+
ERROR,
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
export interface GameObjectChangeEvent {
|
|
40
|
-
type: GameObjectEventType
|
|
41
|
-
state?: GameObjectState
|
|
42
|
-
node: Editor2dNode
|
|
43
|
-
gameObject: GameObject
|
|
64
|
+
type: GameObjectEventType;
|
|
65
|
+
state?: GameObjectState;
|
|
66
|
+
node: Editor2dNode;
|
|
67
|
+
gameObject: GameObject;
|
|
44
68
|
error?: GameObjectError;
|
|
45
69
|
parentObject?: GameObject;
|
|
46
70
|
parentNode?: Editor2dNode;
|
|
47
71
|
}
|
|
48
72
|
|
|
49
73
|
export interface CanvasDrawLoadingState {
|
|
50
|
-
allCount: number
|
|
51
|
-
currentCount: number
|
|
52
|
-
loaded: boolean
|
|
53
|
-
reload?: boolean
|
|
74
|
+
allCount: number;
|
|
75
|
+
currentCount: number;
|
|
76
|
+
loaded: boolean;
|
|
77
|
+
reload?: boolean; // 重新加载
|
|
54
78
|
}
|
|
55
79
|
|
|
56
|
-
function toNodeData(
|
|
57
|
-
|
|
80
|
+
function toNodeData(
|
|
81
|
+
node: Editor2dNode,
|
|
82
|
+
symbols: GameConfig.Symbol[]
|
|
83
|
+
): GameObjectData {
|
|
84
|
+
const originData = omit(node, [
|
|
85
|
+
'parent',
|
|
86
|
+
'previousSibling',
|
|
87
|
+
'nextSibling',
|
|
88
|
+
'children',
|
|
89
|
+
]);
|
|
58
90
|
return GameObjectData.replaceSymbolKey(originData, symbols, true, originData);
|
|
59
|
-
}
|
|
91
|
+
}
|
|
60
92
|
|
|
61
93
|
/**
|
|
62
94
|
* 获取当前画布的变量
|
|
63
95
|
*/
|
|
64
|
-
function getCurrentSymbols(
|
|
96
|
+
function getCurrentSymbols(
|
|
97
|
+
appConfig: AppConfigData,
|
|
98
|
+
root?: Editor2dNode
|
|
99
|
+
): GameConfig.Symbol[] {
|
|
65
100
|
const symbols = appConfig.symbols || [];
|
|
66
101
|
if (root && root.displayType === 'component') {
|
|
67
102
|
return symbols.concat(GameObjectData.getComponentSymbols(root));
|
|
@@ -86,7 +121,10 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
86
121
|
readonly gameObjectCache: Map<string, GameObject> = new Map();
|
|
87
122
|
readonly nodeCache: Map<string, Editor2dNode> = new Map();
|
|
88
123
|
protected nodeVersionCache: Map<string, string> = new Map();
|
|
89
|
-
protected maskCache: Map<
|
|
124
|
+
protected maskCache: Map<
|
|
125
|
+
string,
|
|
126
|
+
{ mask?: string; isMask?: boolean; ignoreMask?: boolean }
|
|
127
|
+
> = new Map();
|
|
90
128
|
protected lastRenderKeys: string[] = [];
|
|
91
129
|
protected renderWidgetDispose: Disposable | undefined;
|
|
92
130
|
protected pixelArt: boolean;
|
|
@@ -100,9 +138,8 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
100
138
|
readonly onGameObjectChange = this.onGameObjectChangeEmitter.event;
|
|
101
139
|
readonly onRenderWidgetCreate = this.onRenderWidgetCreateEmitter.event;
|
|
102
140
|
loading = true;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
) {
|
|
141
|
+
engineName: string;
|
|
142
|
+
constructor(protected opts: CanvasDrawOpts) {
|
|
106
143
|
super();
|
|
107
144
|
this.toDispose.pushAll([
|
|
108
145
|
this.onDrawEmitter,
|
|
@@ -126,7 +163,7 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
126
163
|
* @param engineName
|
|
127
164
|
* @return visible changed
|
|
128
165
|
*/
|
|
129
|
-
protected toggleVisible(appConfig: AppConfigData, visible: boolean
|
|
166
|
+
protected toggleVisible(appConfig: AppConfigData, visible: boolean): boolean {
|
|
130
167
|
if (this.waitToDispose) {
|
|
131
168
|
this.waitToDispose.dispose();
|
|
132
169
|
this.waitToDispose = undefined;
|
|
@@ -140,37 +177,45 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
140
177
|
const backgroundColor = isScene ? appConfig.backgroundColor : '';
|
|
141
178
|
this.pixelArt = appConfig.pixelArt;
|
|
142
179
|
if (visible && !this.renderWidget) {
|
|
143
|
-
const element = window.document.createElement(
|
|
180
|
+
const element = window.document.createElement(
|
|
181
|
+
this.engineName === 'dom' ? 'div' : 'canvas'
|
|
182
|
+
);
|
|
144
183
|
this.opts.host.appendChild(element);
|
|
145
184
|
element.className = 'gedit-canvas-transparent';
|
|
146
|
-
this.renderWidget = this.opts.renderEngine.createGameWidget(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
this.renderWidgetDispose.dispose();
|
|
160
|
-
this.renderWidgetDispose = undefined;
|
|
185
|
+
this.renderWidget = this.opts.renderEngine.createGameWidget(
|
|
186
|
+
this.engineName,
|
|
187
|
+
{
|
|
188
|
+
...appConfig,
|
|
189
|
+
width: 0,
|
|
190
|
+
height: 0,
|
|
191
|
+
uri: this.data?.uri,
|
|
192
|
+
canvas: element,
|
|
193
|
+
rootEngine: appConfig.engine,
|
|
194
|
+
backgroundColor,
|
|
195
|
+
assetsURI: this.opts.assetsURI, // 资源路径
|
|
196
|
+
isSnapshot: this.opts.isSnapshot,
|
|
197
|
+
isIDE: true,
|
|
161
198
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
199
|
+
);
|
|
200
|
+
this.renderWidget.toDispose.push(
|
|
201
|
+
Disposable.create(() => {
|
|
202
|
+
if (this.renderWidgetDispose) {
|
|
203
|
+
this.renderWidgetDispose.dispose();
|
|
204
|
+
this.renderWidgetDispose = undefined;
|
|
205
|
+
}
|
|
206
|
+
element.remove();
|
|
207
|
+
// this.opts.host.removeChild(element);
|
|
208
|
+
this.renderWidget = undefined;
|
|
209
|
+
this.booted = false;
|
|
210
|
+
this.loading = true;
|
|
211
|
+
this.onLoadingEmitter.fire({
|
|
212
|
+
loaded: false,
|
|
213
|
+
allCount: this.allCount,
|
|
214
|
+
currentCount: 0,
|
|
215
|
+
reload: true,
|
|
216
|
+
});
|
|
217
|
+
})
|
|
218
|
+
);
|
|
174
219
|
this.renderWidgetDispose = this.toDispose.push(this.renderWidget);
|
|
175
220
|
Promise.resolve(this.renderWidget.start()).then(() => {
|
|
176
221
|
this.onRenderWidgetCreateEmitter.fire(this.renderWidget!);
|
|
@@ -196,7 +241,7 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
196
241
|
return true;
|
|
197
242
|
}
|
|
198
243
|
return false;
|
|
199
|
-
}
|
|
244
|
+
}
|
|
200
245
|
addComponentSymbolsMetaToLoader(scene: GameSceneIDE): void {
|
|
201
246
|
if (this.currentSymbols.length) {
|
|
202
247
|
this.currentSymbols.forEach(c => {
|
|
@@ -207,6 +252,62 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
207
252
|
});
|
|
208
253
|
}
|
|
209
254
|
}
|
|
255
|
+
|
|
256
|
+
protected switchSnapline(node?: Editor2dNode): void {
|
|
257
|
+
// dom 下开启滚动的话,,显示标尺展示场景大小;
|
|
258
|
+
if (
|
|
259
|
+
node &&
|
|
260
|
+
Editor2dNode.isRootNode(node) &&
|
|
261
|
+
node.displayType === GameObjectBaseType.COMPONENT &&
|
|
262
|
+
this.data?.engineName === 'dom'
|
|
263
|
+
) {
|
|
264
|
+
const snaplineEntity = this.opts.entityManager?.getEntity<SnaplineConfigEntity>(
|
|
265
|
+
SnaplineConfigEntity
|
|
266
|
+
);
|
|
267
|
+
if (!snaplineEntity) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
if (node.scene?.scrollXBool || node.scene?.scrollYBool) {
|
|
271
|
+
snaplineEntity.updateConfig({
|
|
272
|
+
lines: [
|
|
273
|
+
{
|
|
274
|
+
id: 'component_scene_top',
|
|
275
|
+
color: '#fff000',
|
|
276
|
+
horizontal: true,
|
|
277
|
+
start: { x: 0, y: 0 },
|
|
278
|
+
strokeWidth: 1,
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
id: 'component_scene_top',
|
|
282
|
+
color: '#fff000',
|
|
283
|
+
horizontal: true,
|
|
284
|
+
start: { x: 0, y: node.scene?.height || 400 },
|
|
285
|
+
strokeWidth: 1,
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
id: 'component_scene_left',
|
|
289
|
+
color: 'red',
|
|
290
|
+
vertical: true,
|
|
291
|
+
start: { x: 0, y: 0 },
|
|
292
|
+
strokeWidth: 1,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 'component_scene_right',
|
|
296
|
+
color: 'red',
|
|
297
|
+
vertical: true,
|
|
298
|
+
start: { x: node.scene?.width || 400, y: 0 },
|
|
299
|
+
strokeWidth: 1,
|
|
300
|
+
},
|
|
301
|
+
],
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
304
|
+
snaplineEntity.updateConfig({
|
|
305
|
+
lines: [],
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
210
311
|
updateGameObjects(scene: GameSceneIDE, content: Editor2dNode): void {
|
|
211
312
|
const renderKeys: string[] = [];
|
|
212
313
|
if (!content) return;
|
|
@@ -225,16 +326,42 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
225
326
|
this.lastRenderKeys = renderKeys;
|
|
226
327
|
}
|
|
227
328
|
|
|
228
|
-
updateGameObject(
|
|
329
|
+
updateGameObject(
|
|
330
|
+
scene: GameSceneIDE,
|
|
331
|
+
node: Editor2dNode,
|
|
332
|
+
depth: number,
|
|
333
|
+
renderKeys: string[],
|
|
334
|
+
isInside: boolean = false,
|
|
335
|
+
parentId?: string,
|
|
336
|
+
engineName?: string
|
|
337
|
+
): number {
|
|
229
338
|
const nodePath = Editor2dNode.getNodePath(node);
|
|
230
|
-
let children = (node.children as Editor2dNode[] || []).slice().reverse();
|
|
231
|
-
|
|
232
|
-
const
|
|
339
|
+
let children = ((node.children as Editor2dNode[]) || []).slice().reverse();
|
|
340
|
+
// console.log(this.data, scene, node);
|
|
341
|
+
const deco = this.opts.renderEngine.getGameObjectDecoration(
|
|
342
|
+
engineName || this.engineName,
|
|
343
|
+
node.displayType
|
|
344
|
+
);
|
|
345
|
+
if (node.parent) {
|
|
346
|
+
}
|
|
347
|
+
// console.log(deco);
|
|
348
|
+
const compId =
|
|
349
|
+
!Editor2dNode.isRootNode(node) && deco.getComponentId
|
|
350
|
+
? deco.getComponentId(node)
|
|
351
|
+
: undefined;
|
|
233
352
|
let adsorbable = true; // 是否可被吸附
|
|
234
|
-
const selectable: boolean =
|
|
353
|
+
const selectable: boolean =
|
|
354
|
+
!isInside &&
|
|
355
|
+
(!this.opts.isTemplate || !Editor2dNode.isTemplateDisabled(node)); // 是否可被选中
|
|
235
356
|
let childInside = false;
|
|
357
|
+
let componentScene: any;
|
|
236
358
|
if (compId) {
|
|
237
|
-
children = (this.opts.getComponentContent(compId, node) || [])
|
|
359
|
+
children = (this.opts.getComponentContent(compId, node) || [])
|
|
360
|
+
.slice()
|
|
361
|
+
.reverse()
|
|
362
|
+
.concat(children);
|
|
363
|
+
const component = this.opts.getComponentContent(compId, node, true);
|
|
364
|
+
componentScene = component?.[0].scene;
|
|
238
365
|
// 内部节点
|
|
239
366
|
childInside = true;
|
|
240
367
|
// 拥有内部节点的父节点无法被吸附
|
|
@@ -243,7 +370,15 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
243
370
|
// 子节点先创建
|
|
244
371
|
if (children && children.length > 0) {
|
|
245
372
|
for (const child of children) {
|
|
246
|
-
depth = this.updateGameObject(
|
|
373
|
+
depth = this.updateGameObject(
|
|
374
|
+
scene,
|
|
375
|
+
child,
|
|
376
|
+
depth,
|
|
377
|
+
renderKeys,
|
|
378
|
+
childInside || isInside,
|
|
379
|
+
nodePath,
|
|
380
|
+
componentScene?.engine || node.scene?.engine
|
|
381
|
+
);
|
|
247
382
|
}
|
|
248
383
|
}
|
|
249
384
|
const gameObjectCache = this.gameObjectCache;
|
|
@@ -257,62 +392,86 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
257
392
|
}
|
|
258
393
|
let firstCreate = false;
|
|
259
394
|
const nodeData = toNodeData(node, this.currentSymbols);
|
|
260
|
-
const newVersion =
|
|
395
|
+
const newVersion =
|
|
396
|
+
currentDepth +
|
|
397
|
+
(node.version || 0) +
|
|
398
|
+
':' +
|
|
399
|
+
(this.data?.configVersion || 0) +
|
|
400
|
+
':' +
|
|
401
|
+
this.symbolVersion;
|
|
261
402
|
// 内部节点无法选中
|
|
262
403
|
if (!gameObject) {
|
|
263
|
-
const gameObjectChildren = children
|
|
404
|
+
const gameObjectChildren = children
|
|
405
|
+
? children.map(c => gameObjectCache.get(Editor2dNode.getNodePath(c))!)
|
|
406
|
+
: [];
|
|
264
407
|
try {
|
|
265
408
|
const d = { ...nodeData, id: nodePath, depth: currentDepth, parentId };
|
|
266
409
|
if (d.mask) {
|
|
267
410
|
d.mask = `${parentId}/${d.mask}`;
|
|
268
411
|
}
|
|
269
|
-
|
|
412
|
+
if (compId && componentScene) {
|
|
413
|
+
d.scene = componentScene;
|
|
414
|
+
node.scene = componentScene;
|
|
415
|
+
}
|
|
416
|
+
gameObject = scene.createAuto(d, gameObjectChildren, engineName);
|
|
270
417
|
} catch (e) {
|
|
271
418
|
console.error(e);
|
|
272
419
|
return depth;
|
|
273
420
|
}
|
|
274
421
|
gameObjectCache.set(nodePath, gameObject);
|
|
422
|
+
const updateParent = (
|
|
423
|
+
node?: Editor2dNode,
|
|
424
|
+
obj?: GameObject,
|
|
425
|
+
type: GameObjectEventType = GameObjectEventType.UPDATE
|
|
426
|
+
) => {
|
|
427
|
+
// 如果父级是组件或分组更新中心点;
|
|
428
|
+
if (node && obj && !Editor2dNode.isRootNode(node)) {
|
|
429
|
+
this.onGameObjectChangeEmitter.fire({
|
|
430
|
+
type,
|
|
431
|
+
gameObject: obj!,
|
|
432
|
+
node: node!,
|
|
433
|
+
});
|
|
434
|
+
if (node.parent && obj.parent) {
|
|
435
|
+
updateParent(node.parent, obj.parent, type);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
275
439
|
scene.onGameObjectDispose(gameObject, () => {
|
|
276
|
-
const parentObject = parentId ? this.gameObjectCache.get(parentId) : undefined;
|
|
277
|
-
const parentNode = parentId ? this.nodeCache.get(parentId) : undefined;
|
|
278
440
|
const node = this.nodeCache.get(nodePath)!;
|
|
279
|
-
this.gameObjectCache.delete(nodePath);
|
|
280
|
-
this.nodeVersionCache.delete(nodePath);
|
|
281
|
-
this.nodeCache.delete(nodePath);
|
|
282
|
-
this.maskCache.delete(nodePath);
|
|
283
441
|
this.onGameObjectChangeEmitter.fire({
|
|
284
442
|
type: GameObjectEventType.DESTROY,
|
|
285
443
|
gameObject: gameObject!,
|
|
286
|
-
parentObject,
|
|
287
|
-
parentNode,
|
|
288
444
|
node,
|
|
289
445
|
});
|
|
446
|
+
updateParent(node, gameObject);
|
|
447
|
+
this.gameObjectCache.delete(nodePath);
|
|
448
|
+
this.nodeVersionCache.delete(nodePath);
|
|
449
|
+
this.nodeCache.delete(nodePath);
|
|
450
|
+
this.maskCache.delete(nodePath);
|
|
290
451
|
});
|
|
291
452
|
scene.onGameObjectUpdate(gameObject, () => {
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
this.onGameObjectChangeEmitter.fire({
|
|
453
|
+
const node = this.nodeCache.get(nodePath);
|
|
454
|
+
/* this.onGameObjectChangeEmitter.fire({
|
|
295
455
|
type: GameObjectEventType.UPDATE,
|
|
296
456
|
gameObject: gameObject!,
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
457
|
+
node: node!,
|
|
458
|
+
}); */
|
|
459
|
+
// 更新父级
|
|
460
|
+
updateParent(node, gameObject);
|
|
461
|
+
this.switchSnapline(node);
|
|
301
462
|
});
|
|
302
463
|
scene.onGameObjectCreate(gameObject, () => {
|
|
303
464
|
this.nodeVersionCache.set(nodePath, newVersion);
|
|
304
|
-
this.maskCache.set(nodePath, {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
type: GameObjectEventType.CREATE_READY,
|
|
309
|
-
gameObject: gameObject!,
|
|
310
|
-
node: this.nodeCache.get(nodePath)!,
|
|
311
|
-
parentObject,
|
|
312
|
-
parentNode
|
|
465
|
+
this.maskCache.set(nodePath, {
|
|
466
|
+
mask: node.mask,
|
|
467
|
+
isMask: node.isMask,
|
|
468
|
+
ignoreMask: node.ignoreMask,
|
|
313
469
|
});
|
|
314
470
|
// 根节点创建完成则代表加载完成
|
|
315
|
-
this.fireLoading(
|
|
471
|
+
this.fireLoading(
|
|
472
|
+
Editor2dNode.isRootNode(this.nodeCache.get(nodePath)!)
|
|
473
|
+
);
|
|
474
|
+
updateParent(this.nodeCache.get(nodePath), gameObject);
|
|
316
475
|
});
|
|
317
476
|
scene.onGameObjectError(gameObject, error => {
|
|
318
477
|
this.onGameObjectChangeEmitter.fire({
|
|
@@ -326,7 +485,7 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
326
485
|
type: GameObjectEventType.CREATE,
|
|
327
486
|
gameObject: gameObject!,
|
|
328
487
|
node: this.nodeCache.get(nodePath)!,
|
|
329
|
-
state: { selectable, adsorbable, isInside }
|
|
488
|
+
state: { selectable, adsorbable, isInside },
|
|
330
489
|
});
|
|
331
490
|
firstCreate = true;
|
|
332
491
|
}
|
|
@@ -337,14 +496,31 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
337
496
|
if (oldTexture.toString() !== newTexture.toString()) {
|
|
338
497
|
gameObject.dispose();
|
|
339
498
|
this.nodeCache.set(nodePath, node);
|
|
340
|
-
return this.updateGameObject(
|
|
499
|
+
return this.updateGameObject(
|
|
500
|
+
scene,
|
|
501
|
+
node,
|
|
502
|
+
currentDepth,
|
|
503
|
+
renderKeys,
|
|
504
|
+
isInside,
|
|
505
|
+
parentId
|
|
506
|
+
);
|
|
341
507
|
}
|
|
342
508
|
}
|
|
343
509
|
const update = () => {
|
|
344
510
|
const oldVersion = this.nodeVersionCache.get(nodePath);
|
|
345
511
|
const oldMask = this.maskCache.get(nodePath);
|
|
346
|
-
const maskChange =
|
|
347
|
-
|
|
512
|
+
const maskChange =
|
|
513
|
+
oldMask?.mask !== node.mask ||
|
|
514
|
+
oldMask?.isMask !== node.isMask ||
|
|
515
|
+
oldMask?.ignoreMask !== node.ignoreMask;
|
|
516
|
+
const compSceneChange =
|
|
517
|
+
JSON.stringify(componentScene) !== JSON.stringify(node.scene);
|
|
518
|
+
if (
|
|
519
|
+
nodeChanged ||
|
|
520
|
+
maskChange ||
|
|
521
|
+
oldVersion !== newVersion ||
|
|
522
|
+
compSceneChange
|
|
523
|
+
) {
|
|
348
524
|
const d = {
|
|
349
525
|
...nodeData,
|
|
350
526
|
parentId,
|
|
@@ -355,12 +531,20 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
355
531
|
if (d.mask) {
|
|
356
532
|
d.mask = `${parentId}/${d.mask}`;
|
|
357
533
|
}
|
|
534
|
+
if (compId && componentScene) {
|
|
535
|
+
d.scene = componentScene;
|
|
536
|
+
node.scene = componentScene;
|
|
537
|
+
}
|
|
358
538
|
gameObject!.update(d);
|
|
359
539
|
this.nodeVersionCache.set(nodePath, newVersion);
|
|
360
|
-
this.maskCache.set(nodePath, {
|
|
540
|
+
this.maskCache.set(nodePath, {
|
|
541
|
+
mask: node.mask,
|
|
542
|
+
isMask: node.isMask,
|
|
543
|
+
ignoreMask: node.ignoreMask,
|
|
544
|
+
});
|
|
361
545
|
}
|
|
362
546
|
};
|
|
363
|
-
if (!firstCreate && gameObject
|
|
547
|
+
if (!firstCreate && gameObject?.created) {
|
|
364
548
|
try {
|
|
365
549
|
update();
|
|
366
550
|
} catch (e) {
|
|
@@ -405,14 +589,21 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
405
589
|
this.draw();
|
|
406
590
|
}
|
|
407
591
|
|
|
408
|
-
setComponentSymbolsToLoader(
|
|
592
|
+
setComponentSymbolsToLoader(
|
|
593
|
+
scene: GameSceneIDE,
|
|
594
|
+
child: GameObjectData[] = []
|
|
595
|
+
): void {
|
|
409
596
|
child.forEach((item: ComponentGameObjectData) => {
|
|
410
597
|
if (item.displayType === GameObjectBaseType.COMPONENT && item.component) {
|
|
411
598
|
const { id } = item.component;
|
|
412
|
-
const compNode =
|
|
599
|
+
const compNode =
|
|
600
|
+
this.opts.getComponentContent(id, undefined, true) || [];
|
|
413
601
|
const comp = compNode[0];
|
|
414
602
|
if (comp && comp.component) {
|
|
415
|
-
const currentSymbols = getCurrentSymbols(
|
|
603
|
+
const currentSymbols = getCurrentSymbols(
|
|
604
|
+
this.data!.appConfig!,
|
|
605
|
+
comp
|
|
606
|
+
).filter(c => !this.currentSymbols.some(d => d.id === c.id));
|
|
416
607
|
// 变量数据更新
|
|
417
608
|
this.currentSymbols = this.currentSymbols.concat(currentSymbols);
|
|
418
609
|
this.addComponentSymbolsMetaToLoader(scene);
|
|
@@ -426,7 +617,10 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
426
617
|
|
|
427
618
|
symbolsToCurrent(scene: GameSceneIDE, content: Editor2dNode): void {
|
|
428
619
|
// const currentSymbols = getCurrentSymbols(this.data!.appConfig!, content);
|
|
429
|
-
const currentSymbols = getCurrentSymbols(
|
|
620
|
+
const currentSymbols = getCurrentSymbols(
|
|
621
|
+
this.data!.appConfig!,
|
|
622
|
+
content
|
|
623
|
+
).filter(c => !this.currentSymbols.some(d => d.id === c.id));
|
|
430
624
|
// 变量数据更新
|
|
431
625
|
if (JSON.stringify(currentSymbols) !== JSON.stringify(this.oldSymbols)) {
|
|
432
626
|
this.symbolVersion++;
|
|
@@ -448,6 +642,18 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
448
642
|
const { content, appConfig } = this.data;
|
|
449
643
|
if (!appConfig || !content) return undefined;
|
|
450
644
|
if (content.displayType === 'component') {
|
|
645
|
+
if (this.data.engineName === 'dom') {
|
|
646
|
+
const w = content.scene?.scrollXBool
|
|
647
|
+
? content.scene?.contentWidth || content.scene?.width
|
|
648
|
+
: content.scene?.width;
|
|
649
|
+
const h = content.scene?.scrollYBool
|
|
650
|
+
? content.scene?.contentHeight || content.scene?.height
|
|
651
|
+
: content.scene?.height;
|
|
652
|
+
return {
|
|
653
|
+
width: w || 400,
|
|
654
|
+
height: h || 400,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
451
657
|
return { width: 0, height: 0 };
|
|
452
658
|
}
|
|
453
659
|
return GameConfig.getSceneSize(appConfig, content);
|
|
@@ -462,9 +668,22 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
462
668
|
}
|
|
463
669
|
const size = this.getSceneSize();
|
|
464
670
|
if (!content || !appConfig || !this.libLoaded || !size) return;
|
|
465
|
-
|
|
671
|
+
this.engineName =
|
|
672
|
+
(content.displayType === GameObjectBaseType.COMPONENT &&
|
|
673
|
+
content.scene?.engine) ||
|
|
674
|
+
engineName;
|
|
675
|
+
const visibleChanged = this.toggleVisible(appConfig, visible);
|
|
466
676
|
if (!this.renderWidget || !this.booted) return;
|
|
467
|
-
|
|
677
|
+
|
|
678
|
+
let backgroundColor;
|
|
679
|
+
if (engineName === 'dom' && content.displayType === 'component') {
|
|
680
|
+
backgroundColor = content.scene?.backgroundColor;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const scene = this.renderWidget.switchScene(SCENE_KEY, {
|
|
684
|
+
size,
|
|
685
|
+
backgroundColor,
|
|
686
|
+
});
|
|
468
687
|
// 绘制时清除 currentSymbol;
|
|
469
688
|
this.currentSymbols = [];
|
|
470
689
|
/**
|