@gedit/editor-2d 0.1.114 → 0.1.115
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/editor2d-context-key-service.js +24 -35
- package/lib/browser/editor2d-context-key-service.js.map +1 -1
- package/lib/browser/editor2d-contribution.js +89 -139
- package/lib/browser/editor2d-contribution.js.map +1 -1
- package/lib/browser/editor2d-frontend-module.js +20 -20
- package/lib/browser/editor2d-frontend-module.js.map +1 -1
- package/lib/browser/editor2d-label-provider.d.ts +0 -1
- package/lib/browser/editor2d-label-provider.d.ts.map +1 -1
- package/lib/browser/editor2d-label-provider.js +37 -58
- package/lib/browser/editor2d-label-provider.js.map +1 -1
- package/lib/browser/editor2d-model-provider.js +61 -127
- package/lib/browser/editor2d-model-provider.js.map +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.js +44 -110
- package/lib/browser/editor2d-ref-provider-contribution.js.map +1 -1
- package/lib/browser/editor2d-service.js +66 -85
- package/lib/browser/editor2d-service.js.map +1 -1
- package/lib/browser/model/editor2d-document.d.ts +1 -1
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +358 -526
- package/lib/browser/model/editor2d-document.js.map +1 -1
- package/lib/browser/model/editor2d-iterator.js +27 -67
- package/lib/browser/model/editor2d-iterator.js.map +1 -1
- package/lib/browser/model/editor2d-model-container.js +10 -21
- package/lib/browser/model/editor2d-model-container.js.map +1 -1
- package/lib/browser/model/editor2d-model.js +77 -92
- package/lib/browser/model/editor2d-model.js.map +1 -1
- package/lib/browser/model/editor2d-selection.js +16 -43
- package/lib/browser/model/editor2d-selection.js.map +1 -1
- package/lib/browser/model/editor2d-widget.js +71 -90
- package/lib/browser/model/editor2d-widget.js.map +1 -1
- package/lib/browser/model/editor2d.js +41 -127
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/model/utils/anim.utils.js +14 -14
- package/lib/browser/model/utils/anim.utils.js.map +1 -1
- package/lib/browser/playground/canvas-draw-layer.js +45 -69
- package/lib/browser/playground/canvas-draw-layer.js.map +1 -1
- package/lib/browser/playground/canvas-draw.js +142 -244
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.js +54 -101
- package/lib/browser/playground/canvas-layer.js.map +1 -1
- package/lib/browser/playground/entities/document-entity.js +8 -28
- package/lib/browser/playground/entities/document-entity.js.map +1 -1
- package/lib/browser/playground/entities/editor2d-entity.js +14 -37
- package/lib/browser/playground/entities/editor2d-entity.js.map +1 -1
- package/lib/browser/playground/playground-context.d.ts +3 -1
- package/lib/browser/playground/playground-context.d.ts.map +1 -1
- package/lib/browser/playground/playground-context.js +49 -47
- package/lib/browser/playground/playground-context.js.map +1 -1
- package/lib/browser/playground/playground-contribution.js +61 -65
- package/lib/browser/playground/playground-contribution.js.map +1 -1
- package/lib/browser/playground/selection-entity-manager.js +74 -132
- package/lib/browser/playground/selection-entity-manager.js.map +1 -1
- package/lib/browser/playground/selector-extend-icons.js +15 -16
- package/lib/browser/playground/selector-extend-icons.js.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.d.ts +3 -2
- package/lib/browser/playground/selector-extend-renderer.d.ts.map +1 -1
- package/lib/browser/playground/selector-extend-renderer.js +67 -52
- package/lib/browser/playground/selector-extend-renderer.js.map +1 -1
- package/lib/browser/utils/snapshot.js +81 -172
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +7 -7
- package/src/browser/editor2d-label-provider.ts +1 -15
- package/src/browser/model/editor2d-document.ts +6 -2
- package/src/browser/playground/playground-context.ts +2 -0
- package/src/browser/playground/selector-extend-renderer.tsx +43 -10
|
@@ -1,30 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
29
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
30
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -37,168 +11,100 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
37
11
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
38
12
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
39
13
|
};
|
|
40
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
51
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
-
function step(op) {
|
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
-
while (_) try {
|
|
56
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
-
switch (op[0]) {
|
|
59
|
-
case 0: case 1: t = op; break;
|
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
-
default:
|
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
-
if (t[2]) _.ops.pop();
|
|
69
|
-
_.trys.pop(); continue;
|
|
70
|
-
}
|
|
71
|
-
op = body.call(thisArg, _);
|
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var __values = (this && this.__values) || function(o) {
|
|
77
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
78
|
-
if (m) return m.call(o);
|
|
79
|
-
if (o && typeof o.length === "number") return {
|
|
80
|
-
next: function () {
|
|
81
|
-
if (o && i >= o.length) o = void 0;
|
|
82
|
-
return { value: o && o[i++], done: !o };
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
86
|
-
};
|
|
87
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
88
15
|
exports.Editor2dDocument = void 0;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
_this.fireContentChanged = function (nodes, type, noSave, noFiredChanged) {
|
|
16
|
+
const inversify_1 = require("inversify");
|
|
17
|
+
const utils_1 = require("@gedit/utils");
|
|
18
|
+
const editor2d_1 = require("./editor2d");
|
|
19
|
+
const render_engine_1 = require("@gedit/render-engine");
|
|
20
|
+
const render_engine_ide_1 = require("@gedit/render-engine-ide");
|
|
21
|
+
const tree_1 = require("@gedit/tree");
|
|
22
|
+
const browser_1 = require("@gedit/resource/lib/browser");
|
|
23
|
+
const connection_1 = require("@gedit/connection");
|
|
24
|
+
const workspace_2d_1 = require("@gedit/workspace-2d");
|
|
25
|
+
const resource_1 = require("@gedit/resource");
|
|
26
|
+
const app_config_1 = require("@gedit/app-config");
|
|
27
|
+
const editor2d_iterator_1 = require("./editor2d-iterator");
|
|
28
|
+
const utils_2 = require("./utils");
|
|
29
|
+
let versionId = 0;
|
|
30
|
+
let Editor2dDocument = class Editor2dDocument extends tree_1.TreeImpl {
|
|
31
|
+
constructor(message, options, resourceProivder, resourceAutoSaveService, resourceService, engineService, appConfig) {
|
|
32
|
+
super();
|
|
33
|
+
this.message = message;
|
|
34
|
+
this.options = options;
|
|
35
|
+
this.resourceProivder = resourceProivder;
|
|
36
|
+
this.resourceAutoSaveService = resourceAutoSaveService;
|
|
37
|
+
this.resourceService = resourceService;
|
|
38
|
+
this.engineService = engineService;
|
|
39
|
+
this.appConfig = appConfig;
|
|
40
|
+
this.onContentChangedEmitter = new utils_1.Emitter();
|
|
41
|
+
this.onSavedEmitter = new utils_1.Emitter();
|
|
42
|
+
this.onContentChanged = this.onContentChangedEmitter.event;
|
|
43
|
+
this.onSaved = this.onSavedEmitter.event;
|
|
44
|
+
this.animationStarted = false;
|
|
45
|
+
this.animationIds = []; // 当前正在录制的动画节点
|
|
46
|
+
this._localVersion = 0;
|
|
47
|
+
this._saveVersion = 0;
|
|
48
|
+
this.errors = [];
|
|
49
|
+
this.componentContents = {};
|
|
50
|
+
this._snaplines = [];
|
|
51
|
+
this.loading = true;
|
|
52
|
+
this.fireContentChanged = (nodes, type, noSave, noFiredChanged) => {
|
|
127
53
|
// TODO 这里修改目前还是全量的,需要优化
|
|
128
|
-
|
|
129
|
-
|
|
54
|
+
const contents = nodes.map(n => ({ text: 'treeNode' }));
|
|
55
|
+
this._localVersion = ++versionId;
|
|
130
56
|
if (!noFiredChanged) {
|
|
131
|
-
|
|
57
|
+
this.onContentChangedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
132
58
|
}
|
|
133
|
-
if (!
|
|
134
|
-
|
|
135
|
-
if (
|
|
136
|
-
|
|
59
|
+
if (!this.loading && !noSave) {
|
|
60
|
+
this._saveVersion++;
|
|
61
|
+
if (this._saveVersion === Number.MAX_VALUE) {
|
|
62
|
+
this._saveVersion = 0;
|
|
137
63
|
}
|
|
138
|
-
|
|
64
|
+
this.onSavedEmitter.fire({ document: this, contentChanges: contents, nodes, type });
|
|
139
65
|
}
|
|
140
66
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
67
|
+
this.refreshingNodes = new WeakMap();
|
|
68
|
+
this.toDispose.push(this.onContentChangedEmitter);
|
|
69
|
+
this.toDispose.push(this.onSavedEmitter);
|
|
144
70
|
// this.toDispose.
|
|
145
71
|
// this.toDispose.push(this.resourceAutoSaveService);
|
|
146
|
-
|
|
147
|
-
|
|
72
|
+
this.toDispose.push(this.resourceAutoSaveService.onSyncContent(content => this.reloadContent(content || '')));
|
|
73
|
+
this.toDispose.push(this.onSaved(event => this.resourceAutoSaveService.fireDidChangeContent(event)));
|
|
148
74
|
// TODO
|
|
149
75
|
// this.toDispose.push(this.resourceService.onRefsChange(async () => {
|
|
150
76
|
// await this.loadRefInfos();
|
|
151
77
|
// }));
|
|
152
78
|
// 同步数据
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
configurable: true
|
|
162
|
-
});
|
|
163
|
-
Object.defineProperty(Editor2dDocument.prototype, "engineName", {
|
|
164
|
-
get: function () {
|
|
165
|
-
return this.appConfig.engineName;
|
|
166
|
-
},
|
|
167
|
-
enumerable: false,
|
|
168
|
-
configurable: true
|
|
169
|
-
});
|
|
79
|
+
this.resourceAutoSaveService.sync();
|
|
80
|
+
}
|
|
81
|
+
get uri() {
|
|
82
|
+
return this.options.autoSaveService.resource.uri.toString();
|
|
83
|
+
}
|
|
84
|
+
get engineName() {
|
|
85
|
+
return this.appConfig.engineName;
|
|
86
|
+
}
|
|
170
87
|
/**
|
|
171
88
|
* 切换资源, 只有模板编辑器需要用到
|
|
172
89
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
uriObj = new utils_1.URI(uri);
|
|
180
|
-
return [4 /*yield*/, this.resourceProivder(uriObj)];
|
|
181
|
-
case 1:
|
|
182
|
-
resource = _a.sent();
|
|
183
|
-
this.resourceAutoSaveService.changeResource(resource);
|
|
184
|
-
this.resourceAutoSaveService.sync();
|
|
185
|
-
return [2 /*return*/];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
};
|
|
90
|
+
async changeResource(uri) {
|
|
91
|
+
const uriObj = new utils_1.URI(uri);
|
|
92
|
+
const resource = await this.resourceProivder(uriObj);
|
|
93
|
+
this.resourceAutoSaveService.changeResource(resource);
|
|
94
|
+
this.resourceAutoSaveService.sync();
|
|
95
|
+
}
|
|
190
96
|
/**
|
|
191
97
|
* 获取依赖的组件的内容
|
|
192
98
|
* @param compPath
|
|
193
99
|
* @param parentNode
|
|
194
100
|
*/
|
|
195
|
-
|
|
196
|
-
|
|
101
|
+
getComponentContent(compPath, parentNode) {
|
|
102
|
+
const comp = this.componentContents[compPath];
|
|
197
103
|
if (comp && comp.children)
|
|
198
|
-
return comp.children.map(
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
104
|
+
return comp.children.map(c => (Object.assign(Object.assign({}, c), { parent: parentNode })));
|
|
105
|
+
}
|
|
106
|
+
createDisplayNode(displayType, parent, position, index, data) {
|
|
107
|
+
let parentNode;
|
|
202
108
|
if (!parent || editor2d_1.Editor2dNode.isRootNode(parent)) {
|
|
203
109
|
parentNode = this.getNode(editor2d_1.Editor2dNode.ROOT_NODE_ID);
|
|
204
110
|
}
|
|
@@ -206,10 +112,10 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
206
112
|
parentNode = editor2d_1.Editor2dNode.toContainerNode(parent);
|
|
207
113
|
}
|
|
208
114
|
// const lastChild = parentNode.children.slice().reverse().find(c => c.position !== undefined);
|
|
209
|
-
|
|
115
|
+
const attrs = this.engineService.getDisplayDefaultData(this.engineName, displayType);
|
|
210
116
|
if (attrs.position) {
|
|
211
117
|
if (!position) {
|
|
212
|
-
|
|
118
|
+
const pos = 100 + Math.round(Math.random() * 100);
|
|
213
119
|
position = (displayType !== render_engine_1.GameObjectBaseType.GROUP && displayType !== render_engine_1.GameObjectBaseType.COMPONENT) ? { x: pos, y: pos } : { x: 0, y: 0 };
|
|
214
120
|
}
|
|
215
121
|
attrs.position.x = position.x;
|
|
@@ -222,23 +128,23 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
222
128
|
// // attrs.position.y = lastChild.position!.y + 20;
|
|
223
129
|
// }
|
|
224
130
|
}
|
|
225
|
-
|
|
226
|
-
|
|
131
|
+
const name = this.getUniqueName(parentNode.children || [], (data === null || data === void 0 ? void 0 : data.name) || this.engineService.getGameObjectIDERegister(this.engineName, displayType).decoration.name);
|
|
132
|
+
const node = editor2d_1.Editor2dNode.createNode(Object.assign(Object.assign(Object.assign({}, attrs), data), { name }), displayType, undefined, Object.keys(this.nodes));
|
|
227
133
|
this.addChildren(node, parentNode, index === undefined ? 0 : index);
|
|
228
134
|
return node;
|
|
229
|
-
}
|
|
230
|
-
|
|
135
|
+
}
|
|
136
|
+
copyNode(targetNode) {
|
|
231
137
|
if (!targetNode || editor2d_1.Editor2dNode.isRootNode(targetNode))
|
|
232
138
|
return;
|
|
233
|
-
|
|
139
|
+
const parent = targetNode.parent;
|
|
234
140
|
if (!this.canbeAddAsChild(parent, targetNode.displayType))
|
|
235
141
|
return;
|
|
236
|
-
|
|
237
|
-
|
|
142
|
+
const children = parent.children;
|
|
143
|
+
const index = children.findIndex(value => value.id === targetNode.id);
|
|
238
144
|
return this.copyToParentNode(parent, targetNode, index + 1);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
|
|
145
|
+
}
|
|
146
|
+
copyToParentNode(parentNode, nodeData, index, position) {
|
|
147
|
+
let parent = undefined;
|
|
242
148
|
if (this.canbeAddAsChild(parentNode, nodeData.displayType)) {
|
|
243
149
|
parent = parentNode;
|
|
244
150
|
}
|
|
@@ -246,14 +152,14 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
246
152
|
parent = parentNode.parent;
|
|
247
153
|
}
|
|
248
154
|
if (parent) {
|
|
249
|
-
|
|
155
|
+
const newNode = editor2d_1.Editor2dNode.clone(nodeData, [], Object.keys(this.nodes));
|
|
250
156
|
if (newNode.position) {
|
|
251
157
|
newNode.position.x = position ? position.x : newNode.position.x + 20;
|
|
252
158
|
newNode.position.y = position ? position.y : newNode.position.y + 20;
|
|
253
159
|
}
|
|
254
160
|
if (index === undefined) {
|
|
255
161
|
if (parent === parentNode.parent) {
|
|
256
|
-
index = parent.children.findIndex(
|
|
162
|
+
index = parent.children.findIndex(value => value.id === parentNode.id);
|
|
257
163
|
if (index < 0) {
|
|
258
164
|
index = 0;
|
|
259
165
|
}
|
|
@@ -262,9 +168,9 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
262
168
|
index = 0;
|
|
263
169
|
}
|
|
264
170
|
}
|
|
265
|
-
|
|
266
|
-
Object.assign(newNode, { name
|
|
267
|
-
|
|
171
|
+
const name = this.getUniqueName((parent.children || []), nodeData.name);
|
|
172
|
+
Object.assign(newNode, { name });
|
|
173
|
+
let children = parent.children;
|
|
268
174
|
if (!children) {
|
|
269
175
|
children = parent.children = [];
|
|
270
176
|
parent.expanded = true;
|
|
@@ -276,11 +182,11 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
276
182
|
this.fireContentChanged([newNode], 'add');
|
|
277
183
|
return newNode;
|
|
278
184
|
}
|
|
279
|
-
}
|
|
280
|
-
|
|
185
|
+
}
|
|
186
|
+
delNode(targetNode, silent) {
|
|
281
187
|
if (!targetNode || editor2d_1.Editor2dNode.isRootNode(targetNode))
|
|
282
188
|
return;
|
|
283
|
-
|
|
189
|
+
const parent = targetNode.parent;
|
|
284
190
|
this.removeNode(targetNode);
|
|
285
191
|
tree_1.CompositeTreeNode.removeChild(parent, targetNode);
|
|
286
192
|
if (!editor2d_1.Editor2dNode.isRootNode(parent) && parent.children.length === 0) {
|
|
@@ -290,25 +196,19 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
290
196
|
if (!silent) {
|
|
291
197
|
this.fireContentChanged([targetNode], 'delete');
|
|
292
198
|
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
var targetNodes = [];
|
|
297
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
298
|
-
targetNodes[_i] = arguments[_i];
|
|
299
|
-
}
|
|
300
|
-
targetNodes.forEach(function (node) { return _this.delNode(node, true); });
|
|
199
|
+
}
|
|
200
|
+
delNodes(...targetNodes) {
|
|
201
|
+
targetNodes.forEach(node => this.delNode(node, true));
|
|
301
202
|
if (targetNodes.length > 0) {
|
|
302
203
|
this.fireContentChanged(targetNodes, 'delete');
|
|
303
204
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
205
|
+
}
|
|
206
|
+
rename(targetNode, name) {
|
|
306
207
|
if (!name || !targetNode || editor2d_1.Editor2dNode.isRootNode(targetNode))
|
|
307
208
|
return;
|
|
308
|
-
this.updateNode(targetNode, { name
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (index === void 0) { index = 0; }
|
|
209
|
+
this.updateNode(targetNode, { name });
|
|
210
|
+
}
|
|
211
|
+
addChildren(node, parentNode, index = 0) {
|
|
312
212
|
if (node.parent) {
|
|
313
213
|
this.delNode(node, true);
|
|
314
214
|
}
|
|
@@ -320,21 +220,18 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
320
220
|
parentNode.expanded = true;
|
|
321
221
|
this.refresh(parentNode);
|
|
322
222
|
this.fireContentChanged([node], node.parent ? 'update' : 'add');
|
|
323
|
-
}
|
|
223
|
+
}
|
|
324
224
|
/**
|
|
325
225
|
* 打开节点
|
|
326
226
|
*/
|
|
327
|
-
|
|
328
|
-
if (expanded === void 0) { expanded = true; }
|
|
227
|
+
expandNode(node, expanded = true) {
|
|
329
228
|
if (tree_1.CompositeTreeNode.is(node)) {
|
|
330
229
|
node.expanded = expanded;
|
|
331
230
|
this.refresh(node);
|
|
332
231
|
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (forceUpdate === void 0) { forceUpdate = false; }
|
|
337
|
-
var treeNode = typeof node === 'string' ? this.nodes[node] : this.nodes[node.id];
|
|
232
|
+
}
|
|
233
|
+
updateNode(node, data = {}, forceUpdate = false, noSave, noFiredChanged) {
|
|
234
|
+
const treeNode = typeof node === 'string' ? this.nodes[node] : this.nodes[node.id];
|
|
338
235
|
if (!treeNode)
|
|
339
236
|
return;
|
|
340
237
|
// if (data.name) {
|
|
@@ -349,24 +246,27 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
349
246
|
console.error('无法覆盖同步节点数据: ', treeNode, data);
|
|
350
247
|
return;
|
|
351
248
|
}
|
|
352
|
-
|
|
249
|
+
const changed = forceUpdate ? true : utils_1.Compare.isDeepChanged(treeNode, data);
|
|
353
250
|
if (changed) {
|
|
354
251
|
Object.assign(treeNode, data);
|
|
355
252
|
treeNode.version = (treeNode.version || 0) + 1;
|
|
356
253
|
// this.refresh(treeNode as Editor2dContainerNode);
|
|
357
254
|
this.fireContentChanged([treeNode], 'update', noSave, noFiredChanged);
|
|
358
255
|
}
|
|
359
|
-
}
|
|
256
|
+
}
|
|
360
257
|
/**
|
|
361
258
|
* 检测节点名字,保证唯一
|
|
362
259
|
* @param siblings
|
|
363
|
-
* @param
|
|
260
|
+
* @param name
|
|
364
261
|
* @protected
|
|
365
262
|
*/
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (
|
|
263
|
+
getUniqueName(siblings, name, i = 0) {
|
|
264
|
+
const numMatched = name.match(/[0-9]+$/);
|
|
265
|
+
let newName = i ? `${name}${i}` : name;
|
|
266
|
+
if (numMatched) {
|
|
267
|
+
newName = name.slice(0, numMatched.index) + (parseInt(numMatched[0]) + i);
|
|
268
|
+
}
|
|
269
|
+
if (siblings.some(n => n.name === newName)) {
|
|
370
270
|
return this.getUniqueName(siblings, name, i + 1);
|
|
371
271
|
}
|
|
372
272
|
return newName;
|
|
@@ -381,22 +281,22 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
381
281
|
return this.getUniqueName(siblings, name, displayType);
|
|
382
282
|
}
|
|
383
283
|
return name; */
|
|
384
|
-
}
|
|
385
|
-
|
|
284
|
+
}
|
|
285
|
+
getSiblings(treeNode) {
|
|
386
286
|
if (treeNode.parent) {
|
|
387
|
-
return treeNode.parent.children.filter(
|
|
287
|
+
return treeNode.parent.children.filter(n => n !== treeNode);
|
|
388
288
|
}
|
|
389
289
|
return [];
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
290
|
+
}
|
|
291
|
+
reloadContent(content) {
|
|
292
|
+
let data = { version: this.version };
|
|
393
293
|
this.loading = true;
|
|
394
294
|
try {
|
|
395
295
|
data = JSON.parse(content || '{}');
|
|
396
296
|
}
|
|
397
297
|
catch (e) {
|
|
398
298
|
console.error(e);
|
|
399
|
-
this.message.error(
|
|
299
|
+
this.message.error(`文件 ${this.uri} 内容解析失败`);
|
|
400
300
|
}
|
|
401
301
|
if (data.content) {
|
|
402
302
|
this._localVersion = data.content.version;
|
|
@@ -413,111 +313,95 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
413
313
|
this.refresh();
|
|
414
314
|
this.loadRefInfos();
|
|
415
315
|
this.fireContentChanged([], 'add', true);
|
|
416
|
-
}
|
|
417
|
-
|
|
316
|
+
}
|
|
317
|
+
reloadEnd() {
|
|
418
318
|
if (this.loading) {
|
|
419
319
|
this.loading = false;
|
|
420
320
|
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
|
|
321
|
+
}
|
|
322
|
+
createRootNode() {
|
|
323
|
+
const root = editor2d_1.Editor2dNode.createRootNode(new utils_1.URI(this.uri));
|
|
424
324
|
if (root.displayType === render_engine_1.GameObjectBaseType.SCENE) {
|
|
425
|
-
|
|
325
|
+
const defaultData = this.engineService.getDisplayDefaultData(this.engineName, render_engine_1.GameObjectBaseType.SCENE);
|
|
426
326
|
Object.assign(root, defaultData);
|
|
427
327
|
}
|
|
428
328
|
return root;
|
|
429
|
-
}
|
|
430
|
-
|
|
329
|
+
}
|
|
330
|
+
save() {
|
|
431
331
|
return this.resourceAutoSaveService.save();
|
|
432
|
-
}
|
|
332
|
+
}
|
|
433
333
|
;
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
});
|
|
448
|
-
Object.defineProperty(Editor2dDocument.prototype, "onDirtyChanged", {
|
|
449
|
-
get: function () {
|
|
450
|
-
return this.resourceAutoSaveService.onDirtyChanged;
|
|
451
|
-
},
|
|
452
|
-
enumerable: false,
|
|
453
|
-
configurable: true
|
|
454
|
-
});
|
|
455
|
-
Editor2dDocument.prototype.toggleVisible = function (nodes, visible) {
|
|
456
|
-
var _this = this;
|
|
457
|
-
nodes.forEach(function (node) {
|
|
458
|
-
if (_this.checkDecoration(node, 'hidable')) {
|
|
459
|
-
_this.updateNode(node, { canvasHide: visible !== undefined ? !visible : !node.canvasHide });
|
|
334
|
+
get dirty() {
|
|
335
|
+
return this.resourceAutoSaveService.dirty;
|
|
336
|
+
}
|
|
337
|
+
get autoSave() {
|
|
338
|
+
return this.resourceAutoSaveService.autoSave;
|
|
339
|
+
}
|
|
340
|
+
get onDirtyChanged() {
|
|
341
|
+
return this.resourceAutoSaveService.onDirtyChanged;
|
|
342
|
+
}
|
|
343
|
+
toggleVisible(nodes, visible) {
|
|
344
|
+
nodes.forEach(node => {
|
|
345
|
+
if (this.checkDecoration(node, 'hidable')) {
|
|
346
|
+
this.updateNode(node, { canvasHide: visible !== undefined ? !visible : !node.canvasHide });
|
|
460
347
|
}
|
|
461
348
|
});
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
_this.updateNode(node, { locked: locked !== undefined ? locked : !node.locked });
|
|
349
|
+
}
|
|
350
|
+
toggleLock(nodes, locked) {
|
|
351
|
+
nodes.forEach(node => {
|
|
352
|
+
if (this.checkDecoration(node, 'lockable')) {
|
|
353
|
+
this.updateNode(node, { locked: locked !== undefined ? locked : !node.locked });
|
|
468
354
|
}
|
|
469
355
|
});
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
356
|
+
}
|
|
357
|
+
moveUp(node, toTop) {
|
|
358
|
+
const children = node.parent.children;
|
|
359
|
+
const targetNode = toTop ? children[0] : node.previousSibling;
|
|
474
360
|
if (targetNode) {
|
|
475
361
|
this.moveToNode(node, targetNode);
|
|
476
362
|
}
|
|
477
|
-
}
|
|
363
|
+
}
|
|
478
364
|
/**
|
|
479
365
|
* 上移动多个节点
|
|
480
366
|
* @param nodes
|
|
481
367
|
*/
|
|
482
|
-
|
|
483
|
-
var _this = this;
|
|
368
|
+
moveUpMore(nodes) {
|
|
484
369
|
nodes = nodes.length > 1
|
|
485
|
-
? nodes.slice().sort(
|
|
370
|
+
? nodes.slice().sort((n1, n2) => tree_1.CompositeTreeNode.indexOf(n1.parent, n1) - tree_1.CompositeTreeNode.indexOf(n2.parent, n2))
|
|
486
371
|
: nodes;
|
|
487
|
-
nodes.forEach(
|
|
488
|
-
}
|
|
372
|
+
nodes.forEach(n => this.moveUp(n));
|
|
373
|
+
}
|
|
489
374
|
/**
|
|
490
375
|
* 下移动多个节点
|
|
491
376
|
*/
|
|
492
|
-
|
|
493
|
-
var _this = this;
|
|
377
|
+
moveDownMore(nodes) {
|
|
494
378
|
nodes = nodes.length > 1
|
|
495
|
-
? nodes.slice().sort(
|
|
379
|
+
? nodes.slice().sort((n1, n2) => tree_1.CompositeTreeNode.indexOf(n2.parent, n2) - tree_1.CompositeTreeNode.indexOf(n1.parent, n1))
|
|
496
380
|
: nodes;
|
|
497
|
-
nodes.forEach(
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
381
|
+
nodes.forEach(n => this.moveDown(n));
|
|
382
|
+
}
|
|
383
|
+
moveDown(node, toBottom) {
|
|
384
|
+
const children = node.parent.children;
|
|
385
|
+
const targetNode = toBottom ? children[children.length - 1] : node.nextSibling;
|
|
502
386
|
if (targetNode) {
|
|
503
387
|
this.moveToNode(node, targetNode, true);
|
|
504
388
|
}
|
|
505
|
-
}
|
|
389
|
+
}
|
|
506
390
|
/**
|
|
507
391
|
* 移动到对应节点位置
|
|
508
392
|
* @param node
|
|
509
393
|
* @param targetNode
|
|
510
394
|
* @param toAfter - 是否加到目标节点的后边,默认前面
|
|
511
395
|
*/
|
|
512
|
-
|
|
396
|
+
moveToNode(node, targetNode, toAfter) {
|
|
513
397
|
if (editor2d_1.Editor2dNode.isRootNode(targetNode) || tree_1.TreeNode.equals(node, targetNode))
|
|
514
398
|
return;
|
|
515
|
-
|
|
516
|
-
|
|
399
|
+
const parent = targetNode.parent;
|
|
400
|
+
const children = parent.children;
|
|
517
401
|
this.delNode(node, true);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
402
|
+
const targetIndex = children.indexOf(targetNode);
|
|
403
|
+
const previousSibling = targetNode.previousSibling;
|
|
404
|
+
const nextSibling = targetNode.nextSibling;
|
|
521
405
|
// const uniqueName = this.getUniqueName(children, node.name!, node.displayType);
|
|
522
406
|
if (!toAfter) {
|
|
523
407
|
children.splice(targetIndex, 0, node);
|
|
@@ -527,8 +411,8 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
527
411
|
});
|
|
528
412
|
}
|
|
529
413
|
Object.assign(node, {
|
|
530
|
-
parent
|
|
531
|
-
previousSibling
|
|
414
|
+
parent,
|
|
415
|
+
previousSibling,
|
|
532
416
|
nextSibling: targetNode,
|
|
533
417
|
});
|
|
534
418
|
Object.assign(targetNode, {
|
|
@@ -541,9 +425,9 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
541
425
|
nextSibling: node
|
|
542
426
|
});
|
|
543
427
|
Object.assign(node, {
|
|
544
|
-
parent
|
|
428
|
+
parent,
|
|
545
429
|
previousSibling: targetNode,
|
|
546
|
-
nextSibling
|
|
430
|
+
nextSibling,
|
|
547
431
|
});
|
|
548
432
|
if (nextSibling) {
|
|
549
433
|
Object.assign(nextSibling, {
|
|
@@ -553,135 +437,132 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
553
437
|
}
|
|
554
438
|
this.refresh(parent);
|
|
555
439
|
this.fireContentChanged([node], 'update');
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
var _this = this;
|
|
440
|
+
}
|
|
441
|
+
moveToNodesAsChildren(nodes, targetNode) {
|
|
559
442
|
// 后边的先加
|
|
560
443
|
nodes = nodes.slice().reverse();
|
|
561
|
-
|
|
444
|
+
const canAddAsChild = !nodes.find(s => !this.canbeAddAsChild(targetNode, s.displayType, s));
|
|
562
445
|
if (canAddAsChild) {
|
|
563
|
-
nodes.forEach(
|
|
446
|
+
nodes.forEach(node => this.addChildren(node, targetNode, 0));
|
|
564
447
|
return true;
|
|
565
448
|
}
|
|
566
449
|
return false;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
var _this = this;
|
|
450
|
+
}
|
|
451
|
+
moveToNodesAsSiblings(nodes, targetNode) {
|
|
570
452
|
// 后边的先加
|
|
571
453
|
nodes = nodes.slice().reverse();
|
|
572
|
-
|
|
454
|
+
const canAddAsSibling = targetNode.parent && !nodes.find(s => !this.canbeAddAsChild(targetNode.parent, s.displayType, s));
|
|
573
455
|
if (canAddAsSibling) {
|
|
574
|
-
nodes.forEach(
|
|
575
|
-
|
|
456
|
+
nodes.forEach(node => {
|
|
457
|
+
this.moveToNode(node, targetNode, true);
|
|
576
458
|
});
|
|
577
459
|
return true;
|
|
578
460
|
}
|
|
579
461
|
return false;
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
|
|
462
|
+
}
|
|
463
|
+
getSelectedNodes() {
|
|
464
|
+
const nodes = [];
|
|
583
465
|
// eslint-disable-next-line guard-for-in
|
|
584
|
-
for (
|
|
585
|
-
|
|
466
|
+
for (const id in this.nodes) {
|
|
467
|
+
const node = this.nodes[id];
|
|
586
468
|
if (node && node.selected) {
|
|
587
469
|
nodes.push(node);
|
|
588
470
|
}
|
|
589
471
|
}
|
|
590
472
|
return nodes;
|
|
591
|
-
}
|
|
592
|
-
|
|
473
|
+
}
|
|
474
|
+
getNodeById(nodeId) {
|
|
593
475
|
return this.nodes[nodeId];
|
|
594
|
-
}
|
|
595
|
-
|
|
476
|
+
}
|
|
477
|
+
getNodeIcon(node) {
|
|
596
478
|
if (node.tags && node.tags.length > 0) {
|
|
597
|
-
|
|
598
|
-
|
|
479
|
+
const tagId = node.tags[0].id;
|
|
480
|
+
const tagIcon = this.appConfig.getTagIconClass(tagId);
|
|
599
481
|
if (tagIcon)
|
|
600
482
|
return tagIcon;
|
|
601
483
|
}
|
|
602
|
-
|
|
484
|
+
const register = this.engineService.getGameObjectIDERegister(this.engineName, node.displayType);
|
|
603
485
|
if (register && register.decoration && register.decoration.iconClass) {
|
|
604
486
|
return register.decoration.iconClass;
|
|
605
487
|
}
|
|
606
488
|
return '';
|
|
607
|
-
}
|
|
608
|
-
|
|
489
|
+
}
|
|
490
|
+
getNodeIconColor(node) {
|
|
609
491
|
if (node.tags && node.tags.length > 0) {
|
|
610
|
-
|
|
611
|
-
|
|
492
|
+
const tagId = node.tags[0].id;
|
|
493
|
+
const tagIcon = this.appConfig.getTagColorClass(tagId);
|
|
612
494
|
if (tagIcon)
|
|
613
495
|
return tagIcon;
|
|
614
496
|
}
|
|
615
497
|
return '';
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
return this.getSelectedNodes().filter(
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
|
|
498
|
+
}
|
|
499
|
+
getSelectedNodesWithoutRoot() {
|
|
500
|
+
return this.getSelectedNodes().filter(n => !editor2d_1.Editor2dNode.isRootNode(n));
|
|
501
|
+
}
|
|
502
|
+
isContainNode(parent, id) {
|
|
503
|
+
let target = this.nodes[id];
|
|
622
504
|
while (target) {
|
|
623
505
|
if (target.id === parent.id)
|
|
624
506
|
return true;
|
|
625
507
|
target = target.parent;
|
|
626
508
|
}
|
|
627
509
|
return false;
|
|
628
|
-
}
|
|
510
|
+
}
|
|
629
511
|
/**
|
|
630
512
|
* 合并分组
|
|
631
513
|
* @param nodes
|
|
632
514
|
*/
|
|
633
|
-
|
|
515
|
+
combineNodes(nodes) {
|
|
634
516
|
if (nodes.length > 0) {
|
|
635
517
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
518
|
+
const parent = nodes[0].parent;
|
|
519
|
+
const index = tree_1.CompositeTreeNode.indexOf(parent, nodes[0]);
|
|
520
|
+
const group = this.createDisplayNode(render_engine_1.GameObjectBaseType.GROUP, parent, undefined, index);
|
|
639
521
|
this.moveToNodesAsChildren(nodes, group);
|
|
640
522
|
}
|
|
641
|
-
}
|
|
523
|
+
}
|
|
642
524
|
/**
|
|
643
525
|
* 解除分组,目前只支持图层
|
|
644
526
|
* @param node
|
|
645
527
|
*/
|
|
646
|
-
|
|
647
|
-
var _this = this;
|
|
528
|
+
unCombineNode(node) {
|
|
648
529
|
if (node.children && node.parent) {
|
|
649
530
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
node.children.slice().reverse().forEach(
|
|
653
|
-
|
|
531
|
+
const parentNode = node.parent;
|
|
532
|
+
const curIndex = tree_1.CompositeTreeNode.indexOf(parentNode, node);
|
|
533
|
+
node.children.slice().reverse().forEach((n) => {
|
|
534
|
+
this.addChildren(n, parentNode, curIndex);
|
|
654
535
|
});
|
|
655
536
|
}
|
|
656
537
|
this.delNode(node);
|
|
657
|
-
}
|
|
538
|
+
}
|
|
658
539
|
/**
|
|
659
540
|
* 可以作为子节点
|
|
660
541
|
* @param targetNode
|
|
661
542
|
* @param childDisplayType
|
|
662
543
|
* @param childNode
|
|
663
544
|
*/
|
|
664
|
-
|
|
545
|
+
canbeAddAsChild(targetNode, childDisplayType, childNode) {
|
|
665
546
|
if (childNode && childNode.parent === targetNode)
|
|
666
547
|
return true;
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
548
|
+
const isRootNode = editor2d_1.Editor2dNode.isRootNode(targetNode);
|
|
549
|
+
const nodeDeco = this.engineService.getGameObjectDecoration(this.engineName, targetNode.displayType);
|
|
550
|
+
const childDeco = this.engineService.getGameObjectDecoration(this.engineName, childDisplayType);
|
|
551
|
+
const childTypes = typeof nodeDeco.childTypes === 'function' ? nodeDeco.childTypes(targetNode) : (nodeDeco.childTypes || []);
|
|
552
|
+
let checkParent = false;
|
|
672
553
|
if (childDeco.parentTypes !== undefined) {
|
|
673
|
-
checkParent = childDeco.parentTypes.find(
|
|
554
|
+
checkParent = childDeco.parentTypes.find(d => targetNode.displayType === d || (isRootNode && d === 'root') || nodeDeco.group === d) !== undefined;
|
|
674
555
|
if (checkParent && childDeco.parentIgnoreTypes !== undefined) {
|
|
675
|
-
checkParent = !childDeco.parentIgnoreTypes.find(
|
|
556
|
+
checkParent = !childDeco.parentIgnoreTypes.find(d => targetNode.displayType === d || (isRootNode && d === 'root') || nodeDeco.group === d);
|
|
676
557
|
}
|
|
677
558
|
}
|
|
678
|
-
|
|
679
|
-
|
|
559
|
+
const checkChildren = childTypes.find(d => childDisplayType === d || childDeco.group === d) !== undefined;
|
|
560
|
+
const checkSuccess = checkParent || checkChildren;
|
|
680
561
|
if (!checkSuccess)
|
|
681
562
|
return false;
|
|
682
|
-
|
|
563
|
+
const siblings = targetNode.children || [];
|
|
683
564
|
if (childDeco.single) {
|
|
684
|
-
|
|
565
|
+
const addedNodes = siblings.filter(s => s.displayType === childDisplayType);
|
|
685
566
|
if (addedNodes.length > 0)
|
|
686
567
|
return false;
|
|
687
568
|
}
|
|
@@ -689,42 +570,39 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
689
570
|
return childDeco.canbeAddedAsChild(targetNode, siblings);
|
|
690
571
|
}
|
|
691
572
|
return true;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
|
|
573
|
+
}
|
|
574
|
+
checkDecoration(node, decoKey) {
|
|
575
|
+
const deco = this.engineService.getGameObjectDecoration(this.engineName, node.displayType);
|
|
695
576
|
return deco[decoKey] === undefined || !!deco[decoKey];
|
|
696
|
-
}
|
|
697
|
-
|
|
577
|
+
}
|
|
578
|
+
setAnimationStarted(b) {
|
|
698
579
|
this.animationStarted = b;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
var _this = this;
|
|
580
|
+
}
|
|
581
|
+
startRecordAnimation(animationIds, onNodeChange) {
|
|
702
582
|
// this.animationStarted = true;
|
|
703
583
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
704
|
-
|
|
705
|
-
return n.children && n.children.some(function (c) { return c.id === id || getNodesToChildrenById(c, id); });
|
|
706
|
-
};
|
|
584
|
+
const getNodesToChildrenById = (n, id) => n.children && n.children.some((c) => c.id === id || getNodesToChildrenById(c, id));
|
|
707
585
|
this.animationIds = animationIds();
|
|
708
|
-
|
|
709
|
-
.map(
|
|
710
|
-
.map(
|
|
711
|
-
|
|
712
|
-
|
|
586
|
+
const cache = this.animationIds
|
|
587
|
+
.map(id => this.getNodeById(id)).filter(n => !!n)
|
|
588
|
+
.map(node => this.cloneNodeData(node));
|
|
589
|
+
const toDispose = this.onContentChanged(e => {
|
|
590
|
+
this.animationIds = animationIds();
|
|
713
591
|
// TODO 删除动画元件后,动画面板清空数据
|
|
714
592
|
if (e.nodes) {
|
|
715
|
-
|
|
593
|
+
const nodes = e.nodes.filter((n) => {
|
|
716
594
|
// 新建面板时,加入的元素先插入 cache 记录初始值
|
|
717
595
|
if (n && n.animation && n.displayType === render_engine_1.GameObjectBaseType.ANIMATION) {
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
if (!cache.some(
|
|
722
|
-
|
|
596
|
+
const { animation = {} } = n;
|
|
597
|
+
const { frames = {} } = animation || {};
|
|
598
|
+
frames.forEach((c) => {
|
|
599
|
+
if (!cache.some(d => d.id === c.id)) {
|
|
600
|
+
const node = this.cloneNodeData(this.getNodeById(c.id));
|
|
723
601
|
cache.push(node);
|
|
724
602
|
}
|
|
725
603
|
});
|
|
726
604
|
}
|
|
727
|
-
return
|
|
605
|
+
return this.animationIds.some(id => (id === n.id) || getNodesToChildrenById(n, id));
|
|
728
606
|
});
|
|
729
607
|
if (nodes.length) {
|
|
730
608
|
// TODO: 音乐素材变更
|
|
@@ -733,179 +611,142 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
733
611
|
}
|
|
734
612
|
});
|
|
735
613
|
return {
|
|
736
|
-
dispose:
|
|
614
|
+
dispose: () => {
|
|
737
615
|
toDispose.dispose();
|
|
738
616
|
// reset node data
|
|
739
|
-
cache.forEach(
|
|
740
|
-
|
|
741
|
-
|
|
617
|
+
cache.forEach(nodeData => {
|
|
618
|
+
const { displayType } = nodeData;
|
|
619
|
+
const currentNode = this.getNodeById(nodeData.id);
|
|
742
620
|
if (!currentNode) {
|
|
743
621
|
return;
|
|
744
622
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
623
|
+
const register = this.engineService.getGameObjectIDERegister(this.engineService.engineName, displayType);
|
|
624
|
+
const { timelineDisabledKeys = [], } = this.engineService.getGameObjectDecoration(this.engineService.engineName, displayType);
|
|
625
|
+
const keysList = (0, utils_2.getAnimationKeys)(this.engineService, register, timelineDisabledKeys);
|
|
626
|
+
const changeData = (0, utils_2.getChangeAnimationData)(keysList, currentNode, nodeData);
|
|
749
627
|
changeData.name = currentNode === null || currentNode === void 0 ? void 0 : currentNode.name;
|
|
750
|
-
|
|
628
|
+
this.updateNode(nodeData.id, changeData, true);
|
|
751
629
|
});
|
|
752
630
|
// this.animationStarted = false;
|
|
753
|
-
|
|
631
|
+
this.animationIds = [];
|
|
754
632
|
}
|
|
755
633
|
};
|
|
756
|
-
}
|
|
634
|
+
}
|
|
757
635
|
/**
|
|
758
636
|
* 同一个时间周期的refresh自动取消
|
|
759
637
|
* @param raw
|
|
760
638
|
*/
|
|
761
|
-
|
|
762
|
-
var _this = this;
|
|
639
|
+
refresh(raw) {
|
|
763
640
|
if (!raw)
|
|
764
|
-
return
|
|
765
|
-
|
|
641
|
+
return super.refresh();
|
|
642
|
+
const deferred = new utils_1.PromiseDeferred();
|
|
766
643
|
if (this.refreshingNodes.has(raw)) {
|
|
767
|
-
|
|
644
|
+
const cache = this.refreshingNodes.get(raw);
|
|
768
645
|
cache.deferred.resolve(undefined);
|
|
769
646
|
clearTimeout(cache.timeout);
|
|
770
647
|
this.refreshingNodes.delete(raw);
|
|
771
648
|
}
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
.then(
|
|
776
|
-
.catch(
|
|
649
|
+
const timeout = setTimeout(() => {
|
|
650
|
+
this.refreshingNodes.delete(raw);
|
|
651
|
+
super.refresh(raw)
|
|
652
|
+
.then(res => deferred.resolve(res))
|
|
653
|
+
.catch(rej => deferred.reject(rej));
|
|
777
654
|
});
|
|
778
655
|
// @ts-ignore
|
|
779
|
-
this.refreshingNodes.set(raw, { timeout
|
|
656
|
+
this.refreshingNodes.set(raw, { timeout, deferred });
|
|
780
657
|
return deferred.promise;
|
|
781
|
-
}
|
|
782
|
-
|
|
658
|
+
}
|
|
659
|
+
cloneNodeData(node) {
|
|
783
660
|
return (0, utils_1.deepClone)((0, utils_1.omit)(node, ['parent', 'previousSibling', 'nextSibling', 'selected', 'canvasHide', 'version']));
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
});
|
|
792
|
-
Object.defineProperty(Editor2dDocument.prototype, "length", {
|
|
793
|
-
get: function () {
|
|
794
|
-
return Object.keys(this.nodes).length;
|
|
795
|
-
},
|
|
796
|
-
enumerable: false,
|
|
797
|
-
configurable: true
|
|
798
|
-
});
|
|
661
|
+
}
|
|
662
|
+
get version() {
|
|
663
|
+
return this._localVersion;
|
|
664
|
+
}
|
|
665
|
+
get length() {
|
|
666
|
+
return Object.keys(this.nodes).length;
|
|
667
|
+
}
|
|
799
668
|
/**
|
|
800
669
|
* 检测错误
|
|
801
670
|
* @protected
|
|
802
671
|
*/
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
}
|
|
825
|
-
node.children = node.children ? node.children.map(function (c) { return normalize(c, version, node); }) : undefined;
|
|
826
|
-
return node;
|
|
827
|
-
};
|
|
828
|
-
this.componentContents = (0, utils_1.mapValues)(componentContents, function (value) { return value.content ? normalize(value.content, value.version) : undefined; });
|
|
829
|
-
return [4 /*yield*/, this.refresh()];
|
|
830
|
-
case 4:
|
|
831
|
-
_b.sent();
|
|
832
|
-
this.fireContentChanged([], 'add', true);
|
|
833
|
-
return [2 /*return*/];
|
|
834
|
-
}
|
|
835
|
-
});
|
|
836
|
-
});
|
|
837
|
-
};
|
|
838
|
-
Editor2dDocument.prototype.getWarningDesc = function (node) {
|
|
672
|
+
async loadRefInfos() {
|
|
673
|
+
const componentContents = await this.resourceService.getDependenciesContent(this.uri, u => !!u.match(/\.comp/));
|
|
674
|
+
// TODO 模板模式暂时不做资源依赖检测
|
|
675
|
+
if (!this.options.isTemplate) {
|
|
676
|
+
this.errors = await this.resourceService.checkRefsErrors(this.uri);
|
|
677
|
+
}
|
|
678
|
+
const normalize = (node, version, parent) => {
|
|
679
|
+
if (parent) {
|
|
680
|
+
node.parent = parent;
|
|
681
|
+
}
|
|
682
|
+
if (version !== undefined) {
|
|
683
|
+
node.version = version;
|
|
684
|
+
}
|
|
685
|
+
node.children = node.children ? node.children.map(c => normalize(c, version, node)) : undefined;
|
|
686
|
+
return node;
|
|
687
|
+
};
|
|
688
|
+
this.componentContents = (0, utils_1.mapValues)(componentContents, (value) => value.content ? normalize(value.content, value.version) : undefined);
|
|
689
|
+
await this.refresh();
|
|
690
|
+
this.fireContentChanged([], 'add', true);
|
|
691
|
+
}
|
|
692
|
+
getWarningDesc(node) {
|
|
839
693
|
if (node.error && node.error.message)
|
|
840
694
|
return node.error.message;
|
|
841
|
-
|
|
842
|
-
|
|
695
|
+
let uris = [];
|
|
696
|
+
const register = this.engineService.getGameObjectIDERegister(this.engineName, node.displayType);
|
|
843
697
|
if (register.getReferenceUris) {
|
|
844
698
|
uris = register.getReferenceUris(node);
|
|
845
699
|
}
|
|
846
700
|
else {
|
|
847
701
|
return undefined;
|
|
848
702
|
}
|
|
849
|
-
|
|
703
|
+
const error = this.errors.find(e => uris.includes(e.uri));
|
|
850
704
|
return error === null || error === void 0 ? void 0 : error.message;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
var e_1, _a;
|
|
705
|
+
}
|
|
706
|
+
queryNodesByTypes(types) {
|
|
854
707
|
if (!this.root)
|
|
855
708
|
return [];
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
if (node !== this.root && (!types || types.includes(node.displayType))) {
|
|
861
|
-
nodes.push(node);
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
866
|
-
finally {
|
|
867
|
-
try {
|
|
868
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
709
|
+
const nodes = [];
|
|
710
|
+
for (const node of new editor2d_iterator_1.Editor2dIterator(this.root)) {
|
|
711
|
+
if (node !== this.root && (!types || types.includes(node.displayType))) {
|
|
712
|
+
nodes.push(node);
|
|
869
713
|
}
|
|
870
|
-
finally { if (e_1) throw e_1.error; }
|
|
871
714
|
}
|
|
872
715
|
return nodes;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
|
|
716
|
+
}
|
|
717
|
+
nodeIdToGameObjectId(nodeId) {
|
|
718
|
+
const node = this.nodes[nodeId];
|
|
876
719
|
if (!node)
|
|
877
720
|
return '';
|
|
878
|
-
|
|
721
|
+
const objectId = editor2d_1.Editor2dNode.getNodePath(node);
|
|
879
722
|
return objectId;
|
|
880
|
-
}
|
|
723
|
+
}
|
|
881
724
|
/**
|
|
882
725
|
* 获取游戏对象
|
|
883
726
|
* @param nodeId
|
|
884
727
|
*/
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
728
|
+
getGameObjectById(nodeId) {
|
|
729
|
+
const objectId = this.nodeIdToGameObjectId(nodeId);
|
|
730
|
+
const game = this.engineService.getGameWidgetByUri(this.uri);
|
|
888
731
|
if (game) {
|
|
889
|
-
|
|
732
|
+
const scene = game.getCurrentScene();
|
|
890
733
|
if (scene) {
|
|
891
734
|
return scene.gameObjectStore.get(objectId);
|
|
892
735
|
}
|
|
893
736
|
}
|
|
894
|
-
}
|
|
737
|
+
}
|
|
895
738
|
/**
|
|
896
739
|
* 位置移动
|
|
897
740
|
* @param nodes
|
|
898
741
|
* @param type
|
|
899
742
|
* @param delta
|
|
900
743
|
*/
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
if (delta === void 0) { delta = 1; }
|
|
904
|
-
nodes = nodes.filter(function (node) { return node.position; });
|
|
744
|
+
positionMove(nodes, type, delta = 1) {
|
|
745
|
+
nodes = nodes.filter(node => node.position);
|
|
905
746
|
if (nodes.length === 0)
|
|
906
747
|
return;
|
|
907
|
-
|
|
908
|
-
|
|
748
|
+
let moveType = 'x';
|
|
749
|
+
let moveDelta = delta;
|
|
909
750
|
switch (type) {
|
|
910
751
|
case 'left':
|
|
911
752
|
moveDelta = -moveDelta;
|
|
@@ -920,58 +761,49 @@ var Editor2dDocument = /** @class */ (function (_super) {
|
|
|
920
761
|
moveType = 'y';
|
|
921
762
|
break;
|
|
922
763
|
}
|
|
923
|
-
nodes.forEach(
|
|
924
|
-
|
|
925
|
-
|
|
764
|
+
nodes.forEach(node => {
|
|
765
|
+
const position = node.position;
|
|
766
|
+
const newPosition = {
|
|
926
767
|
x: moveType === 'x' ? position.x + moveDelta : position.x,
|
|
927
768
|
y: moveType === 'y' ? position.y + moveDelta : position.y,
|
|
928
769
|
};
|
|
929
|
-
|
|
770
|
+
this.updateNode(node, { position: newPosition, }, true, true, true);
|
|
930
771
|
});
|
|
931
772
|
this.fireContentChanged(nodes, 'update');
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
get: function () {
|
|
948
|
-
return this._saveVersion;
|
|
949
|
-
},
|
|
950
|
-
enumerable: false,
|
|
951
|
-
configurable: true
|
|
952
|
-
});
|
|
953
|
-
Editor2dDocument.prototype.findIndex = function (node) {
|
|
954
|
-
var parent = node.parent;
|
|
773
|
+
}
|
|
774
|
+
get snaplines() {
|
|
775
|
+
return this._snaplines;
|
|
776
|
+
}
|
|
777
|
+
set snaplines(lines) {
|
|
778
|
+
this._snaplines = lines;
|
|
779
|
+
if (JSON.stringify(lines) !== JSON.stringify(this._snaplines)) {
|
|
780
|
+
this.fireContentChanged([], 'update');
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
get saveVersion() {
|
|
784
|
+
return this._saveVersion;
|
|
785
|
+
}
|
|
786
|
+
findIndex(node) {
|
|
787
|
+
const parent = node.parent;
|
|
955
788
|
if (parent) {
|
|
956
789
|
return parent.children.indexOf(node);
|
|
957
790
|
}
|
|
958
791
|
return 0;
|
|
959
|
-
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
}(tree_1.TreeImpl));
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
Editor2dDocument = __decorate([
|
|
795
|
+
(0, inversify_1.injectable)(),
|
|
796
|
+
__param(0, (0, inversify_1.inject)(connection_1.MessageService)),
|
|
797
|
+
__param(1, (0, inversify_1.inject)(editor2d_1.Editor2dModelOptions)),
|
|
798
|
+
__param(2, (0, inversify_1.inject)(resource_1.ResourceProvider)),
|
|
799
|
+
__param(3, (0, inversify_1.inject)(browser_1.ResourceAutoSaveService)),
|
|
800
|
+
__param(4, (0, inversify_1.inject)(workspace_2d_1.WorkspaceResourceService)),
|
|
801
|
+
__param(5, (0, inversify_1.inject)(render_engine_ide_1.RenderEngineIDEService)),
|
|
802
|
+
__param(6, (0, inversify_1.inject)(app_config_1.AppConfigService)),
|
|
803
|
+
__metadata("design:paramtypes", [connection_1.MessageService, Object, Function, browser_1.ResourceAutoSaveService,
|
|
804
|
+
workspace_2d_1.WorkspaceResourceService,
|
|
805
|
+
render_engine_ide_1.RenderEngineIDEService,
|
|
806
|
+
app_config_1.AppConfigService])
|
|
807
|
+
], Editor2dDocument);
|
|
976
808
|
exports.Editor2dDocument = Editor2dDocument;
|
|
977
809
|
//# sourceMappingURL=editor2d-document.js.map
|