@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.
Files changed (134) hide show
  1. package/lib/browser/editor2d-context-key-service.js +24 -35
  2. package/lib/browser/editor2d-context-key-service.js.map +1 -1
  3. package/lib/browser/editor2d-contribution.js +89 -139
  4. package/lib/browser/editor2d-contribution.js.map +1 -1
  5. package/lib/browser/editor2d-frontend-module.js +20 -20
  6. package/lib/browser/editor2d-frontend-module.js.map +1 -1
  7. package/lib/browser/editor2d-label-provider.d.ts +0 -1
  8. package/lib/browser/editor2d-label-provider.d.ts.map +1 -1
  9. package/lib/browser/editor2d-label-provider.js +37 -58
  10. package/lib/browser/editor2d-label-provider.js.map +1 -1
  11. package/lib/browser/editor2d-model-provider.js +61 -127
  12. package/lib/browser/editor2d-model-provider.js.map +1 -1
  13. package/lib/browser/editor2d-ref-provider-contribution.d.ts +1 -1
  14. package/lib/browser/editor2d-ref-provider-contribution.d.ts.map +1 -1
  15. package/lib/browser/editor2d-ref-provider-contribution.js +46 -112
  16. package/lib/browser/editor2d-ref-provider-contribution.js.map +1 -1
  17. package/lib/browser/editor2d-service.js +66 -85
  18. package/lib/browser/editor2d-service.js.map +1 -1
  19. package/lib/browser/model/editor2d-document.d.ts +46 -20
  20. package/lib/browser/model/editor2d-document.d.ts.map +1 -1
  21. package/lib/browser/model/editor2d-document.js +602 -549
  22. package/lib/browser/model/editor2d-document.js.map +1 -1
  23. package/lib/browser/model/editor2d-iterator.js +27 -67
  24. package/lib/browser/model/editor2d-iterator.js.map +1 -1
  25. package/lib/browser/model/editor2d-model-container.js +10 -21
  26. package/lib/browser/model/editor2d-model-container.js.map +1 -1
  27. package/lib/browser/model/editor2d-model.js +77 -92
  28. package/lib/browser/model/editor2d-model.js.map +1 -1
  29. package/lib/browser/model/editor2d-selection.js +16 -43
  30. package/lib/browser/model/editor2d-selection.js.map +1 -1
  31. package/lib/browser/model/editor2d-widget.js +71 -90
  32. package/lib/browser/model/editor2d-widget.js.map +1 -1
  33. package/lib/browser/model/editor2d.d.ts +8 -4
  34. package/lib/browser/model/editor2d.d.ts.map +1 -1
  35. package/lib/browser/model/editor2d.js +61 -128
  36. package/lib/browser/model/editor2d.js.map +1 -1
  37. package/lib/browser/model/utils/anim.utils.d.ts +3 -0
  38. package/lib/browser/model/utils/anim.utils.d.ts.map +1 -1
  39. package/lib/browser/model/utils/anim.utils.js +24 -18
  40. package/lib/browser/model/utils/anim.utils.js.map +1 -1
  41. package/lib/browser/playground/canvas-draw.d.ts +8 -0
  42. package/lib/browser/playground/canvas-draw.d.ts.map +1 -1
  43. package/lib/browser/playground/canvas-draw.js +164 -252
  44. package/lib/browser/playground/canvas-draw.js.map +1 -1
  45. package/lib/browser/playground/canvas-layer.d.ts +10 -2
  46. package/lib/browser/playground/canvas-layer.d.ts.map +1 -1
  47. package/lib/browser/playground/canvas-layer.js +78 -102
  48. package/lib/browser/playground/canvas-layer.js.map +1 -1
  49. package/lib/browser/playground/entities/document-entity.js +8 -28
  50. package/lib/browser/playground/entities/document-entity.js.map +1 -1
  51. package/lib/browser/playground/entities/editor2d-entity.js +14 -37
  52. package/lib/browser/playground/entities/editor2d-entity.js.map +1 -1
  53. package/lib/browser/playground/entities/extend-entity.d.ts +10 -0
  54. package/lib/browser/playground/entities/extend-entity.d.ts.map +1 -0
  55. package/lib/browser/playground/entities/extend-entity.js +34 -0
  56. package/lib/browser/playground/entities/extend-entity.js.map +1 -0
  57. package/lib/browser/playground/entities/index.d.ts +1 -0
  58. package/lib/browser/playground/entities/index.d.ts.map +1 -1
  59. package/lib/browser/playground/entities/index.js +1 -0
  60. package/lib/browser/playground/entities/index.js.map +1 -1
  61. package/lib/browser/playground/extend-edit-layer-point-event.d.ts +30 -0
  62. package/lib/browser/playground/extend-edit-layer-point-event.d.ts.map +1 -0
  63. package/lib/browser/playground/extend-edit-layer-point-event.js +50 -0
  64. package/lib/browser/playground/extend-edit-layer-point-event.js.map +1 -0
  65. package/lib/browser/playground/extend-edit-layer.d.ts +38 -0
  66. package/lib/browser/playground/extend-edit-layer.d.ts.map +1 -0
  67. package/lib/browser/playground/extend-edit-layer.js +335 -0
  68. package/lib/browser/playground/extend-edit-layer.js.map +1 -0
  69. package/lib/browser/playground/index.d.ts +1 -0
  70. package/lib/browser/playground/index.d.ts.map +1 -1
  71. package/lib/browser/playground/index.js +1 -0
  72. package/lib/browser/playground/index.js.map +1 -1
  73. package/lib/browser/playground/path-edit-layer-move-point.d.ts +15 -0
  74. package/lib/browser/playground/path-edit-layer-move-point.d.ts.map +1 -0
  75. package/lib/browser/playground/path-edit-layer-move-point.js +47 -0
  76. package/lib/browser/playground/path-edit-layer-move-point.js.map +1 -0
  77. package/lib/browser/playground/path-edit-layer-svg-path.d.ts +11 -0
  78. package/lib/browser/playground/path-edit-layer-svg-path.d.ts.map +1 -0
  79. package/lib/browser/playground/path-edit-layer-svg-path.js +21 -0
  80. package/lib/browser/playground/path-edit-layer-svg-path.js.map +1 -0
  81. package/lib/browser/playground/path-edit-layer.d.ts +36 -0
  82. package/lib/browser/playground/path-edit-layer.d.ts.map +1 -0
  83. package/lib/browser/playground/path-edit-layer.js +257 -0
  84. package/lib/browser/playground/path-edit-layer.js.map +1 -0
  85. package/lib/browser/playground/playground-context.d.ts +3 -1
  86. package/lib/browser/playground/playground-context.d.ts.map +1 -1
  87. package/lib/browser/playground/playground-context.js +49 -47
  88. package/lib/browser/playground/playground-context.js.map +1 -1
  89. package/lib/browser/playground/playground-contribution.d.ts +2 -0
  90. package/lib/browser/playground/playground-contribution.d.ts.map +1 -1
  91. package/lib/browser/playground/playground-contribution.js +100 -67
  92. package/lib/browser/playground/playground-contribution.js.map +1 -1
  93. package/lib/browser/playground/selection-entity-manager.js +74 -132
  94. package/lib/browser/playground/selection-entity-manager.js.map +1 -1
  95. package/lib/browser/playground/selector-extend-icons.js +15 -16
  96. package/lib/browser/playground/selector-extend-icons.js.map +1 -1
  97. package/lib/browser/playground/selector-extend-renderer.d.ts +3 -2
  98. package/lib/browser/playground/selector-extend-renderer.d.ts.map +1 -1
  99. package/lib/browser/playground/selector-extend-renderer.js +67 -52
  100. package/lib/browser/playground/selector-extend-renderer.js.map +1 -1
  101. package/lib/browser/utils/snapshot.d.ts.map +1 -1
  102. package/lib/browser/utils/snapshot.js +81 -172
  103. package/lib/browser/utils/snapshot.js.map +1 -1
  104. package/package.json +9 -7
  105. package/src/browser/editor2d-label-provider.ts +1 -15
  106. package/src/browser/editor2d-ref-provider-contribution.ts +8 -8
  107. package/src/browser/model/editor2d-document.ts +284 -51
  108. package/src/browser/model/editor2d.ts +21 -5
  109. package/src/browser/model/utils/anim.utils.ts +9 -2
  110. package/src/browser/playground/canvas-draw.ts +31 -17
  111. package/src/browser/playground/canvas-layer.ts +25 -3
  112. package/src/browser/playground/entities/extend-entity.ts +37 -0
  113. package/src/browser/playground/entities/index.ts +1 -0
  114. package/src/browser/playground/extend-edit-layer-point-event.tsx +71 -0
  115. package/src/browser/playground/extend-edit-layer.tsx +442 -0
  116. package/src/browser/playground/index.ts +1 -0
  117. package/src/browser/playground/path-edit-layer-move-point.tsx +71 -0
  118. package/src/browser/playground/path-edit-layer-svg-path.tsx +50 -0
  119. package/src/browser/playground/path-edit-layer.tsx +330 -0
  120. package/src/browser/playground/playground-context.ts +2 -0
  121. package/src/browser/playground/playground-contribution.ts +37 -3
  122. package/src/browser/playground/selector-extend-renderer.tsx +43 -10
  123. package/src/browser/style/canvas-layer.css +16 -0
  124. package/src/browser/style/extend-edit-layer.less +127 -0
  125. package/src/browser/style/index.less +2 -1
  126. package/src/browser/style/path-edit-layer.less +72 -0
  127. package/src/browser/svg/pen+.svg +24 -0
  128. package/src/browser/utils/snapshot.ts +1 -0
  129. package/lib/browser/playground/canvas-draw-layer.d.ts +0 -22
  130. package/lib/browser/playground/canvas-draw-layer.d.ts.map +0 -1
  131. package/lib/browser/playground/canvas-draw-layer.js +0 -126
  132. package/lib/browser/playground/canvas-draw-layer.js.map +0 -1
  133. package/src/browser/playground/canvas-draw-layer.tsx +0 -88
  134. 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
- var render_engine_1 = require("@gedit/render-engine");
78
- var editor2d_1 = require("../model/editor2d");
79
- var utils_1 = require("@gedit/utils");
80
- var WAIT_TO_DISPOSE_TIME = 30000; // 延迟删除, 这样tab在频繁切换时候不会有延迟
81
- var SCENE_KEY = 'boot';
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, function (v, key) {
19
+ (0, utils_1.each)(obj, (v, key) => {
93
20
  var _a;
94
- var currentPath = path ? "".concat(path, ".").concat(key) : key;
21
+ const currentPath = path ? `${path}.${key}` : key;
95
22
  if (typeof v === 'string') {
96
- var matched = v.match(/^\$\{([^\}]+)\}$/);
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
- var symbolId_1 = matched[1];
103
- var symbolValue = ((_a = config.symbols.find(function (s) { return s.id === symbolId_1; })) === null || _a === void 0 ? void 0 : _a.value) || '';
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(function (item, i) {
109
- originData = replaceSymbolKey(originData, config, item, "".concat(currentPath, ".").concat(i));
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
- var originData = (0, utils_1.omit)(node, ['parent', 'previousSibling', 'nextSibling', 'children']);
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
- var CanvasDraw = /** @class */ (function (_super) {
127
- __extends(CanvasDraw, _super);
128
- function CanvasDraw(opts) {
129
- var _this = _super.call(this) || this;
130
- _this.opts = opts;
131
- _this.onDrawEmitter = new utils_1.Emitter();
132
- _this.onLoadingEmitter = new utils_1.Emitter();
133
- _this.onGameObjectChangeEmitter = new utils_1.Emitter();
134
- _this.booted = false;
135
- _this.libLoaded = false;
136
- _this.libLoading = false;
137
- _this.lastVisible = false;
138
- _this.gameObjectCache = new Map();
139
- _this.nodeCache = new Map();
140
- _this.nodeVersionCache = new Map();
141
- _this.lastRenderKeys = [];
142
- _this.allCount = -1;
143
- _this.onDraw = _this.onDrawEmitter.event;
144
- _this.onLoading = _this.onLoadingEmitter.event;
145
- _this.onGameObjectChange = _this.onGameObjectChangeEmitter.event;
146
- _this.loading = true;
147
- _this.lastZoom = 0.1;
148
- _this.toDispose.pushAll([
149
- _this.onDrawEmitter,
150
- _this.onLoadingEmitter,
151
- _this.onGameObjectChangeEmitter,
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
- CanvasDraw.prototype.startLoadLibs = function () {
156
- return __awaiter(this, void 0, void 0, function () {
157
- return __generator(this, function (_a) {
158
- switch (_a.label) {
159
- case 0: return [4 /*yield*/, this.opts.renderEngine.loadIDELibs()];
160
- case 1:
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
- CanvasDraw.prototype.toggleVisible = function (appConfig, visible, engineName) {
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
- var isScene = new utils_1.URI((_a = this.data) === null || _a === void 0 ? void 0 : _a.uri).path.ext === '.scene';
109
+ const isScene = new utils_1.URI((_a = this.data) === null || _a === void 0 ? void 0 : _a.uri).path.ext === '.scene';
191
110
  // 组件模式用透明
192
- var backgroundColor = isScene ? appConfig.backgroundColor : '';
111
+ const backgroundColor = isScene ? appConfig.backgroundColor : '';
193
112
  this.pixelArt = appConfig.pixelArt;
194
113
  if (visible && !this.renderWidget) {
195
- var element_1 = window.document.createElement('canvas');
196
- this.opts.host.appendChild(element_1);
197
- element_1.className = 'gedit-canvas-transparent';
198
- this.renderWidget = this.opts.renderEngine.createGameWidget(engineName, __assign(__assign({}, appConfig), { width: 0, height: 0, uri: (_b = this.data) === null || _b === void 0 ? void 0 : _b.uri, canvas: element_1, backgroundColor: backgroundColor, assetsURI: this.opts.assetsURI, isIDE: true }));
199
- this.renderWidget.toDispose.push(utils_1.Disposable.create(function () {
200
- if (_this.renderWidgetDispose) {
201
- _this.renderWidgetDispose.dispose();
202
- _this.renderWidgetDispose = undefined;
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
- _this.opts.host.removeChild(element_1);
205
- _this.renderWidget = undefined;
206
- _this.booted = false;
207
- _this.loading = true;
208
- _this.onLoadingEmitter.fire({
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: _this.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(function () {
217
- _this.booted = true;
218
- _this.draw();
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
- var timeoutId_1 = setTimeout(function () {
228
- if (_this.renderWidget)
229
- _this.renderWidget.dispose();
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(function () {
232
- window.clearTimeout(timeoutId_1);
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
- CanvasDraw.prototype.updateGameObjects = function (scene, content) {
243
- var _this = this;
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(function (key) {
169
+ this.lastRenderKeys.forEach(key => {
250
170
  if (!renderKeys.includes(key)) {
251
- var obj = _this.gameObjectCache.get(key);
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
- CanvasDraw.prototype.updateGameObject = function (scene, node, depth, renderKeys, isInside, parentId) {
260
- var e_1, _a;
261
- var _this = this;
262
- var _b;
263
- if (isInside === void 0) { isInside = false; }
264
- var nodePath = editor2d_1.Editor2dNode.getNodePath(node);
265
- var children = (node.children || []).slice().reverse();
266
- var deco = this.opts.renderEngine.getGameObjectDecoration(this.data.engineName, node.displayType);
267
- var compId = !editor2d_1.Editor2dNode.isRootNode(node) && deco.getComponentId ? deco.getComponentId(node) : undefined;
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
- try {
281
- for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {
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
- var gameObjectCache = this.gameObjectCache;
295
- var currentDepth = depth;
296
- var oldNode = this.nodeCache.get(nodePath);
297
- var nodeChanged = node !== oldNode;
298
- var gameObject = gameObjectCache.get(nodePath);
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
- var firstCreate = false;
304
- var nodeData = toNodeData(node, this.data.appConfig);
305
- var newVersion = currentDepth + (node.version || 0) + ':' + (((_b = this.data) === null || _b === void 0 ? void 0 : _b.configVersion) || 0);
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
- var gameObjectChildren = children ? children.map(function (c) { return gameObjectCache.get(editor2d_1.Editor2dNode.getNodePath(c)); }) : [];
215
+ const gameObjectChildren = children ? children.map(c => gameObjectCache.get(editor2d_1.Editor2dNode.getNodePath(c))) : [];
309
216
  try {
310
- gameObject = scene.createAuto(__assign(__assign({}, nodeData), { id: nodePath, depth: currentDepth, parentId: parentId }), gameObjectChildren);
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, function () {
318
- _this.gameObjectCache.delete(nodePath);
319
- _this.nodeVersionCache.delete(nodePath);
320
- _this.nodeCache.delete(nodePath);
321
- _this.onGameObjectChangeEmitter.fire({ type: GameObjectEventType.DESTROY, gameObject: gameObject, node: _this.nodeCache.get(nodePath) });
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, function () {
324
- _this.onGameObjectChangeEmitter.fire({
235
+ scene.onGameObjectUpdate(gameObject, () => {
236
+ this.onGameObjectChangeEmitter.fire({
325
237
  type: GameObjectEventType.UPDATE,
326
238
  gameObject: gameObject,
327
- node: _this.nodeCache.get(nodePath),
239
+ node: this.nodeCache.get(nodePath),
328
240
  });
329
241
  });
330
- scene.onGameObjectCreate(gameObject, function () {
331
- _this.nodeVersionCache.set(nodePath, newVersion);
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
- _this.fireLoading(editor2d_1.Editor2dNode.isRootNode(_this.nodeCache.get(nodePath)));
246
+ this.fireLoading(editor2d_1.Editor2dNode.isRootNode(this.nodeCache.get(nodePath)));
334
247
  });
335
- scene.onGameObjectError(gameObject, function (error) {
336
- _this.onGameObjectChangeEmitter.fire({
248
+ scene.onGameObjectError(gameObject, error => {
249
+ this.onGameObjectChangeEmitter.fire({
337
250
  type: GameObjectEventType.ERROR,
338
251
  gameObject: gameObject,
339
- node: _this.nodeCache.get(nodePath),
340
- error: 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: selectable, adsorbable: adsorbable, isInside: isInside }
260
+ state: { selectable, adsorbable, isInside }
348
261
  });
349
262
  firstCreate = true;
350
263
  }
351
- if (gameObject && gameObject.getTextureId) {
352
- var oldTexture = gameObject.getTextureId();
353
- var newTexture = nodeData.textureId;
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
- var update = function () {
362
- var oldVersion = _this.nodeVersionCache.get(nodePath);
363
- if (nodeChanged || oldVersion !== newVersion) {
364
- gameObject.update(__assign(__assign({}, nodeData), { parentId: parentId, id: nodePath, textureId: nodeData.textureId, depth: currentDepth }));
365
- _this.nodeVersionCache.set(nodePath, newVersion);
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
- CanvasDraw.prototype.fireLoading = function (allLoaded) {
381
- var allCount = this.allCount;
382
- var currentCount = this.nodeVersionCache.size;
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: allCount,
389
- currentCount: currentCount,
308
+ allCount,
309
+ currentCount,
390
310
  });
391
- };
392
- CanvasDraw.prototype.refreshScale = function (delayDraw, zoom) {
311
+ }
312
+ refreshScale(delayDraw = true, zoom = this.lastZoom) {
393
313
  var _a, _b;
394
- if (delayDraw === void 0) { delayDraw = true; }
395
- if (zoom === void 0) { zoom = this.lastZoom; }
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
- CanvasDraw.prototype.update = function (data) {
321
+ }
322
+ update(data) {
405
323
  this.data = data;
406
324
  this.draw();
407
- };
325
+ }
408
326
  /**
409
327
  * 获取画布的宽高
410
328
  */
411
- CanvasDraw.prototype.getSceneSize = function () {
329
+ getSceneSize() {
412
330
  if (!this.data)
413
331
  return undefined;
414
- var _a = this.data, content = _a.content, appConfig = _a.appConfig;
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
- CanvasDraw.prototype.draw = function () {
336
+ }
337
+ draw() {
420
338
  if (!this.data)
421
339
  return;
422
- var _a = this.data, visible = _a.visible, appConfig = _a.appConfig, content = _a.content, engineName = _a.engineName;
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
- var size = this.getSceneSize();
346
+ const size = this.getSceneSize();
429
347
  if (!content || !appConfig || !this.libLoaded || !size)
430
348
  return;
431
- var visibleChanged = this.toggleVisible(appConfig, visible, engineName);
349
+ const visibleChanged = this.toggleVisible(appConfig, visible, engineName);
432
350
  if (!this.renderWidget || !this.booted)
433
351
  return;
434
- var scene = this.renderWidget.switchScene(SCENE_KEY, size);
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
- return CanvasDraw;
455
- }(utils_1.DisposableImpl));
366
+ }
367
+ }
456
368
  exports.CanvasDraw = CanvasDraw;
457
369
  //# sourceMappingURL=canvas-draw.js.map