@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.
|
@@ -4,23 +4,6 @@ window.EVA.plugin = window.EVA.plugin || {};
|
|
|
4
4
|
window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
|
|
5
5
|
var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter) {
|
|
6
6
|
'use strict';
|
|
7
|
-
var extendStatics = function (d, b) {
|
|
8
|
-
extendStatics = Object.setPrototypeOf || {
|
|
9
|
-
__proto__: []
|
|
10
|
-
} instanceof Array && function (d, b) {
|
|
11
|
-
d.__proto__ = b;
|
|
12
|
-
} || function (d, b) {
|
|
13
|
-
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
14
|
-
};
|
|
15
|
-
return extendStatics(d, b);
|
|
16
|
-
};
|
|
17
|
-
function __extends(d, b) {
|
|
18
|
-
extendStatics(d, b);
|
|
19
|
-
function __() {
|
|
20
|
-
this.constructor = d;
|
|
21
|
-
}
|
|
22
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
23
|
-
}
|
|
24
7
|
function __decorate(decorators, target, key, desc) {
|
|
25
8
|
var c = arguments.length,
|
|
26
9
|
r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
|
|
@@ -55,136 +38,6 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
55
38
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
56
39
|
});
|
|
57
40
|
}
|
|
58
|
-
function __generator(thisArg, body) {
|
|
59
|
-
var _ = {
|
|
60
|
-
label: 0,
|
|
61
|
-
sent: function () {
|
|
62
|
-
if (t[0] & 1) throw t[1];
|
|
63
|
-
return t[1];
|
|
64
|
-
},
|
|
65
|
-
trys: [],
|
|
66
|
-
ops: []
|
|
67
|
-
},
|
|
68
|
-
f,
|
|
69
|
-
y,
|
|
70
|
-
t,
|
|
71
|
-
g;
|
|
72
|
-
return g = {
|
|
73
|
-
next: verb(0),
|
|
74
|
-
"throw": verb(1),
|
|
75
|
-
"return": verb(2)
|
|
76
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
|
77
|
-
return this;
|
|
78
|
-
}), g;
|
|
79
|
-
function verb(n) {
|
|
80
|
-
return function (v) {
|
|
81
|
-
return step([n, v]);
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
function step(op) {
|
|
85
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
86
|
-
while (_) try {
|
|
87
|
-
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;
|
|
88
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
89
|
-
switch (op[0]) {
|
|
90
|
-
case 0:
|
|
91
|
-
case 1:
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
case 4:
|
|
95
|
-
_.label++;
|
|
96
|
-
return {
|
|
97
|
-
value: op[1],
|
|
98
|
-
done: false
|
|
99
|
-
};
|
|
100
|
-
case 5:
|
|
101
|
-
_.label++;
|
|
102
|
-
y = op[1];
|
|
103
|
-
op = [0];
|
|
104
|
-
continue;
|
|
105
|
-
case 7:
|
|
106
|
-
op = _.ops.pop();
|
|
107
|
-
_.trys.pop();
|
|
108
|
-
continue;
|
|
109
|
-
default:
|
|
110
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
111
|
-
_ = 0;
|
|
112
|
-
continue;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
115
|
-
_.label = op[1];
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
119
|
-
_.label = t[1];
|
|
120
|
-
t = op;
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
if (t && _.label < t[2]) {
|
|
124
|
-
_.label = t[2];
|
|
125
|
-
_.ops.push(op);
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
if (t[2]) _.ops.pop();
|
|
129
|
-
_.trys.pop();
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
op = body.call(thisArg, _);
|
|
133
|
-
} catch (e) {
|
|
134
|
-
op = [6, e];
|
|
135
|
-
y = 0;
|
|
136
|
-
} finally {
|
|
137
|
-
f = t = 0;
|
|
138
|
-
}
|
|
139
|
-
if (op[0] & 5) throw op[1];
|
|
140
|
-
return {
|
|
141
|
-
value: op[0] ? op[1] : void 0,
|
|
142
|
-
done: true
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function __values(o) {
|
|
147
|
-
var s = typeof Symbol === "function" && Symbol.iterator,
|
|
148
|
-
m = s && o[s],
|
|
149
|
-
i = 0;
|
|
150
|
-
if (m) return m.call(o);
|
|
151
|
-
if (o && typeof o.length === "number") return {
|
|
152
|
-
next: function () {
|
|
153
|
-
if (o && i >= o.length) o = void 0;
|
|
154
|
-
return {
|
|
155
|
-
value: o && o[i++],
|
|
156
|
-
done: !o
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
161
|
-
}
|
|
162
|
-
function __read(o, n) {
|
|
163
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
164
|
-
if (!m) return o;
|
|
165
|
-
var i = m.call(o),
|
|
166
|
-
r,
|
|
167
|
-
ar = [],
|
|
168
|
-
e;
|
|
169
|
-
try {
|
|
170
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
e = {
|
|
173
|
-
error: error
|
|
174
|
-
};
|
|
175
|
-
} finally {
|
|
176
|
-
try {
|
|
177
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
178
|
-
} finally {
|
|
179
|
-
if (e) throw e.error;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return ar;
|
|
183
|
-
}
|
|
184
|
-
function __spread() {
|
|
185
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
186
|
-
return ar;
|
|
187
|
-
}
|
|
188
41
|
function getIDEPropsPropertyObj(target, propertyKey) {
|
|
189
42
|
if (!target.constructor.IDEProps) {
|
|
190
43
|
target.constructor.IDEProps = {};
|
|
@@ -212,33 +65,29 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
212
65
|
MASK_TYPE["Img"] = "Img";
|
|
213
66
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
214
67
|
})(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
_this.spriteName = '';
|
|
222
|
-
return _this;
|
|
68
|
+
class Mask$2 extends eva_js.Component {
|
|
69
|
+
constructor() {
|
|
70
|
+
super(...arguments);
|
|
71
|
+
this.style = {};
|
|
72
|
+
this.resource = '';
|
|
73
|
+
this.spriteName = '';
|
|
223
74
|
}
|
|
224
|
-
|
|
75
|
+
init(obj) {
|
|
225
76
|
_extends(this, obj);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
var resourceKeySplit = '_s|r|c_';
|
|
234
|
-
var propertyForGraphics = {
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
Mask$2.componentName = 'Mask';
|
|
80
|
+
__decorate([type('string')], Mask$2.prototype, "resource", void 0);
|
|
81
|
+
__decorate([type('string')], Mask$2.prototype, "spriteName", void 0);
|
|
82
|
+
const resourceKeySplit = '_s|r|c_';
|
|
83
|
+
const propertyForGraphics = {
|
|
235
84
|
Circle: ['x', 'y', 'radius'],
|
|
236
85
|
Ellipse: ['x', 'y', 'width', 'height'],
|
|
237
86
|
Rect: ['x', 'y', 'width', 'height'],
|
|
238
87
|
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
239
88
|
Polygon: ['paths']
|
|
240
89
|
};
|
|
241
|
-
|
|
90
|
+
const functionForGraphics = {
|
|
242
91
|
Circle: 'circle',
|
|
243
92
|
Ellipse: 'ellipse',
|
|
244
93
|
Rect: 'rect',
|
|
@@ -255,23 +104,21 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
255
104
|
MASK_TYPE["Img"] = "Img";
|
|
256
105
|
MASK_TYPE["Sprite"] = "Sprite";
|
|
257
106
|
})(MASK_TYPE || (MASK_TYPE = {}));
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
_this.maskSpriteCache = {};
|
|
265
|
-
return _this;
|
|
107
|
+
let Mask = class Mask extends pluginRenderer.Renderer {
|
|
108
|
+
constructor() {
|
|
109
|
+
super(...arguments);
|
|
110
|
+
this.name = 'Mask';
|
|
111
|
+
this.changedCache = {};
|
|
112
|
+
this.maskSpriteCache = {};
|
|
266
113
|
}
|
|
267
|
-
|
|
114
|
+
init() {
|
|
268
115
|
this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
|
|
269
116
|
this.renderSystem.rendererManager.register(this);
|
|
270
|
-
}
|
|
271
|
-
|
|
117
|
+
}
|
|
118
|
+
rendererUpdate() {
|
|
272
119
|
this.changedCache = {};
|
|
273
|
-
}
|
|
274
|
-
|
|
120
|
+
}
|
|
121
|
+
componentChanged(changed) {
|
|
275
122
|
if (changed.component.name !== 'Mask') return;
|
|
276
123
|
switch (changed.type) {
|
|
277
124
|
case eva_js.OBSERVER_TYPE.ADD:
|
|
@@ -284,16 +131,16 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
284
131
|
this.change(changed);
|
|
285
132
|
break;
|
|
286
133
|
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
|
|
134
|
+
}
|
|
135
|
+
add(changed) {
|
|
136
|
+
const component = changed.component;
|
|
290
137
|
if (!(component.type in MASK_TYPE)) {
|
|
291
138
|
throw new Error('no have Mask type: ' + component.type);
|
|
292
139
|
}
|
|
293
140
|
if (!component.style) {
|
|
294
141
|
throw new Error('no have Mask style: ' + component.type);
|
|
295
142
|
}
|
|
296
|
-
|
|
143
|
+
let mask;
|
|
297
144
|
switch (component.type) {
|
|
298
145
|
case MASK_TYPE.Circle:
|
|
299
146
|
mask = this.createGraphics(component);
|
|
@@ -320,22 +167,22 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
320
167
|
if (!mask) {
|
|
321
168
|
throw new Error('no have mask instance, check your mask params: ' + component.type);
|
|
322
169
|
}
|
|
323
|
-
|
|
170
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
324
171
|
container.mask = mask;
|
|
325
172
|
container.addChild(mask);
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
173
|
+
}
|
|
174
|
+
remove(changed) {
|
|
175
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
329
176
|
container.removeChild(container.mask);
|
|
330
177
|
container.mask.destroy({
|
|
331
178
|
children: true
|
|
332
179
|
});
|
|
333
180
|
container.mask = null;
|
|
334
181
|
delete this.maskSpriteCache[changed.gameObject.id];
|
|
335
|
-
}
|
|
336
|
-
|
|
182
|
+
}
|
|
183
|
+
change(changed) {
|
|
337
184
|
if (this.changedCache[changed.gameObject.id]) return;
|
|
338
|
-
|
|
185
|
+
const component = changed.component;
|
|
339
186
|
if (changed.prop.prop[0] === 'type') {
|
|
340
187
|
this.changedCache[changed.gameObject.id] = true;
|
|
341
188
|
if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
|
|
@@ -358,101 +205,76 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
|
|
|
358
205
|
this.changedCache[changed.gameObject.id] = true;
|
|
359
206
|
this.changeSprite(component);
|
|
360
207
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
208
|
+
}
|
|
209
|
+
createGraphics(component) {
|
|
210
|
+
const graphics = new rendererAdapter.Graphics();
|
|
364
211
|
this.draw(graphics, component);
|
|
365
212
|
return graphics;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
213
|
+
}
|
|
214
|
+
redrawGraphics(changed) {
|
|
215
|
+
const container = this.containerManager.getContainer(changed.gameObject.id);
|
|
216
|
+
const graphics = container.mask;
|
|
370
217
|
graphics.clear();
|
|
371
218
|
this.draw(graphics, changed.component);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
for (var _b = __values(propertyForGraphics[component.type]), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
378
|
-
var key = _c.value;
|
|
379
|
-
params.push(component.style[key]);
|
|
380
|
-
}
|
|
381
|
-
} catch (e_1_1) {
|
|
382
|
-
e_1 = {
|
|
383
|
-
error: e_1_1
|
|
384
|
-
};
|
|
385
|
-
} finally {
|
|
386
|
-
try {
|
|
387
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
388
|
-
} finally {
|
|
389
|
-
if (e_1) throw e_1.error;
|
|
390
|
-
}
|
|
219
|
+
}
|
|
220
|
+
draw(graphics, component) {
|
|
221
|
+
const params = [];
|
|
222
|
+
for (const key of propertyForGraphics[component.type]) {
|
|
223
|
+
params.push(component.style[key]);
|
|
391
224
|
}
|
|
392
|
-
graphics[functionForGraphics[component.type]]
|
|
225
|
+
graphics[functionForGraphics[component.type]](...params);
|
|
393
226
|
graphics.fill(0x000000);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
227
|
+
}
|
|
228
|
+
createSprite(component) {
|
|
229
|
+
const sprite = new rendererAdapter.Sprite(null);
|
|
397
230
|
this.maskSpriteCache[component.gameObject.id] = sprite;
|
|
398
231
|
this.setSprite(component, sprite);
|
|
399
232
|
return sprite.sprite;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
233
|
+
}
|
|
234
|
+
changeSpriteStyle(component) {
|
|
235
|
+
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
403
236
|
sprite.sprite.width = component.style.width;
|
|
404
237
|
sprite.sprite.height = component.style.height;
|
|
405
238
|
sprite.sprite.position.x = component.style.x;
|
|
406
239
|
sprite.sprite.position.y = component.style.y;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
240
|
+
}
|
|
241
|
+
changeSprite(component) {
|
|
242
|
+
const sprite = this.maskSpriteCache[component.gameObject.id];
|
|
410
243
|
this.setSprite(component, sprite);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
} else {
|
|
434
|
-
sprite.image = res.data.image;
|
|
435
|
-
}
|
|
436
|
-
sprite.sprite.width = component.style.width;
|
|
437
|
-
sprite.sprite.height = component.style.height;
|
|
438
|
-
sprite.sprite.position.x = component.style.x;
|
|
439
|
-
sprite.sprite.position.y = component.style.y;
|
|
440
|
-
return [2];
|
|
441
|
-
}
|
|
442
|
-
});
|
|
244
|
+
}
|
|
245
|
+
setSprite(component, sprite) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
let res;
|
|
248
|
+
try {
|
|
249
|
+
const asyncId = this.increaseAsyncId(component.gameObject.id);
|
|
250
|
+
res = yield eva_js.resource.getResource(component.resource);
|
|
251
|
+
if (!this.validateAsyncId(component.gameObject.id, asyncId)) return;
|
|
252
|
+
} catch (e) {
|
|
253
|
+
throw new Error('mask resource load error');
|
|
254
|
+
}
|
|
255
|
+
if (component.type === MASK_TYPE.Sprite) {
|
|
256
|
+
const img = component.resource + resourceKeySplit + component.spriteName;
|
|
257
|
+
const texture = res.instance[img];
|
|
258
|
+
sprite.image = texture;
|
|
259
|
+
} else {
|
|
260
|
+
sprite.image = res.data.image;
|
|
261
|
+
}
|
|
262
|
+
sprite.sprite.width = component.style.width;
|
|
263
|
+
sprite.sprite.height = component.style.height;
|
|
264
|
+
sprite.sprite.position.x = component.style.x;
|
|
265
|
+
sprite.sprite.position.y = component.style.y;
|
|
443
266
|
});
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
}(pluginRenderer.Renderer);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
Mask.systemName = 'Mask';
|
|
270
|
+
Mask = __decorate([eva_js.decorators.componentObserver({
|
|
271
|
+
Mask: ['type', {
|
|
272
|
+
prop: ['style'],
|
|
273
|
+
deep: true
|
|
274
|
+
}, 'resource', 'spriteName']
|
|
275
|
+
})], Mask);
|
|
454
276
|
var Mask$1 = Mask;
|
|
455
|
-
exports.Mask = Mask$
|
|
277
|
+
exports.Mask = Mask$2;
|
|
456
278
|
exports.MaskSystem = Mask$1;
|
|
457
279
|
Object.defineProperty(exports, '__esModule', {
|
|
458
280
|
value: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)({}).hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},_extends.apply(null,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_mask=function(e,t,r,i){"use strict";function s(e,t,r,i){var s,n=arguments.length,o=n<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,r):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,r,i);else for(var c=e.length-1;c>=0;c--)(s=e[c])&&(o=(n<3?s(o):n>3?s(t,r,o):s(t,r))||o);return n>3&&o&&Object.defineProperty(t,r,o),o}function n(e,t,r,i){return new(r||(r=Promise))((function(s,n){function o(e){try{a(i.next(e))}catch(e){n(e)}}function c(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,c)}a((i=i.apply(e,t||[])).next())}))}function o(e){return function(t,r){var i=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);i.key=r,i.type=e}}e.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"}(e.MASK_TYPE||(e.MASK_TYPE={}));class c extends t.Component{constructor(){super(...arguments),this.style={},this.resource="",this.spriteName=""}init(e){_extends(this,e)}}c.componentName="Mask",s([o("string")],c.prototype,"resource",void 0),s([o("string")],c.prototype,"spriteName",void 0);const a={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},p={Circle:"circle",Ellipse:"ellipse",Rect:"rect",RoundedRect:"roundRect",Polygon:"poly"};var h;!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(h||(h={}));let d=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(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}}add(e){const t=e.component;if(!(t.type in h))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 h.Circle:case h.Ellipse:case h.Rect:case h.RoundedRect:case h.Polygon:r=this.createGraphics(t);break;case h.Img:case h.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,[h.Sprite,h.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]?[h.Sprite,h.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 a[t.type])r.push(t.style[e]);e[p[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(e,r){return n(this,void 0,void 0,(function*(){let i;try{const r=this.increaseAsyncId(e.gameObject.id);if(i=yield t.resource.getResource(e.resource),!this.validateAsyncId(e.gameObject.id,r))return}catch(e){throw new Error("mask resource load error")}if(e.type===h.Sprite){const t=e.resource+"_s|r|c_"+e.spriteName,s=i.instance[t];r.image=s}else r.image=i.data.image;r.sprite.width=e.style.width,r.sprite.height=e.style.height,r.sprite.position.x=e.style.x,r.sprite.position.y=e.style.y}))}};d.systemName="Mask",d=s([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],d);var l=d;return e.Mask=c,e.MaskSystem=l,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);window.EVA.plugin.renderer.mask=window.EVA.plugin.renderer.mask||_EVA_IIFE_mask;
|