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