@eva/plugin-renderer-mask 2.0.0-beta.1 → 2.0.0-beta.3
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.
|
@@ -21,20 +21,6 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
21
21
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
22
22
|
and limitations under the License.
|
|
23
23
|
***************************************************************************** */
|
|
24
|
-
/* global Reflect, Promise */
|
|
25
|
-
|
|
26
|
-
var extendStatics = function(d, b) {
|
|
27
|
-
extendStatics = Object.setPrototypeOf ||
|
|
28
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
29
|
-
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
30
|
-
return extendStatics(d, b);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function __extends(d, b) {
|
|
34
|
-
extendStatics(d, b);
|
|
35
|
-
function __() { this.constructor = d; }
|
|
36
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
37
|
-
}
|
|
38
24
|
|
|
39
25
|
function __decorate(decorators, target, key, desc) {
|
|
40
26
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -50,68 +36,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
50
36
|
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
51
37
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
52
38
|
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function __generator(thisArg, body) {
|
|
56
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
57
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
58
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
59
|
-
function step(op) {
|
|
60
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
61
|
-
while (_) try {
|
|
62
|
-
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;
|
|
63
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
64
|
-
switch (op[0]) {
|
|
65
|
-
case 0: case 1: t = op; break;
|
|
66
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
67
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
68
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
69
|
-
default:
|
|
70
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
71
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
72
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
73
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
74
|
-
if (t[2]) _.ops.pop();
|
|
75
|
-
_.trys.pop(); continue;
|
|
76
|
-
}
|
|
77
|
-
op = body.call(thisArg, _);
|
|
78
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
79
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function __values(o) {
|
|
84
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
85
|
-
if (m) return m.call(o);
|
|
86
|
-
return {
|
|
87
|
-
next: function () {
|
|
88
|
-
if (o && i >= o.length) o = void 0;
|
|
89
|
-
return { value: o && o[i++], done: !o };
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function __read(o, n) {
|
|
95
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
96
|
-
if (!m) return o;
|
|
97
|
-
var i = m.call(o), r, ar = [], e;
|
|
98
|
-
try {
|
|
99
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
100
|
-
}
|
|
101
|
-
catch (error) { e = { error: error }; }
|
|
102
|
-
finally {
|
|
103
|
-
try {
|
|
104
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
105
|
-
}
|
|
106
|
-
finally { if (e) throw e.error; }
|
|
107
|
-
}
|
|
108
|
-
return ar;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function __spread() {
|
|
112
|
-
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
113
|
-
ar = ar.concat(__read(arguments[i]));
|
|
114
|
-
return ar;
|
|
115
39
|
}
|
|
116
40
|
|
|
117
41
|
exports.MASK_TYPE = void 0;
|
|
@@ -124,38 +48,34 @@ exports.MASK_TYPE = void 0;
|
|
|
124
48
|
MASK_TYPE["Img"] = "Img";
|
|
125
49
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
126
50
|
})(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
_this.spriteName = '';
|
|
134
|
-
return _this;
|
|
51
|
+
class Mask$2 extends eva_js.Component {
|
|
52
|
+
constructor() {
|
|
53
|
+
super(...arguments);
|
|
54
|
+
this.style = {};
|
|
55
|
+
this.resource = '';
|
|
56
|
+
this.spriteName = '';
|
|
135
57
|
}
|
|
136
|
-
|
|
58
|
+
init(obj) {
|
|
137
59
|
Object.assign(this, obj);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}(eva_js.Component));
|
|
148
|
-
var Mask$3 = Mask$2;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
Mask$2.componentName = 'Mask';
|
|
63
|
+
__decorate([
|
|
64
|
+
inspectorDecorator.type('string')
|
|
65
|
+
], Mask$2.prototype, "resource", void 0);
|
|
66
|
+
__decorate([
|
|
67
|
+
inspectorDecorator.type('string')
|
|
68
|
+
], Mask$2.prototype, "spriteName", void 0);
|
|
149
69
|
|
|
150
|
-
|
|
151
|
-
|
|
70
|
+
const resourceKeySplit = '_s|r|c_';
|
|
71
|
+
const propertyForGraphics = {
|
|
152
72
|
Circle: ['x', 'y', 'radius'],
|
|
153
73
|
Ellipse: ['x', 'y', 'width', 'height'],
|
|
154
74
|
Rect: ['x', 'y', 'width', 'height'],
|
|
155
75
|
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
156
76
|
Polygon: ['paths'],
|
|
157
77
|
};
|
|
158
|
-
|
|
78
|
+
const functionForGraphics = {
|
|
159
79
|
Circle: 'circle',
|
|
160
80
|
Ellipse: 'ellipse',
|
|
161
81
|
Rect: 'rect',
|
|
@@ -172,23 +92,21 @@ var MASK_TYPE;
|
|
|
172
92
|
MASK_TYPE["Img"] = "Img";
|
|
173
93
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
174
94
|
})(MASK_TYPE || (MASK_TYPE = {}));
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
_this.maskSpriteCache = {};
|
|
182
|
-
return _this;
|
|
95
|
+
let Mask = class Mask extends pluginRenderer.Renderer {
|
|
96
|
+
constructor() {
|
|
97
|
+
super(...arguments);
|
|
98
|
+
this.name = 'Mask';
|
|
99
|
+
this.changedCache = {};
|
|
100
|
+
this.maskSpriteCache = {};
|
|
183
101
|
}
|
|
184
|
-
|
|
102
|
+
init() {
|
|
185
103
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
186
104
|
this.renderSystem.rendererManager.register(this);
|
|
187
|
-
}
|
|
188
|
-
|
|
105
|
+
}
|
|
106
|
+
rendererUpdate() {
|
|
189
107
|
this.changedCache = {};
|
|
190
|
-
}
|
|
191
|
-
|
|
108
|
+
}
|
|
109
|
+
componentChanged(changed) {
|
|
192
110
|
if (changed.component.name !== 'Mask')
|
|
193
111
|
return;
|
|
194
112
|
switch (changed.type) {
|
|
@@ -202,16 +120,16 @@ var Mask = (function (_super) {
|
|
|
202
120
|
this.change(changed);
|
|
203
121
|
break;
|
|
204
122
|
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
|
|
123
|
+
}
|
|
124
|
+
add(changed) {
|
|
125
|
+
const component = changed.component;
|
|
208
126
|
if (!(component.type in MASK_TYPE)) {
|
|
209
127
|
throw new Error('no have Mask type: ' + component.type);
|
|
210
128
|
}
|
|
211
129
|
if (!component.style) {
|
|
212
130
|
throw new Error('no have Mask style: ' + component.type);
|
|
213
131
|
}
|
|
214
|
-
|
|
132
|
+
let mask;
|
|
215
133
|
switch (component.type) {
|
|
216
134
|
case MASK_TYPE.Circle:
|
|
217
135
|
mask = this.createGraphics(component);
|
|
@@ -238,21 +156,21 @@ var Mask = (function (_super) {
|
|
|
238
156
|
if (!mask) {
|
|
239
157
|
throw new Error('no have mask instance, check your mask params: ' + component.type);
|
|
240
158
|
}
|
|
241
|
-
|
|
159
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
242
160
|
container.mask = mask;
|
|
243
161
|
container.addChild(mask);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
162
|
+
}
|
|
163
|
+
remove(changed) {
|
|
164
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
247
165
|
container.removeChild(container.mask);
|
|
248
166
|
container.mask.destroy({ children: true });
|
|
249
167
|
container.mask = null;
|
|
250
168
|
delete this.maskSpriteCache[changed.gameObject.id];
|
|
251
|
-
}
|
|
252
|
-
|
|
169
|
+
}
|
|
170
|
+
change(changed) {
|
|
253
171
|
if (this.changedCache[changed.gameObject.id])
|
|
254
172
|
return;
|
|
255
|
-
|
|
173
|
+
const component = changed.component;
|
|
256
174
|
if (changed.prop.prop[0] === 'type') {
|
|
257
175
|
this.changedCache[changed.gameObject.id] = true;
|
|
258
176
|
if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
|
|
@@ -280,98 +198,77 @@ var Mask = (function (_super) {
|
|
|
280
198
|
this.changedCache[changed.gameObject.id] = true;
|
|
281
199
|
this.changeSprite(component);
|
|
282
200
|
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
201
|
+
}
|
|
202
|
+
createGraphics(component) {
|
|
203
|
+
const graphics = new rendererAdapter.Graphics();
|
|
286
204
|
this.draw(graphics, component);
|
|
287
205
|
return graphics;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
206
|
+
}
|
|
207
|
+
redrawGraphics(changed) {
|
|
208
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
209
|
+
const graphics = container.mask;
|
|
292
210
|
graphics.clear();
|
|
293
211
|
this.draw(graphics, changed.component);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
for (var _b = __values(propertyForGraphics[component.type]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
300
|
-
var key = _c.value;
|
|
301
|
-
params.push(component.style[key]);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
305
|
-
finally {
|
|
306
|
-
try {
|
|
307
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
308
|
-
}
|
|
309
|
-
finally { if (e_1) throw e_1.error; }
|
|
212
|
+
}
|
|
213
|
+
draw(graphics, component) {
|
|
214
|
+
const params = [];
|
|
215
|
+
for (const key of propertyForGraphics[component.type]) {
|
|
216
|
+
params.push(component.style[key]);
|
|
310
217
|
}
|
|
311
|
-
graphics[functionForGraphics[component.type]]
|
|
218
|
+
graphics[functionForGraphics[component.type]](...params);
|
|
312
219
|
graphics.fill(0x000000);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
|
|
220
|
+
}
|
|
221
|
+
createSprite(component) {
|
|
222
|
+
const sprite = new rendererAdapter.Sprite(null);
|
|
316
223
|
this.maskSpriteCache[component.gameObject.id] = sprite;
|
|
317
224
|
this.setSprite(component, sprite);
|
|
318
225
|
return sprite.sprite;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
|
|
226
|
+
}
|
|
227
|
+
changeSpriteStyle(component) {
|
|
228
|
+
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
322
229
|
sprite.sprite.width = component.style.width;
|
|
323
230
|
sprite.sprite.height = component.style.height;
|
|
324
231
|
sprite.sprite.position.x = component.style.x;
|
|
325
232
|
sprite.sprite.position.y = component.style.y;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
233
|
+
}
|
|
234
|
+
changeSprite(component) {
|
|
235
|
+
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
329
236
|
this.setSprite(component, sprite);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
sprite.image = res.data.image;
|
|
356
|
-
}
|
|
357
|
-
sprite.sprite.width = component.style.width;
|
|
358
|
-
sprite.sprite.height = component.style.height;
|
|
359
|
-
sprite.sprite.position.x = component.style.x;
|
|
360
|
-
sprite.sprite.position.y = component.style.y;
|
|
361
|
-
return [2];
|
|
362
|
-
}
|
|
363
|
-
});
|
|
237
|
+
}
|
|
238
|
+
setSprite(component, sprite) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
let res;
|
|
241
|
+
try {
|
|
242
|
+
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
243
|
+
res = yield eva_js.resource.getResource(component.resource);
|
|
244
|
+
if (!this.validateAsyncId(component.gameObject.id, asyncId))
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
catch (e) {
|
|
248
|
+
throw new Error('mask resource load error');
|
|
249
|
+
}
|
|
250
|
+
if (component.type === MASK_TYPE.Sprite) {
|
|
251
|
+
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
252
|
+
const texture = res.instance[img];
|
|
253
|
+
sprite.image = texture;
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
sprite.image = res.data.image;
|
|
257
|
+
}
|
|
258
|
+
sprite.sprite.width = component.style.width;
|
|
259
|
+
sprite.sprite.height = component.style.height;
|
|
260
|
+
sprite.sprite.position.x = component.style.x;
|
|
261
|
+
sprite.sprite.position.y = component.style.y;
|
|
364
262
|
});
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
}(pluginRenderer.Renderer));
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
Mask.systemName = 'Mask';
|
|
266
|
+
Mask = __decorate([
|
|
267
|
+
eva_js.decorators.componentObserver({
|
|
268
|
+
Mask: ['type', { prop: ['style'], deep: true }, 'resource', 'spriteName'],
|
|
269
|
+
})
|
|
270
|
+
], Mask);
|
|
374
271
|
var Mask$1 = Mask;
|
|
375
272
|
|
|
376
|
-
exports.Mask = Mask$
|
|
273
|
+
exports.Mask = Mask$2;
|
|
377
274
|
exports.MaskSystem = Mask$1;
|
|
@@ -1 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),i=require("@eva/renderer-adapter");
|
|
2
|
+
/*! *****************************************************************************
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
5
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
6
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
9
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
10
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
11
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
12
|
+
|
|
13
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
|
+
and limitations under the License.
|
|
15
|
+
***************************************************************************** */
|
|
16
|
+
function s(e,t,r,i){var s,a=arguments.length,c=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)c=Reflect.decorate(e,t,r,i);else for(var n=e.length-1;n>=0;n--)(s=e[n])&&(c=(a<3?s(c):a>3?s(t,r,c):s(t,r))||c);return a>3&&c&&Object.defineProperty(t,r,c),c}exports.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(exports.MASK_TYPE||(exports.MASK_TYPE={}));class a extends e.Component{constructor(){super(...arguments),this.style={},this.resource="",this.spriteName=""}init(e){Object.assign(this,e)}}a.componentName="Mask",s([t.type("string")],a.prototype,"resource",void 0),s([t.type("string")],a.prototype,"spriteName",void 0);const c={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},n={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"};var o;!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(o||(o={}));let p=class extends r.Renderer{constructor(){super(...arguments),this.name="Mask",this.changedCache={},this.maskSpriteCache={}}init(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)}rendererUpdate(){this.changedCache={}}componentChanged(t){if("Mask"===t.component.name)switch(t.type){case e.OBSERVER_TYPE.ADD:this.add(t);break;case e.OBSERVER_TYPE.REMOVE:this.remove(t);break;case e.OBSERVER_TYPE.CHANGE:this.change(t)}}add(e){const t=e.component;if(!(t.type in o))throw new Error("no have Mask type: "+t.type);if(!t.style)throw new Error("no have Mask style: "+t.type);let r;switch(t.type){case o.Circle:case o.Ellipse:case o.Rect:case o.RoundedRect:case o.Polygon:r=this.createGraphics(t);break;case o.Img:case o.Sprite:r=this.createSprite(t)}if(!r)throw new Error("no have mask instance, check your mask params: "+t.type);const i=this.containerManager.getContainer(e.gameObject.id);i.mask=r,i.addChild(r)}remove(e){const t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]}change(e){if(this.changedCache[e.gameObject.id])return;const t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[o.Sprite,o.Img].indexOf(t.type)>-1||t._lastType!==t.type?(this.remove(e),this.add(e),t._lastType=t.type):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[o.Sprite,o.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}createGraphics(e){const t=new i.Graphics;return this.draw(t,e),t}redrawGraphics(e){const t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)}draw(e,t){const r=[];for(const e of c[t.type])r.push(t.style[e]);e[n[t.type]](...r),e.fill(0)}createSprite(e){const t=new i.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite}changeSpriteStyle(e){const t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y}changeSprite(e){const t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)}setSprite(t,r){return i=this,s=void 0,c=function*(){let i;try{const r=this.increaseAsyncId(t.gameObject.id);if(i=yield e.resource.getResource(t.resource),!this.validateAsyncId(t.gameObject.id,r))return}catch(e){throw new Error("mask resource load error")}if(t.type===o.Sprite){const e=t.resource+"_s|r|c_"+t.spriteName,s=i.instance[e];r.image=s}else r.image=i.data.image;r.sprite.width=t.style.width,r.sprite.height=t.style.height,r.sprite.position.x=t.style.x,r.sprite.position.y=t.style.y},new((a=void 0)||(a=Promise))((function(e,t){function r(e){try{o(c.next(e))}catch(e){t(e)}}function n(e){try{o(c.throw(e))}catch(e){t(e)}}function o(t){t.done?e(t.value):new a((function(e){e(t.value)})).then(r,n)}o((c=c.apply(i,s||[])).next())}));var i,s,a,c}};p.systemName="Mask",p=s([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],p);var h=p;exports.Mask=a,exports.MaskSystem=h;
|