@gedit/editor-2d 0.1.114 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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.d.ts +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.d.ts.map +1 -1
- package/lib/browser/editor2d-ref-provider-contribution.js +46 -112
- 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 +46 -20
- package/lib/browser/model/editor2d-document.d.ts.map +1 -1
- package/lib/browser/model/editor2d-document.js +602 -549
- 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.d.ts +8 -4
- package/lib/browser/model/editor2d.d.ts.map +1 -1
- package/lib/browser/model/editor2d.js +61 -128
- package/lib/browser/model/editor2d.js.map +1 -1
- package/lib/browser/model/utils/anim.utils.d.ts +3 -0
- package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
- package/lib/browser/model/utils/anim.utils.js +24 -18
- package/lib/browser/model/utils/anim.utils.js.map +1 -1
- package/lib/browser/playground/canvas-draw.d.ts +8 -0
- package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
- package/lib/browser/playground/canvas-draw.js +164 -252
- package/lib/browser/playground/canvas-draw.js.map +1 -1
- package/lib/browser/playground/canvas-layer.d.ts +10 -2
- package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
- package/lib/browser/playground/canvas-layer.js +78 -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/entities/extend-entity.d.ts +10 -0
- package/lib/browser/playground/entities/extend-entity.d.ts.map +1 -0
- package/lib/browser/playground/entities/extend-entity.js +34 -0
- package/lib/browser/playground/entities/extend-entity.js.map +1 -0
- package/lib/browser/playground/entities/index.d.ts +1 -0
- package/lib/browser/playground/entities/index.d.ts.map +1 -1
- package/lib/browser/playground/entities/index.js +1 -0
- package/lib/browser/playground/entities/index.js.map +1 -1
- package/lib/browser/playground/extend-edit-layer-point-event.d.ts +30 -0
- package/lib/browser/playground/extend-edit-layer-point-event.d.ts.map +1 -0
- package/lib/browser/playground/extend-edit-layer-point-event.js +50 -0
- package/lib/browser/playground/extend-edit-layer-point-event.js.map +1 -0
- package/lib/browser/playground/extend-edit-layer.d.ts +38 -0
- package/lib/browser/playground/extend-edit-layer.d.ts.map +1 -0
- package/lib/browser/playground/extend-edit-layer.js +335 -0
- package/lib/browser/playground/extend-edit-layer.js.map +1 -0
- package/lib/browser/playground/index.d.ts +1 -0
- package/lib/browser/playground/index.d.ts.map +1 -1
- package/lib/browser/playground/index.js +1 -0
- package/lib/browser/playground/index.js.map +1 -1
- package/lib/browser/playground/path-edit-layer-move-point.d.ts +15 -0
- package/lib/browser/playground/path-edit-layer-move-point.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer-move-point.js +47 -0
- package/lib/browser/playground/path-edit-layer-move-point.js.map +1 -0
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts +11 -0
- package/lib/browser/playground/path-edit-layer-svg-path.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer-svg-path.js +21 -0
- package/lib/browser/playground/path-edit-layer-svg-path.js.map +1 -0
- package/lib/browser/playground/path-edit-layer.d.ts +36 -0
- package/lib/browser/playground/path-edit-layer.d.ts.map +1 -0
- package/lib/browser/playground/path-edit-layer.js +257 -0
- package/lib/browser/playground/path-edit-layer.js.map +1 -0
- 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.d.ts +2 -0
- package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
- package/lib/browser/playground/playground-contribution.js +100 -67
- 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.d.ts.map +1 -1
- package/lib/browser/utils/snapshot.js +81 -172
- package/lib/browser/utils/snapshot.js.map +1 -1
- package/package.json +9 -7
- package/src/browser/editor2d-label-provider.ts +1 -15
- package/src/browser/editor2d-ref-provider-contribution.ts +8 -8
- package/src/browser/model/editor2d-document.ts +284 -51
- package/src/browser/model/editor2d.ts +21 -5
- package/src/browser/model/utils/anim.utils.ts +9 -2
- package/src/browser/playground/canvas-draw.ts +31 -17
- package/src/browser/playground/canvas-layer.ts +25 -3
- package/src/browser/playground/entities/extend-entity.ts +37 -0
- package/src/browser/playground/entities/index.ts +1 -0
- package/src/browser/playground/extend-edit-layer-point-event.tsx +71 -0
- package/src/browser/playground/extend-edit-layer.tsx +442 -0
- package/src/browser/playground/index.ts +1 -0
- package/src/browser/playground/path-edit-layer-move-point.tsx +71 -0
- package/src/browser/playground/path-edit-layer-svg-path.tsx +50 -0
- package/src/browser/playground/path-edit-layer.tsx +330 -0
- package/src/browser/playground/playground-context.ts +2 -0
- package/src/browser/playground/playground-contribution.ts +37 -3
- package/src/browser/playground/selector-extend-renderer.tsx +43 -10
- package/src/browser/style/canvas-layer.css +16 -0
- package/src/browser/style/extend-edit-layer.less +127 -0
- package/src/browser/style/index.less +2 -1
- package/src/browser/style/path-edit-layer.less +72 -0
- package/src/browser/svg/pen+.svg +24 -0
- package/src/browser/utils/snapshot.ts +1 -0
- package/lib/browser/playground/canvas-draw-layer.d.ts +0 -22
- package/lib/browser/playground/canvas-draw-layer.d.ts.map +0 -1
- package/lib/browser/playground/canvas-draw-layer.js +0 -126
- package/lib/browser/playground/canvas-draw-layer.js.map +0 -1
- package/src/browser/playground/canvas-draw-layer.tsx +0 -88
- package/src/browser/style/canvas-draw-layer.less +0 -24
|
@@ -1,84 +1,11 @@
|
|
|
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
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
-
function step(op) {
|
|
42
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
-
while (_) try {
|
|
44
|
-
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;
|
|
45
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
-
switch (op[0]) {
|
|
47
|
-
case 0: case 1: t = op; break;
|
|
48
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
-
default:
|
|
52
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
-
if (t[2]) _.ops.pop();
|
|
57
|
-
_.trys.pop(); continue;
|
|
58
|
-
}
|
|
59
|
-
op = body.call(thisArg, _);
|
|
60
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var __values = (this && this.__values) || function(o) {
|
|
65
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
66
|
-
if (m) return m.call(o);
|
|
67
|
-
if (o && typeof o.length === "number") return {
|
|
68
|
-
next: function () {
|
|
69
|
-
if (o && i >= o.length) o = void 0;
|
|
70
|
-
return { value: o && o[i++], done: !o };
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
74
|
-
};
|
|
75
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
76
3
|
exports.CanvasDraw = exports.GameObjectEventType = void 0;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
4
|
+
const render_engine_1 = require("@gedit/render-engine");
|
|
5
|
+
const editor2d_1 = require("../model/editor2d");
|
|
6
|
+
const utils_1 = require("@gedit/utils");
|
|
7
|
+
const WAIT_TO_DISPOSE_TIME = 30000; // 延迟删除, 这样tab在频繁切换时候不会有延迟
|
|
8
|
+
const SCENE_KEY = 'boot';
|
|
82
9
|
var GameObjectEventType;
|
|
83
10
|
(function (GameObjectEventType) {
|
|
84
11
|
GameObjectEventType[GameObjectEventType["CREATE"] = 0] = "CREATE";
|
|
@@ -89,24 +16,24 @@ var GameObjectEventType;
|
|
|
89
16
|
function replaceSymbolKey(originData, config, obj, path) {
|
|
90
17
|
if (!obj)
|
|
91
18
|
return originData;
|
|
92
|
-
(0, utils_1.each)(obj,
|
|
19
|
+
(0, utils_1.each)(obj, (v, key) => {
|
|
93
20
|
var _a;
|
|
94
|
-
|
|
21
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
95
22
|
if (typeof v === 'string') {
|
|
96
|
-
|
|
23
|
+
let matched = v.match(/^\$\{([^\}]+)\}$/);
|
|
97
24
|
// 旧的写法, TODO 暂时做兼容
|
|
98
25
|
if (!matched && key === 'textureId') {
|
|
99
26
|
matched = v.match(/^symbol\/(.+)/);
|
|
100
27
|
}
|
|
101
28
|
if (matched) {
|
|
102
|
-
|
|
103
|
-
|
|
29
|
+
const symbolId = matched[1];
|
|
30
|
+
const symbolValue = ((_a = config.symbols.find(s => s.id === symbolId)) === null || _a === void 0 ? void 0 : _a.value) || '';
|
|
104
31
|
originData = (0, utils_1.setByKey)(originData, currentPath, symbolValue, true, true);
|
|
105
32
|
}
|
|
106
33
|
}
|
|
107
34
|
else if (Array.isArray(v)) {
|
|
108
|
-
v.forEach(
|
|
109
|
-
originData = replaceSymbolKey(originData, config, item,
|
|
35
|
+
v.forEach((item, i) => {
|
|
36
|
+
originData = replaceSymbolKey(originData, config, item, `${currentPath}.${i}`);
|
|
110
37
|
});
|
|
111
38
|
}
|
|
112
39
|
else if (typeof v === 'object') {
|
|
@@ -116,59 +43,52 @@ function replaceSymbolKey(originData, config, obj, path) {
|
|
|
116
43
|
return originData;
|
|
117
44
|
}
|
|
118
45
|
function toNodeData(node, config) {
|
|
119
|
-
|
|
46
|
+
const originData = (0, utils_1.omit)(node, ['parent', 'previousSibling', 'nextSibling', 'children']);
|
|
120
47
|
return replaceSymbolKey(originData, config, originData);
|
|
121
48
|
}
|
|
122
49
|
;
|
|
123
50
|
/**
|
|
124
51
|
* 画布绘制逻辑
|
|
125
52
|
*/
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
53
|
+
class CanvasDraw extends utils_1.DisposableImpl {
|
|
54
|
+
constructor(opts) {
|
|
55
|
+
super();
|
|
56
|
+
this.opts = opts;
|
|
57
|
+
this.onDrawEmitter = new utils_1.Emitter();
|
|
58
|
+
this.onLoadingEmitter = new utils_1.Emitter();
|
|
59
|
+
this.onGameObjectChangeEmitter = new utils_1.Emitter();
|
|
60
|
+
this.onRenderWidgetCreateEmitter = new utils_1.Emitter();
|
|
61
|
+
this.booted = false;
|
|
62
|
+
this.libLoaded = false;
|
|
63
|
+
this.libLoading = false;
|
|
64
|
+
this.lastVisible = false;
|
|
65
|
+
this.gameObjectCache = new Map();
|
|
66
|
+
this.nodeCache = new Map();
|
|
67
|
+
this.nodeVersionCache = new Map();
|
|
68
|
+
this.maskCache = new Map();
|
|
69
|
+
this.lastRenderKeys = [];
|
|
70
|
+
this.allCount = -1;
|
|
71
|
+
this.onDraw = this.onDrawEmitter.event;
|
|
72
|
+
this.onLoading = this.onLoadingEmitter.event;
|
|
73
|
+
this.onGameObjectChange = this.onGameObjectChangeEmitter.event;
|
|
74
|
+
this.onRenderWidgetCreate = this.onRenderWidgetCreateEmitter.event;
|
|
75
|
+
this.loading = true;
|
|
76
|
+
this.lastZoom = 0.1;
|
|
77
|
+
this.toDispose.pushAll([
|
|
78
|
+
this.onDrawEmitter,
|
|
79
|
+
this.onLoadingEmitter,
|
|
80
|
+
this.onGameObjectChangeEmitter,
|
|
81
|
+
this.onRenderWidgetCreateEmitter,
|
|
152
82
|
]);
|
|
153
|
-
return _this;
|
|
154
83
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
_a.sent();
|
|
162
|
-
this.libLoaded = true;
|
|
163
|
-
this.draw();
|
|
164
|
-
return [2 /*return*/];
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
CanvasDraw.prototype.getData = function () {
|
|
84
|
+
async startLoadLibs() {
|
|
85
|
+
await this.opts.renderEngine.loadIDELibs();
|
|
86
|
+
this.libLoaded = true;
|
|
87
|
+
this.draw();
|
|
88
|
+
}
|
|
89
|
+
getData() {
|
|
170
90
|
return this.data;
|
|
171
|
-
}
|
|
91
|
+
}
|
|
172
92
|
/**
|
|
173
93
|
* 在不可见情况下,销毁gameObject,来提升性能
|
|
174
94
|
* @param appConfig
|
|
@@ -176,8 +96,7 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
176
96
|
* @param engineName
|
|
177
97
|
* @return visible changed
|
|
178
98
|
*/
|
|
179
|
-
|
|
180
|
-
var _this = this;
|
|
99
|
+
toggleVisible(appConfig, visible, engineName) {
|
|
181
100
|
var _a, _b;
|
|
182
101
|
if (this.waitToDispose) {
|
|
183
102
|
this.waitToDispose.dispose();
|
|
@@ -187,35 +106,37 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
187
106
|
if (appConfig.pixelArt !== this.pixelArt && this.renderWidget) {
|
|
188
107
|
this.renderWidget.dispose();
|
|
189
108
|
}
|
|
190
|
-
|
|
109
|
+
const isScene = new utils_1.URI((_a = this.data) === null || _a === void 0 ? void 0 : _a.uri).path.ext === '.scene';
|
|
191
110
|
// 组件模式用透明
|
|
192
|
-
|
|
111
|
+
const backgroundColor = isScene ? appConfig.backgroundColor : '';
|
|
193
112
|
this.pixelArt = appConfig.pixelArt;
|
|
194
113
|
if (visible && !this.renderWidget) {
|
|
195
|
-
|
|
196
|
-
this.opts.host.appendChild(
|
|
197
|
-
|
|
198
|
-
this.renderWidget = this.opts.renderEngine.createGameWidget(engineName,
|
|
199
|
-
this.renderWidget.toDispose.push(utils_1.Disposable.create(
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
114
|
+
const element = window.document.createElement('canvas');
|
|
115
|
+
this.opts.host.appendChild(element);
|
|
116
|
+
element.className = 'gedit-canvas-transparent';
|
|
117
|
+
this.renderWidget = this.opts.renderEngine.createGameWidget(engineName, Object.assign(Object.assign({}, appConfig), { width: 0, height: 0, uri: (_b = this.data) === null || _b === void 0 ? void 0 : _b.uri, canvas: element, backgroundColor, assetsURI: this.opts.assetsURI, isSnapshot: this.opts.isSnapshot, isIDE: true }));
|
|
118
|
+
this.renderWidget.toDispose.push(utils_1.Disposable.create(() => {
|
|
119
|
+
if (this.renderWidgetDispose) {
|
|
120
|
+
this.renderWidgetDispose.dispose();
|
|
121
|
+
this.renderWidgetDispose = undefined;
|
|
203
122
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
123
|
+
element.remove();
|
|
124
|
+
// this.opts.host.removeChild(element);
|
|
125
|
+
this.renderWidget = undefined;
|
|
126
|
+
this.booted = false;
|
|
127
|
+
this.loading = true;
|
|
128
|
+
this.onLoadingEmitter.fire({
|
|
209
129
|
loaded: false,
|
|
210
|
-
allCount:
|
|
130
|
+
allCount: this.allCount,
|
|
211
131
|
currentCount: 0,
|
|
212
132
|
reload: true,
|
|
213
133
|
});
|
|
214
134
|
}));
|
|
215
135
|
this.renderWidgetDispose = this.toDispose.push(this.renderWidget);
|
|
216
|
-
this.renderWidget.start().then(
|
|
217
|
-
|
|
218
|
-
|
|
136
|
+
Promise.resolve(this.renderWidget.start()).then(() => {
|
|
137
|
+
this.onRenderWidgetCreateEmitter.fire(this.renderWidget);
|
|
138
|
+
this.booted = true;
|
|
139
|
+
this.draw();
|
|
219
140
|
});
|
|
220
141
|
}
|
|
221
142
|
// 更新backgroundColor
|
|
@@ -224,12 +145,12 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
224
145
|
}
|
|
225
146
|
// 延迟删除不可见的游戏对象, 提升性能
|
|
226
147
|
if (!visible && this.renderWidget) {
|
|
227
|
-
|
|
228
|
-
if (
|
|
229
|
-
|
|
148
|
+
const timeoutId = setTimeout(() => {
|
|
149
|
+
if (this.renderWidget)
|
|
150
|
+
this.renderWidget.dispose();
|
|
230
151
|
}, WAIT_TO_DISPOSE_TIME);
|
|
231
|
-
this.waitToDispose = utils_1.Disposable.create(
|
|
232
|
-
window.clearTimeout(
|
|
152
|
+
this.waitToDispose = utils_1.Disposable.create(() => {
|
|
153
|
+
window.clearTimeout(timeoutId);
|
|
233
154
|
});
|
|
234
155
|
}
|
|
235
156
|
if (visible !== this.lastVisible) {
|
|
@@ -237,37 +158,33 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
237
158
|
return true;
|
|
238
159
|
}
|
|
239
160
|
return false;
|
|
240
|
-
}
|
|
161
|
+
}
|
|
241
162
|
;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var renderKeys = [];
|
|
163
|
+
updateGameObjects(scene, content) {
|
|
164
|
+
const renderKeys = [];
|
|
245
165
|
if (!content)
|
|
246
166
|
return;
|
|
247
167
|
this.allCount = this.updateGameObject(scene, content, 0, renderKeys);
|
|
248
168
|
// 删除节点
|
|
249
|
-
this.lastRenderKeys.forEach(
|
|
169
|
+
this.lastRenderKeys.forEach(key => {
|
|
250
170
|
if (!renderKeys.includes(key)) {
|
|
251
|
-
|
|
171
|
+
const obj = this.gameObjectCache.get(key);
|
|
252
172
|
if (obj) {
|
|
253
173
|
obj.dispose();
|
|
254
174
|
}
|
|
255
175
|
}
|
|
256
176
|
});
|
|
257
177
|
this.lastRenderKeys = renderKeys;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
var adsorbable = true; // 是否可被吸附
|
|
269
|
-
var selectable = !isInside && (!this.opts.isTemplate || !editor2d_1.Editor2dNode.isTemplateDisabled(node)); // 是否可被选中
|
|
270
|
-
var childInside = false;
|
|
178
|
+
}
|
|
179
|
+
updateGameObject(scene, node, depth, renderKeys, isInside = false, parentId) {
|
|
180
|
+
var _a;
|
|
181
|
+
const nodePath = editor2d_1.Editor2dNode.getNodePath(node);
|
|
182
|
+
let children = (node.children || []).slice().reverse();
|
|
183
|
+
const deco = this.opts.renderEngine.getGameObjectDecoration(this.data.engineName, node.displayType);
|
|
184
|
+
const compId = !editor2d_1.Editor2dNode.isRootNode(node) && deco.getComponentId ? deco.getComponentId(node) : undefined;
|
|
185
|
+
let adsorbable = true; // 是否可被吸附
|
|
186
|
+
const selectable = !isInside && (!this.opts.isTemplate || !editor2d_1.Editor2dNode.isTemplateDisabled(node)); // 是否可被选中
|
|
187
|
+
let childInside = false;
|
|
271
188
|
if (compId) {
|
|
272
189
|
children = (this.opts.getComponentContent(compId, node) || []).slice().reverse();
|
|
273
190
|
// 内部节点
|
|
@@ -277,92 +194,95 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
277
194
|
}
|
|
278
195
|
// 子节点先创建
|
|
279
196
|
if (children && children.length > 0) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
var child = children_1_1.value;
|
|
283
|
-
depth = this.updateGameObject(scene, child, depth, renderKeys, childInside || isInside, nodePath);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
287
|
-
finally {
|
|
288
|
-
try {
|
|
289
|
-
if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);
|
|
290
|
-
}
|
|
291
|
-
finally { if (e_1) throw e_1.error; }
|
|
197
|
+
for (const child of children) {
|
|
198
|
+
depth = this.updateGameObject(scene, child, depth, renderKeys, childInside || isInside, nodePath);
|
|
292
199
|
}
|
|
293
200
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
201
|
+
const gameObjectCache = this.gameObjectCache;
|
|
202
|
+
const currentDepth = depth;
|
|
203
|
+
const oldNode = this.nodeCache.get(nodePath);
|
|
204
|
+
const nodeChanged = node !== oldNode;
|
|
205
|
+
let gameObject = gameObjectCache.get(nodePath);
|
|
299
206
|
// 节点重置
|
|
300
207
|
if (nodeChanged) {
|
|
301
208
|
this.nodeCache.set(nodePath, node);
|
|
302
209
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
210
|
+
let firstCreate = false;
|
|
211
|
+
const nodeData = toNodeData(node, this.data.appConfig);
|
|
212
|
+
const newVersion = currentDepth + (node.version || 0) + ':' + (((_a = this.data) === null || _a === void 0 ? void 0 : _a.configVersion) || 0);
|
|
306
213
|
// 内部节点无法选中
|
|
307
214
|
if (!gameObject) {
|
|
308
|
-
|
|
215
|
+
const gameObjectChildren = children ? children.map(c => gameObjectCache.get(editor2d_1.Editor2dNode.getNodePath(c))) : [];
|
|
309
216
|
try {
|
|
310
|
-
|
|
217
|
+
const d = Object.assign(Object.assign({}, nodeData), { id: nodePath, depth: currentDepth, parentId });
|
|
218
|
+
if (d.mask) {
|
|
219
|
+
d.mask = `${parentId}/${d.mask}`;
|
|
220
|
+
}
|
|
221
|
+
gameObject = scene.createAuto(d, gameObjectChildren);
|
|
311
222
|
}
|
|
312
223
|
catch (e) {
|
|
313
224
|
console.error(e);
|
|
314
225
|
return depth;
|
|
315
226
|
}
|
|
316
227
|
gameObjectCache.set(nodePath, gameObject);
|
|
317
|
-
scene.onGameObjectDispose(gameObject,
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
228
|
+
scene.onGameObjectDispose(gameObject, () => {
|
|
229
|
+
this.gameObjectCache.delete(nodePath);
|
|
230
|
+
this.nodeVersionCache.delete(nodePath);
|
|
231
|
+
this.nodeCache.delete(nodePath);
|
|
232
|
+
this.maskCache.delete(nodePath);
|
|
233
|
+
this.onGameObjectChangeEmitter.fire({ type: GameObjectEventType.DESTROY, gameObject: gameObject, node: this.nodeCache.get(nodePath) });
|
|
322
234
|
});
|
|
323
|
-
scene.onGameObjectUpdate(gameObject,
|
|
324
|
-
|
|
235
|
+
scene.onGameObjectUpdate(gameObject, () => {
|
|
236
|
+
this.onGameObjectChangeEmitter.fire({
|
|
325
237
|
type: GameObjectEventType.UPDATE,
|
|
326
238
|
gameObject: gameObject,
|
|
327
|
-
node:
|
|
239
|
+
node: this.nodeCache.get(nodePath),
|
|
328
240
|
});
|
|
329
241
|
});
|
|
330
|
-
scene.onGameObjectCreate(gameObject,
|
|
331
|
-
|
|
242
|
+
scene.onGameObjectCreate(gameObject, () => {
|
|
243
|
+
this.nodeVersionCache.set(nodePath, newVersion);
|
|
244
|
+
this.maskCache.set(nodePath, { mask: node.mask, isMask: node.isMask, ignoreMask: node.ignoreMask });
|
|
332
245
|
// 根节点创建完成则代表加载完成
|
|
333
|
-
|
|
246
|
+
this.fireLoading(editor2d_1.Editor2dNode.isRootNode(this.nodeCache.get(nodePath)));
|
|
334
247
|
});
|
|
335
|
-
scene.onGameObjectError(gameObject,
|
|
336
|
-
|
|
248
|
+
scene.onGameObjectError(gameObject, error => {
|
|
249
|
+
this.onGameObjectChangeEmitter.fire({
|
|
337
250
|
type: GameObjectEventType.ERROR,
|
|
338
251
|
gameObject: gameObject,
|
|
339
|
-
node:
|
|
340
|
-
error
|
|
252
|
+
node: this.nodeCache.get(nodePath),
|
|
253
|
+
error,
|
|
341
254
|
});
|
|
342
255
|
});
|
|
343
256
|
this.onGameObjectChangeEmitter.fire({
|
|
344
257
|
type: GameObjectEventType.CREATE,
|
|
345
258
|
gameObject: gameObject,
|
|
346
259
|
node: this.nodeCache.get(nodePath),
|
|
347
|
-
state: { selectable
|
|
260
|
+
state: { selectable, adsorbable, isInside }
|
|
348
261
|
});
|
|
349
262
|
firstCreate = true;
|
|
350
263
|
}
|
|
351
|
-
if (gameObject && gameObject.
|
|
352
|
-
|
|
353
|
-
|
|
264
|
+
if (gameObject && gameObject.needResource) {
|
|
265
|
+
const oldTexture = gameObject.data.textureId || '';
|
|
266
|
+
const newTexture = nodeData.textureId || '';
|
|
354
267
|
// 素材更新则销毁重新创建
|
|
355
|
-
if (oldTexture !== newTexture) {
|
|
268
|
+
if (oldTexture.toString() !== newTexture.toString()) {
|
|
356
269
|
gameObject.dispose();
|
|
357
270
|
this.nodeCache.set(nodePath, node);
|
|
358
271
|
return this.updateGameObject(scene, node, currentDepth, renderKeys, isInside, parentId);
|
|
359
272
|
}
|
|
360
273
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
274
|
+
const update = () => {
|
|
275
|
+
const oldVersion = this.nodeVersionCache.get(nodePath);
|
|
276
|
+
const oldMask = this.maskCache.get(nodePath);
|
|
277
|
+
const maskChange = (oldMask === null || oldMask === void 0 ? void 0 : oldMask.mask) !== node.mask || (oldMask === null || oldMask === void 0 ? void 0 : oldMask.isMask) !== node.isMask || (oldMask === null || oldMask === void 0 ? void 0 : oldMask.ignoreMask) !== node.ignoreMask;
|
|
278
|
+
if (nodeChanged || maskChange || oldVersion !== newVersion) {
|
|
279
|
+
const d = Object.assign(Object.assign({}, nodeData), { parentId, id: nodePath, textureId: nodeData.textureId, depth: currentDepth });
|
|
280
|
+
if (d.mask) {
|
|
281
|
+
d.mask = `${parentId}/${d.mask}`;
|
|
282
|
+
}
|
|
283
|
+
gameObject.update(d);
|
|
284
|
+
this.nodeVersionCache.set(nodePath, newVersion);
|
|
285
|
+
this.maskCache.set(nodePath, { mask: node.mask, isMask: node.isMask, ignoreMask: node.ignoreMask });
|
|
366
286
|
}
|
|
367
287
|
};
|
|
368
288
|
if (!firstCreate && gameObject.created) {
|
|
@@ -376,62 +296,60 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
376
296
|
renderKeys.push(nodePath);
|
|
377
297
|
depth++;
|
|
378
298
|
return depth;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
299
|
+
}
|
|
300
|
+
fireLoading(allLoaded) {
|
|
301
|
+
const allCount = this.allCount;
|
|
302
|
+
const currentCount = this.nodeVersionCache.size;
|
|
383
303
|
if (allLoaded) {
|
|
384
304
|
this.loading = false;
|
|
385
305
|
}
|
|
386
306
|
this.onLoadingEmitter.fire({
|
|
387
307
|
loaded: allLoaded,
|
|
388
|
-
allCount
|
|
389
|
-
currentCount
|
|
308
|
+
allCount,
|
|
309
|
+
currentCount,
|
|
390
310
|
});
|
|
391
|
-
}
|
|
392
|
-
|
|
311
|
+
}
|
|
312
|
+
refreshScale(delayDraw = true, zoom = this.lastZoom) {
|
|
393
313
|
var _a, _b;
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
var visible = (_a = this.data) === null || _a === void 0 ? void 0 : _a.visible;
|
|
397
|
-
var scene = (_b = this.renderWidget) === null || _b === void 0 ? void 0 : _b.currentScene;
|
|
314
|
+
const visible = (_a = this.data) === null || _a === void 0 ? void 0 : _a.visible;
|
|
315
|
+
const scene = (_b = this.renderWidget) === null || _b === void 0 ? void 0 : _b.currentScene;
|
|
398
316
|
this.lastZoom = zoom;
|
|
399
317
|
if (scene) {
|
|
400
318
|
// 隐藏的画布把像素点降低减少内存消耗
|
|
401
319
|
scene.setScale(visible ? zoom : 0.1, delayDraw);
|
|
402
320
|
}
|
|
403
|
-
}
|
|
404
|
-
|
|
321
|
+
}
|
|
322
|
+
update(data) {
|
|
405
323
|
this.data = data;
|
|
406
324
|
this.draw();
|
|
407
|
-
}
|
|
325
|
+
}
|
|
408
326
|
/**
|
|
409
327
|
* 获取画布的宽高
|
|
410
328
|
*/
|
|
411
|
-
|
|
329
|
+
getSceneSize() {
|
|
412
330
|
if (!this.data)
|
|
413
331
|
return undefined;
|
|
414
|
-
|
|
332
|
+
const { content, appConfig } = this.data;
|
|
415
333
|
if (!appConfig || !content)
|
|
416
334
|
return undefined;
|
|
417
335
|
return render_engine_1.GameConfig.getSceneSize(appConfig, content);
|
|
418
|
-
}
|
|
419
|
-
|
|
336
|
+
}
|
|
337
|
+
draw() {
|
|
420
338
|
if (!this.data)
|
|
421
339
|
return;
|
|
422
|
-
|
|
340
|
+
const { visible, appConfig, content, engineName } = this.data;
|
|
423
341
|
if (!this.libLoaded && !this.libLoading) {
|
|
424
342
|
this.libLoading = true;
|
|
425
343
|
this.startLoadLibs();
|
|
426
344
|
return;
|
|
427
345
|
}
|
|
428
|
-
|
|
346
|
+
const size = this.getSceneSize();
|
|
429
347
|
if (!content || !appConfig || !this.libLoaded || !size)
|
|
430
348
|
return;
|
|
431
|
-
|
|
349
|
+
const visibleChanged = this.toggleVisible(appConfig, visible, engineName);
|
|
432
350
|
if (!this.renderWidget || !this.booted)
|
|
433
351
|
return;
|
|
434
|
-
|
|
352
|
+
const scene = this.renderWidget.switchScene(SCENE_KEY, size);
|
|
435
353
|
/**
|
|
436
354
|
* 更新画布大小
|
|
437
355
|
*/
|
|
@@ -444,14 +362,8 @@ var CanvasDraw = /** @class */ (function (_super) {
|
|
|
444
362
|
* 加载scene的资源文件并渲染
|
|
445
363
|
*/
|
|
446
364
|
this.renderWidget.loadCurrentScene();
|
|
447
|
-
/**
|
|
448
|
-
* 动态计算画布宽高
|
|
449
|
-
*/
|
|
450
|
-
// const enlargeBounds = this.selectionEntityManager.getEntityEnlargeBounds(CANVAS_MIN_WIDTH, CANVAS_MIN_HEIGHT);
|
|
451
|
-
// this.renderWidget.updateCanvasBounds(enlargeBounds);
|
|
452
365
|
this.onDrawEmitter.fire(size);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
}(utils_1.DisposableImpl));
|
|
366
|
+
}
|
|
367
|
+
}
|
|
456
368
|
exports.CanvasDraw = CanvasDraw;
|
|
457
369
|
//# sourceMappingURL=canvas-draw.js.map
|