@gedit/editor-2d 0.2.47 → 0.2.49
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 +21 -7
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +169 -14
- package/lib/browser/model/editor2d-document.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 +148 -26
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +2 -2
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +57 -41
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/playground-contribution.d.ts +2 -0
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +19 -2
- 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 +19 -3
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/utils/snapshot.js +1 -1
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -9
- package/src/browser/model/editor2d-document.ts +183 -14
- package/src/browser/playground/canvas-draw.ts +308 -94
- package/src/browser/playground/canvas-layer.ts +41 -25
- package/src/browser/playground/playground-contribution.ts +15 -3
- package/src/browser/playground/selection-entity-manager.tsx +17 -3
- package/src/browser/style/index.less +6 -0
- package/src/browser/utils/snapshot.ts +1 -1
|
@@ -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,28 +392,40 @@ 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);
|
|
275
|
-
const updateParent = (
|
|
422
|
+
const updateParent = (
|
|
423
|
+
node?: Editor2dNode,
|
|
424
|
+
obj?: GameObject,
|
|
425
|
+
type: GameObjectEventType = GameObjectEventType.UPDATE
|
|
426
|
+
) => {
|
|
276
427
|
// 如果父级是组件或分组更新中心点;
|
|
277
|
-
if (
|
|
278
|
-
node &&
|
|
279
|
-
obj &&
|
|
280
|
-
!Editor2dNode.isRootNode(node)
|
|
281
|
-
) {
|
|
428
|
+
if (node && obj && !Editor2dNode.isRootNode(node)) {
|
|
282
429
|
this.onGameObjectChangeEmitter.fire({
|
|
283
430
|
type,
|
|
284
431
|
gameObject: obj!,
|
|
@@ -311,12 +458,19 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
311
458
|
}); */
|
|
312
459
|
// 更新父级
|
|
313
460
|
updateParent(node, gameObject);
|
|
461
|
+
this.switchSnapline(node);
|
|
314
462
|
});
|
|
315
463
|
scene.onGameObjectCreate(gameObject, () => {
|
|
316
464
|
this.nodeVersionCache.set(nodePath, newVersion);
|
|
317
|
-
this.maskCache.set(nodePath, {
|
|
465
|
+
this.maskCache.set(nodePath, {
|
|
466
|
+
mask: node.mask,
|
|
467
|
+
isMask: node.isMask,
|
|
468
|
+
ignoreMask: node.ignoreMask,
|
|
469
|
+
});
|
|
318
470
|
// 根节点创建完成则代表加载完成
|
|
319
|
-
this.fireLoading(
|
|
471
|
+
this.fireLoading(
|
|
472
|
+
Editor2dNode.isRootNode(this.nodeCache.get(nodePath)!)
|
|
473
|
+
);
|
|
320
474
|
updateParent(this.nodeCache.get(nodePath), gameObject);
|
|
321
475
|
});
|
|
322
476
|
scene.onGameObjectError(gameObject, error => {
|
|
@@ -331,7 +485,7 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
331
485
|
type: GameObjectEventType.CREATE,
|
|
332
486
|
gameObject: gameObject!,
|
|
333
487
|
node: this.nodeCache.get(nodePath)!,
|
|
334
|
-
state: { selectable, adsorbable, isInside }
|
|
488
|
+
state: { selectable, adsorbable, isInside },
|
|
335
489
|
});
|
|
336
490
|
firstCreate = true;
|
|
337
491
|
}
|
|
@@ -342,14 +496,31 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
342
496
|
if (oldTexture.toString() !== newTexture.toString()) {
|
|
343
497
|
gameObject.dispose();
|
|
344
498
|
this.nodeCache.set(nodePath, node);
|
|
345
|
-
return this.updateGameObject(
|
|
499
|
+
return this.updateGameObject(
|
|
500
|
+
scene,
|
|
501
|
+
node,
|
|
502
|
+
currentDepth,
|
|
503
|
+
renderKeys,
|
|
504
|
+
isInside,
|
|
505
|
+
parentId
|
|
506
|
+
);
|
|
346
507
|
}
|
|
347
508
|
}
|
|
348
509
|
const update = () => {
|
|
349
510
|
const oldVersion = this.nodeVersionCache.get(nodePath);
|
|
350
511
|
const oldMask = this.maskCache.get(nodePath);
|
|
351
|
-
const maskChange =
|
|
352
|
-
|
|
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
|
+
) {
|
|
353
524
|
const d = {
|
|
354
525
|
...nodeData,
|
|
355
526
|
parentId,
|
|
@@ -360,9 +531,17 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
360
531
|
if (d.mask) {
|
|
361
532
|
d.mask = `${parentId}/${d.mask}`;
|
|
362
533
|
}
|
|
534
|
+
if (compId && componentScene) {
|
|
535
|
+
d.scene = componentScene;
|
|
536
|
+
node.scene = componentScene;
|
|
537
|
+
}
|
|
363
538
|
gameObject!.update(d);
|
|
364
539
|
this.nodeVersionCache.set(nodePath, newVersion);
|
|
365
|
-
this.maskCache.set(nodePath, {
|
|
540
|
+
this.maskCache.set(nodePath, {
|
|
541
|
+
mask: node.mask,
|
|
542
|
+
isMask: node.isMask,
|
|
543
|
+
ignoreMask: node.ignoreMask,
|
|
544
|
+
});
|
|
366
545
|
}
|
|
367
546
|
};
|
|
368
547
|
if (!firstCreate && gameObject?.created) {
|
|
@@ -410,14 +589,21 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
410
589
|
this.draw();
|
|
411
590
|
}
|
|
412
591
|
|
|
413
|
-
setComponentSymbolsToLoader(
|
|
592
|
+
setComponentSymbolsToLoader(
|
|
593
|
+
scene: GameSceneIDE,
|
|
594
|
+
child: GameObjectData[] = []
|
|
595
|
+
): void {
|
|
414
596
|
child.forEach((item: ComponentGameObjectData) => {
|
|
415
597
|
if (item.displayType === GameObjectBaseType.COMPONENT && item.component) {
|
|
416
598
|
const { id } = item.component;
|
|
417
|
-
const compNode =
|
|
599
|
+
const compNode =
|
|
600
|
+
this.opts.getComponentContent(id, undefined, true) || [];
|
|
418
601
|
const comp = compNode[0];
|
|
419
602
|
if (comp && comp.component) {
|
|
420
|
-
const currentSymbols = getCurrentSymbols(
|
|
603
|
+
const currentSymbols = getCurrentSymbols(
|
|
604
|
+
this.data!.appConfig!,
|
|
605
|
+
comp
|
|
606
|
+
).filter(c => !this.currentSymbols.some(d => d.id === c.id));
|
|
421
607
|
// 变量数据更新
|
|
422
608
|
this.currentSymbols = this.currentSymbols.concat(currentSymbols);
|
|
423
609
|
this.addComponentSymbolsMetaToLoader(scene);
|
|
@@ -431,7 +617,10 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
431
617
|
|
|
432
618
|
symbolsToCurrent(scene: GameSceneIDE, content: Editor2dNode): void {
|
|
433
619
|
// const currentSymbols = getCurrentSymbols(this.data!.appConfig!, content);
|
|
434
|
-
const currentSymbols = getCurrentSymbols(
|
|
620
|
+
const currentSymbols = getCurrentSymbols(
|
|
621
|
+
this.data!.appConfig!,
|
|
622
|
+
content
|
|
623
|
+
).filter(c => !this.currentSymbols.some(d => d.id === c.id));
|
|
435
624
|
// 变量数据更新
|
|
436
625
|
if (JSON.stringify(currentSymbols) !== JSON.stringify(this.oldSymbols)) {
|
|
437
626
|
this.symbolVersion++;
|
|
@@ -453,6 +642,18 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
453
642
|
const { content, appConfig } = this.data;
|
|
454
643
|
if (!appConfig || !content) return undefined;
|
|
455
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
|
+
}
|
|
456
657
|
return { width: 0, height: 0 };
|
|
457
658
|
}
|
|
458
659
|
return GameConfig.getSceneSize(appConfig, content);
|
|
@@ -467,9 +668,22 @@ export class CanvasDraw extends DisposableImpl {
|
|
|
467
668
|
}
|
|
468
669
|
const size = this.getSceneSize();
|
|
469
670
|
if (!content || !appConfig || !this.libLoaded || !size) return;
|
|
470
|
-
|
|
671
|
+
this.engineName =
|
|
672
|
+
(content.displayType === GameObjectBaseType.COMPONENT &&
|
|
673
|
+
content.scene?.engine) ||
|
|
674
|
+
engineName;
|
|
675
|
+
const visibleChanged = this.toggleVisible(appConfig, visible);
|
|
471
676
|
if (!this.renderWidget || !this.booted) return;
|
|
472
|
-
|
|
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
|
+
});
|
|
473
687
|
// 绘制时清除 currentSymbol;
|
|
474
688
|
this.currentSymbols = [];
|
|
475
689
|
/**
|