@eva/plugin-renderer-mask 1.2.7-editor.7 → 1.2.8-fix.1

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.
@@ -14,7 +14,7 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
14
14
  d.__proto__ = b;
15
15
  } || function (d, b) {
16
16
  for (var p in b) {
17
- if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
17
+ if (b.hasOwnProperty(p)) d[p] = b[p];
18
18
  }
19
19
  };
20
20
 
@@ -22,8 +22,6 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
22
22
  };
23
23
 
24
24
  function __extends(d, b) {
25
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
26
-
27
25
  _extendStatics(d, b);
28
26
 
29
27
  function __() {
@@ -33,22 +31,6 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
33
31
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34
32
  }
35
33
 
36
- var _assign = function __assign() {
37
- _assign = Object.assign || function __assign(t) {
38
- for (var s, i = 1, n = arguments.length; i < n; i++) {
39
- s = arguments[i];
40
-
41
- for (var p in s) {
42
- if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
43
- }
44
- }
45
-
46
- return t;
47
- };
48
-
49
- return _assign.apply(this, arguments);
50
- };
51
-
52
34
  function __decorate(decorators, target, key, desc) {
53
35
  var c = arguments.length,
54
36
  r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
@@ -59,10 +41,6 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
59
41
  return c > 3 && r && Object.defineProperty(target, key, r), r;
60
42
  }
61
43
 
62
- function __metadata(metadataKey, metadataValue) {
63
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
64
- }
65
-
66
44
  function __awaiter(thisArg, _arguments, P, generator) {
67
45
  function adopt(value) {
68
46
  return value instanceof P ? value : new P(function (resolve) {
@@ -258,119 +236,27 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
258
236
  return ar;
259
237
  }
260
238
 
261
- var SymbolKeysNotSupportedError = function (_super) {
262
- __extends(SymbolKeysNotSupportedError, _super);
263
-
264
- function SymbolKeysNotSupportedError() {
265
- var _newTarget = this.constructor;
266
-
267
- var _this = _super.call(this, 'Symbol keys are not supported yet!') || this;
268
-
269
- Object.setPrototypeOf(_this, _newTarget.prototype);
270
- return _this;
271
- }
272
-
273
- return SymbolKeysNotSupportedError;
274
- }(Error);
275
-
276
- (function (_super) {
277
- __extends(StaticGetPropertiesIsNotAFunctionError, _super);
278
-
279
- function StaticGetPropertiesIsNotAFunctionError() {
280
- var _newTarget = this.constructor;
281
-
282
- var _this = _super.call(this, 'getProperties is not a function!') || this;
283
-
284
- Object.setPrototypeOf(_this, _newTarget.prototype);
285
- return _this;
286
- }
287
-
288
- return StaticGetPropertiesIsNotAFunctionError;
289
- })(Error);
290
-
291
- var IDE_PROPERTY_METADATA = 'IDE_PROPERTY_METADATA';
292
-
293
- function transformBasicType(type) {
294
- if (type === String) {
295
- return 'string';
296
- }
297
-
298
- if (type === Number) {
299
- return 'number';
239
+ function getIDEPropsPropertyObj(target, propertyKey) {
240
+ if (!target.constructor.IDEProps) {
241
+ target.constructor.IDEProps = {};
300
242
  }
301
243
 
302
- if (type === Boolean) {
303
- return 'boolean';
244
+ if (!target.constructor.IDEProps[propertyKey]) {
245
+ target.constructor.IDEProps[propertyKey] = {};
304
246
  }
305
247
 
306
- return 'unknown';
248
+ var propertyObj = target.constructor.IDEProps[propertyKey];
249
+ return propertyObj;
307
250
  }
308
251
 
309
- function defineTypes(target, key, options, returnTypeFunction) {
310
- var type = Reflect.getMetadata('design:type', target, key);
311
- var isArray = type === Array;
312
- var str = transformBasicType(type);
313
-
314
- if (str !== 'unknown') {
315
- type = str;
316
- }
317
-
318
- if (returnTypeFunction) {
319
- var returnType = returnTypeFunction();
320
-
321
- if (Array.isArray(returnType)) {
322
- isArray = true;
323
- type = returnType[0];
324
- } else {
325
- type = returnType;
326
- }
327
- }
328
-
329
- var properties = Reflect.getMetadata(IDE_PROPERTY_METADATA, target.constructor) || {};
330
- properties[key] = _assign({
331
- type: type,
332
- isArray: isArray
333
- }, options);
334
- Reflect.defineMetadata(IDE_PROPERTY_METADATA, properties, target.constructor);
335
- }
336
-
337
- function getTypeDecoratorParams(returnTypeFuncOrOptions, maybeOptions) {
338
- if (typeof returnTypeFuncOrOptions === 'function') {
339
- return {
340
- returnTypeFunc: returnTypeFuncOrOptions,
341
- options: maybeOptions || {}
342
- };
343
- }
344
-
345
- return {
346
- options: returnTypeFuncOrOptions || {}
347
- };
348
- }
349
-
350
- function Field(returnTypeFunction, maybeOptions) {
252
+ function type(type) {
351
253
  return function (target, propertyKey) {
352
- if (typeof propertyKey === 'symbol') {
353
- throw new SymbolKeysNotSupportedError();
354
- }
355
-
356
- var _a = getTypeDecoratorParams(returnTypeFunction, maybeOptions),
357
- options = _a.options,
358
- returnTypeFunc = _a.returnTypeFunc;
359
-
360
- defineTypes(target, propertyKey, options, returnTypeFunc);
254
+ var prop = getIDEPropsPropertyObj(target, propertyKey);
255
+ prop.key = propertyKey;
256
+ prop.type = type;
361
257
  };
362
258
  }
363
259
 
364
- var ExecuteMode;
365
-
366
- (function (ExecuteMode) {
367
- ExecuteMode[ExecuteMode["Edit"] = 2] = "Edit";
368
- ExecuteMode[ExecuteMode["Game"] = 4] = "Game";
369
- ExecuteMode[ExecuteMode["All"] = 6] = "All";
370
- })(ExecuteMode || (ExecuteMode = {}));
371
-
372
- var _a;
373
-
374
260
  exports.MASK_TYPE = void 0;
375
261
 
376
262
  (function (MASK_TYPE) {
@@ -383,41 +269,6 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
383
269
  MASK_TYPE["Sprite"] = "Sprite";
384
270
  })(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
385
271
 
386
- var MaskStyle = function () {
387
- function MaskStyle() {}
388
-
389
- __decorate([Field({
390
- step: 1
391
- }), __metadata("design:type", Number)], MaskStyle.prototype, "x", void 0);
392
-
393
- __decorate([Field({
394
- step: 1
395
- }), __metadata("design:type", Number)], MaskStyle.prototype, "y", void 0);
396
-
397
- __decorate([Field({
398
- step: 0.1,
399
- if: function _if(mask) {
400
- return mask.type === exports.MASK_TYPE.Circle || mask.type === exports.MASK_TYPE.RoundedRect;
401
- }
402
- }), __metadata("design:type", Number)], MaskStyle.prototype, "radius", void 0);
403
-
404
- __decorate([Field({
405
- step: 1,
406
- if: function _if(mask) {
407
- return mask.type !== exports.MASK_TYPE.Circle;
408
- }
409
- }), __metadata("design:type", Number)], MaskStyle.prototype, "width", void 0);
410
-
411
- __decorate([Field({
412
- step: 1,
413
- if: function _if(mask) {
414
- return mask.type !== exports.MASK_TYPE.Circle;
415
- }
416
- }), __metadata("design:type", Number)], MaskStyle.prototype, "height", void 0);
417
-
418
- return MaskStyle;
419
- }();
420
-
421
272
  var Mask$2 = function (_super) {
422
273
  __extends(Mask, _super);
423
274
 
@@ -436,23 +287,9 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
436
287
 
437
288
  Mask.componentName = 'Mask';
438
289
 
439
- __decorate([Field({
440
- type: 'selector',
441
- options: (_a = {}, _a[exports.MASK_TYPE.Circle] = exports.MASK_TYPE.Circle, _a[exports.MASK_TYPE.Ellipse] = exports.MASK_TYPE.Ellipse, _a[exports.MASK_TYPE.Img] = exports.MASK_TYPE.Img, _a[exports.MASK_TYPE.Rect] = exports.MASK_TYPE.Rect, _a[exports.MASK_TYPE.RoundedRect] = exports.MASK_TYPE.RoundedRect, _a),
442
- alias: 'type',
443
- default: exports.MASK_TYPE.Circle
444
- }), __metadata("design:type", String)], Mask.prototype, "mask_type", void 0);
445
-
446
- __decorate([Field(function () {
447
- return MaskStyle;
448
- }), __metadata("design:type", Object)], Mask.prototype, "style", void 0);
449
-
450
- __decorate([Field({
451
- type: 'resource',
452
- if: function _if(mask) {
453
- return mask.type === exports.MASK_TYPE.Img || exports.MASK_TYPE.Sprite;
454
- }
455
- }), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
290
+ __decorate([type('string')], Mask.prototype, "resource", void 0);
291
+
292
+ __decorate([type('string')], Mask.prototype, "spriteName", void 0);
456
293
 
457
294
  return Mask;
458
295
  }(eva_js.Component);
@@ -593,10 +430,9 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
593
430
  if (changed.prop.prop[0] === 'type') {
594
431
  this.changedCache[changed.gameObject.id] = true;
595
432
 
596
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
433
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
597
434
  this.remove(changed);
598
435
  this.add(changed);
599
- component._lastType = component.type;
600
436
  } else {
601
437
  this.redrawGraphics(changed);
602
438
  }
@@ -1 +1 @@
1
- function _extends(){return _extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(this,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,n){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function c(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))}function u(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function l(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}var y=function(e){function t(){var t=this.constructor,r=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(Error);!function(e){function t(){var t=this.constructor,r=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(r,t.prototype),r}i(t,e)}(Error);var d,f,h="IDE_PROPERTY_METADATA";function g(e,t,r,n){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,c=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==c&&(o=c),n){var s=n();Array.isArray(s)?(i=!0,o=s[0]):o=s}var p=Reflect.getMetadata(h,e.constructor)||{};p[t]=a({type:o,isArray:i},r),Reflect.defineMetadata(h,p,e.constructor)}function m(e,t){return function(r,n){if("symbol"==typeof n)throw new y;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);g(r,n,o.options,o.returnTypeFunc)}}!function(e){e[e.Edit=2]="Edit",e[e.Game=4]="Game",e[e.All=6]="All"}(d||(d={})),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={}));var v,w=function(){function t(){}return c([m({step:1}),s("design:type",Number)],t.prototype,"x",void 0),c([m({step:1}),s("design:type",Number)],t.prototype,"y",void 0),c([m({step:.1,if:function(t){return t.type===e.MASK_TYPE.Circle||t.type===e.MASK_TYPE.RoundedRect}}),s("design:type",Number)],t.prototype,"radius",void 0),c([m({step:1,if:function(t){return t.type!==e.MASK_TYPE.Circle}}),s("design:type",Number)],t.prototype,"width",void 0),c([m({step:1,if:function(t){return t.type!==e.MASK_TYPE.Circle}}),s("design:type",Number)],t.prototype,"height",void 0),t}(),E=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.style={},e.resource="",e.spriteName="",e}return i(r,t),r.prototype.init=function(e){_extends(this,e)},r.componentName="Mask",c([m({type:"selector",options:(f={},f[e.MASK_TYPE.Circle]=e.MASK_TYPE.Circle,f[e.MASK_TYPE.Ellipse]=e.MASK_TYPE.Ellipse,f[e.MASK_TYPE.Img]=e.MASK_TYPE.Img,f[e.MASK_TYPE.Rect]=e.MASK_TYPE.Rect,f[e.MASK_TYPE.RoundedRect]=e.MASK_TYPE.RoundedRect,f),alias:"type",default:e.MASK_TYPE.Circle}),s("design:type",String)],r.prototype,"mask_type",void 0),c([m((function(){return w})),s("design:type",Object)],r.prototype,"style",void 0),c([m({type:"resource",if:function(t){return t.type===e.MASK_TYPE.Img||e.MASK_TYPE.Sprite}}),s("design:type",String)],r.prototype,"resource",void 0),r}(t.Component),S=E,b={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},R={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(v||(v={}));var _=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return i(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(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)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in v))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case v.Circle:case v.Ellipse:case v.Rect:case v.RoundedRect:case v.Polygon:t=this.createGraphics(r);break;case v.Img:case v.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var 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]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[v.Sprite,v.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]?[v.Sprite,v.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))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(b[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[R[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var 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},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(e,r){return p(this,void 0,void 0,(function(){var n,o,i,a;return u(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=c.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return e.type===v.Sprite?(i=e.resource+"_s|r|c_"+e.spriteName,a=n.instance[i],r.image=a):r.image=n.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,[2]}}))}))},o.systemName="Mask",o=c([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer),A=_;return e.Mask=S,e.MaskSystem=A,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;
1
+ function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,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,n){"use strict";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function l(e){return function(t,r){var n=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);n.key=r,n.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={}));var u,h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(t,e),t.prototype.init=function(e){_extends(this,e)},t.componentName="Mask",a([l("string")],t.prototype,"resource",void 0),a([l("string")],t.prototype,"spriteName",void 0),t}(t.Component),d={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},y={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(u||(u={}));var f=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return i(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(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)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in u))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case u.Circle:case u.Ellipse:case u.Rect:case u.RoundedRect:case u.Polygon:t=this.createGraphics(r);break;case u.Img:case u.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var 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]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[u.Sprite,u.Img].indexOf(t.type)>-1?(this.remove(e),this.add(e)):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[u.Sprite,u.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))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(d[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[y[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var 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},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(e,r){return c(this,void 0,void 0,(function(){var n,o,i,a;return s(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=c.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(i=e.resource+"_s|r|c_"+e.spriteName,a=n.instance[i],r.image=a):r.image=n.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,[2]}}))}))},o.systemName="Mask",o=a([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer);return e.Mask=h,e.MaskSystem=f,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;
@@ -43,10 +43,6 @@ function __decorate(decorators, target, key, desc) {
43
43
  return c > 3 && r && Object.defineProperty(target, key, r), r;
44
44
  }
45
45
 
46
- function __metadata(metadataKey, metadataValue) {
47
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
48
- }
49
-
50
46
  function __awaiter(thisArg, _arguments, P, generator) {
51
47
  return new (P || (P = Promise))(function (resolve, reject) {
52
48
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -118,7 +114,6 @@ function __spread() {
118
114
  return ar;
119
115
  }
120
116
 
121
- var _a;
122
117
  exports.MASK_TYPE = void 0;
123
118
  (function (MASK_TYPE) {
124
119
  MASK_TYPE["Circle"] = "Circle";
@@ -129,31 +124,6 @@ exports.MASK_TYPE = void 0;
129
124
  MASK_TYPE["Img"] = "Img";
130
125
  MASK_TYPE["Sprite"] = "Sprite";
131
126
  })(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
132
- var MaskStyle = (function () {
133
- function MaskStyle() {
134
- }
135
- __decorate([
136
- inspectorDecorator.Field({ step: 1 }),
137
- __metadata("design:type", Number)
138
- ], MaskStyle.prototype, "x", void 0);
139
- __decorate([
140
- inspectorDecorator.Field({ step: 1 }),
141
- __metadata("design:type", Number)
142
- ], MaskStyle.prototype, "y", void 0);
143
- __decorate([
144
- inspectorDecorator.Field({ step: 0.1, if: function (mask) { return mask.type === exports.MASK_TYPE.Circle || mask.type === exports.MASK_TYPE.RoundedRect; } }),
145
- __metadata("design:type", Number)
146
- ], MaskStyle.prototype, "radius", void 0);
147
- __decorate([
148
- inspectorDecorator.Field({ step: 1, if: function (mask) { return mask.type !== exports.MASK_TYPE.Circle; } }),
149
- __metadata("design:type", Number)
150
- ], MaskStyle.prototype, "width", void 0);
151
- __decorate([
152
- inspectorDecorator.Field({ step: 1, if: function (mask) { return mask.type !== exports.MASK_TYPE.Circle; } }),
153
- __metadata("design:type", Number)
154
- ], MaskStyle.prototype, "height", void 0);
155
- return MaskStyle;
156
- }());
157
127
  var Mask$2 = (function (_super) {
158
128
  __extends(Mask, _super);
159
129
  function Mask() {
@@ -168,31 +138,11 @@ var Mask$2 = (function (_super) {
168
138
  };
169
139
  Mask.componentName = 'Mask';
170
140
  __decorate([
171
- inspectorDecorator.Field({
172
- type: 'selector',
173
- options: (_a = {},
174
- _a[exports.MASK_TYPE.Circle] = exports.MASK_TYPE.Circle,
175
- _a[exports.MASK_TYPE.Ellipse] = exports.MASK_TYPE.Ellipse,
176
- _a[exports.MASK_TYPE.Img] = exports.MASK_TYPE.Img,
177
- _a[exports.MASK_TYPE.Rect] = exports.MASK_TYPE.Rect,
178
- _a[exports.MASK_TYPE.RoundedRect] = exports.MASK_TYPE.RoundedRect,
179
- _a),
180
- alias: 'type',
181
- default: exports.MASK_TYPE.Circle,
182
- }),
183
- __metadata("design:type", String)
184
- ], Mask.prototype, "mask_type", void 0);
185
- __decorate([
186
- inspectorDecorator.Field(function () { return MaskStyle; }),
187
- __metadata("design:type", Object)
188
- ], Mask.prototype, "style", void 0);
189
- __decorate([
190
- inspectorDecorator.Field({
191
- type: 'resource',
192
- if: function (mask) { return mask.type === exports.MASK_TYPE.Img || exports.MASK_TYPE.Sprite; },
193
- }),
194
- __metadata("design:type", String)
141
+ inspectorDecorator.type('string')
195
142
  ], Mask.prototype, "resource", void 0);
143
+ __decorate([
144
+ inspectorDecorator.type('string')
145
+ ], Mask.prototype, "spriteName", void 0);
196
146
  return Mask;
197
147
  }(eva_js.Component));
198
148
  var Mask$3 = Mask$2;
@@ -305,11 +255,9 @@ var Mask = (function (_super) {
305
255
  var component = changed.component;
306
256
  if (changed.prop.prop[0] === 'type') {
307
257
  this.changedCache[changed.gameObject.id] = true;
308
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 ||
309
- component._lastType !== component.type) {
258
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
310
259
  this.remove(changed);
311
260
  this.add(changed);
312
- component._lastType = component.type;
313
261
  }
314
262
  else {
315
263
  this.redrawGraphics(changed);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@eva/eva.js"),r=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),o=require("@eva/renderer-adapter"),i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},i(e,t)};function a(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function p(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var p=e.length-1;p>=0;p--)(o=e[p])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:p(0),throw:p(1),return:p(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function p(i){return function(p){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,p])}}}function l(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}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={}));var u,y=function(){function e(){}return p([r.Field({step:1}),s("design:type",Number)],e.prototype,"x",void 0),p([r.Field({step:1}),s("design:type",Number)],e.prototype,"y",void 0),p([r.Field({step:.1,if:function(e){return e.type===exports.MASK_TYPE.Circle||e.type===exports.MASK_TYPE.RoundedRect}}),s("design:type",Number)],e.prototype,"radius",void 0),p([r.Field({step:1,if:function(e){return e.type!==exports.MASK_TYPE.Circle}}),s("design:type",Number)],e.prototype,"width",void 0),p([r.Field({step:1,if:function(e){return e.type!==exports.MASK_TYPE.Circle}}),s("design:type",Number)],e.prototype,"height",void 0),e}(),d=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.style={},e.resource="",e.spriteName="",e}return a(n,t),n.prototype.init=function(e){Object.assign(this,e)},n.componentName="Mask",p([r.Field({type:"selector",options:(e={},e[exports.MASK_TYPE.Circle]=exports.MASK_TYPE.Circle,e[exports.MASK_TYPE.Ellipse]=exports.MASK_TYPE.Ellipse,e[exports.MASK_TYPE.Img]=exports.MASK_TYPE.Img,e[exports.MASK_TYPE.Rect]=exports.MASK_TYPE.Rect,e[exports.MASK_TYPE.RoundedRect]=exports.MASK_TYPE.RoundedRect,e),alias:"type",default:exports.MASK_TYPE.Circle}),s("design:type",String)],n.prototype,"mask_type",void 0),p([r.Field((function(){return y})),s("design:type",Object)],n.prototype,"style",void 0),p([r.Field({type:"resource",if:function(e){return e.type===exports.MASK_TYPE.Img||exports.MASK_TYPE.Sprite}}),s("design:type",String)],n.prototype,"resource",void 0),n}(t.Component),h=d,f={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},g={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(u||(u={}));var m=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return a(r,e),r.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},r.prototype.rendererUpdate=function(){this.changedCache={}},r.prototype.componentChanged=function(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)}},r.prototype.add=function(e){var t,r=e.component;if(!(r.type in u))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case u.Circle:case u.Ellipse:case u.Rect:case u.RoundedRect:case u.Polygon:t=this.createGraphics(r);break;case u.Img:case u.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},r.prototype.remove=function(e){var 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]},r.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[u.Sprite,u.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]?[u.Sprite,u.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))}},r.prototype.createGraphics=function(e){var t=new o.Graphics;return this.draw(t,e),t},r.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},r.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(f[t.type]),a=i.next();!a.done;a=i.next()){var p=a.value;o.push(t.style[p])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[g[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));return e}(o)),e.endFill()},r.prototype.createSprite=function(e){var t=new o.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},r.prototype.changeSpriteStyle=function(e){var 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},r.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},r.prototype.setSprite=function(e,r){return n=this,o=void 0,a=function(){var n,o,i,a;return c(this,(function(p){switch(p.label){case 0:return p.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=p.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw p.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(i=e.resource+"_s|r|c_"+e.spriteName,a=n.instance[i],r.image=a):r.image=n.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,[2]}}))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{s(a.next(e))}catch(e){t(e)}}function p(e){try{s(a.throw(e))}catch(e){t(e)}}function s(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(r,p)}s((a=a.apply(n,o||[])).next())}));var n,o,i,a},r.systemName="Mask",r=p([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],r)}(n.Renderer),v=m;exports.Mask=h,exports.MaskSystem=v;
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"),n=require("@eva/renderer-adapter"),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}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={}));var p,l=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(r,e),r.prototype.init=function(e){Object.assign(this,e)},r.componentName="Mask",a([t.type("string")],r.prototype,"resource",void 0),a([t.type("string")],r.prototype,"spriteName",void 0),r}(e.Component),h={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},u={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(p||(p={}));var y=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Mask",e.changedCache={},e.maskSpriteCache={},e}return i(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(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)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in p))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case p.Circle:case p.Ellipse:case p.Rect:case p.RoundedRect:case p.Polygon:t=this.createGraphics(r);break;case p.Img:case p.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var 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]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[p.Sprite,p.Img].indexOf(t.type)>-1?(this.remove(e),this.add(e)):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[p.Sprite,p.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))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(h[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[u[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(s(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var 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},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(t,r){return n=this,o=void 0,a=function(){var n,o,i,a;return c(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(t.gameObject.id),[4,e.resource.getResource(t.resource)];case 1:return n=c.sent(),this.validateAsyncId(t.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return t.type===p.Sprite?(i=t.resource+"_s|r|c_"+t.spriteName,a=n.instance[i],r.image=a):r.image=n.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,[2]}}))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{s(a.next(e))}catch(e){t(e)}}function c(e){try{s(a.throw(e))}catch(e){t(e)}}function s(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(r,c)}s((a=a.apply(n,o||[])).next())}));var n,o,i,a},o.systemName="Mask",o=a([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer);exports.Mask=l,exports.MaskSystem=y;
@@ -11,8 +11,6 @@ import { Sprite } from '@eva/renderer-adapter';
11
11
 
12
12
  export declare class Mask extends Component<MaskParams> {
13
13
  static componentName: string;
14
- _lastType: MaskParams['type'];
15
- mask_type: string;
16
14
  type: MaskParams['type'];
17
15
  style?: MaskParams['style'];
18
16
  resource?: string;
@@ -1,5 +1,5 @@
1
1
  import { Component, OBSERVER_TYPE, decorators, resource } from '@eva/eva.js';
2
- import { Field } from '@eva/inspector-decorator';
2
+ import { type } from '@eva/inspector-decorator';
3
3
  import { RendererSystem, Renderer } from '@eva/plugin-renderer';
4
4
  import { Graphics, Sprite } from '@eva/renderer-adapter';
5
5
 
@@ -39,10 +39,6 @@ function __decorate(decorators, target, key, desc) {
39
39
  return c > 3 && r && Object.defineProperty(target, key, r), r;
40
40
  }
41
41
 
42
- function __metadata(metadataKey, metadataValue) {
43
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
44
- }
45
-
46
42
  function __awaiter(thisArg, _arguments, P, generator) {
47
43
  return new (P || (P = Promise))(function (resolve, reject) {
48
44
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
@@ -114,7 +110,6 @@ function __spread() {
114
110
  return ar;
115
111
  }
116
112
 
117
- var _a;
118
113
  var MASK_TYPE$1;
119
114
  (function (MASK_TYPE) {
120
115
  MASK_TYPE["Circle"] = "Circle";
@@ -125,31 +120,6 @@ var MASK_TYPE$1;
125
120
  MASK_TYPE["Img"] = "Img";
126
121
  MASK_TYPE["Sprite"] = "Sprite";
127
122
  })(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
128
- var MaskStyle = (function () {
129
- function MaskStyle() {
130
- }
131
- __decorate([
132
- Field({ step: 1 }),
133
- __metadata("design:type", Number)
134
- ], MaskStyle.prototype, "x", void 0);
135
- __decorate([
136
- Field({ step: 1 }),
137
- __metadata("design:type", Number)
138
- ], MaskStyle.prototype, "y", void 0);
139
- __decorate([
140
- Field({ step: 0.1, if: function (mask) { return mask.type === MASK_TYPE$1.Circle || mask.type === MASK_TYPE$1.RoundedRect; } }),
141
- __metadata("design:type", Number)
142
- ], MaskStyle.prototype, "radius", void 0);
143
- __decorate([
144
- Field({ step: 1, if: function (mask) { return mask.type !== MASK_TYPE$1.Circle; } }),
145
- __metadata("design:type", Number)
146
- ], MaskStyle.prototype, "width", void 0);
147
- __decorate([
148
- Field({ step: 1, if: function (mask) { return mask.type !== MASK_TYPE$1.Circle; } }),
149
- __metadata("design:type", Number)
150
- ], MaskStyle.prototype, "height", void 0);
151
- return MaskStyle;
152
- }());
153
123
  var Mask$2 = (function (_super) {
154
124
  __extends(Mask, _super);
155
125
  function Mask() {
@@ -164,31 +134,11 @@ var Mask$2 = (function (_super) {
164
134
  };
165
135
  Mask.componentName = 'Mask';
166
136
  __decorate([
167
- Field({
168
- type: 'selector',
169
- options: (_a = {},
170
- _a[MASK_TYPE$1.Circle] = MASK_TYPE$1.Circle,
171
- _a[MASK_TYPE$1.Ellipse] = MASK_TYPE$1.Ellipse,
172
- _a[MASK_TYPE$1.Img] = MASK_TYPE$1.Img,
173
- _a[MASK_TYPE$1.Rect] = MASK_TYPE$1.Rect,
174
- _a[MASK_TYPE$1.RoundedRect] = MASK_TYPE$1.RoundedRect,
175
- _a),
176
- alias: 'type',
177
- default: MASK_TYPE$1.Circle,
178
- }),
179
- __metadata("design:type", String)
180
- ], Mask.prototype, "mask_type", void 0);
181
- __decorate([
182
- Field(function () { return MaskStyle; }),
183
- __metadata("design:type", Object)
184
- ], Mask.prototype, "style", void 0);
185
- __decorate([
186
- Field({
187
- type: 'resource',
188
- if: function (mask) { return mask.type === MASK_TYPE$1.Img || MASK_TYPE$1.Sprite; },
189
- }),
190
- __metadata("design:type", String)
137
+ type('string')
191
138
  ], Mask.prototype, "resource", void 0);
139
+ __decorate([
140
+ type('string')
141
+ ], Mask.prototype, "spriteName", void 0);
192
142
  return Mask;
193
143
  }(Component));
194
144
  var Mask$3 = Mask$2;
@@ -301,11 +251,9 @@ var Mask = (function (_super) {
301
251
  var component = changed.component;
302
252
  if (changed.prop.prop[0] === 'type') {
303
253
  this.changedCache[changed.gameObject.id] = true;
304
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 ||
305
- component._lastType !== component.type) {
254
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
306
255
  this.remove(changed);
307
256
  this.add(changed);
308
- component._lastType = component.type;
309
257
  }
310
258
  else {
311
259
  this.redrawGraphics(changed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-mask",
3
- "version": "1.2.7-editor.7",
3
+ "version": "1.2.8-fix.1",
4
4
  "description": "@eva/plugin-renderer-mask",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-mask.esm.js",
@@ -18,10 +18,10 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/inspector-decorator": "0.1.0-alpha.2",
22
- "@eva/plugin-renderer": "1.2.7-editor.7",
23
- "@eva/renderer-adapter": "1.2.7-editor.7",
24
- "@eva/eva.js": "1.2.7-editor.7",
21
+ "@eva/inspector-decorator": "^0.0.5",
22
+ "@eva/plugin-renderer": "1.2.8-fix.1",
23
+ "@eva/renderer-adapter": "1.2.8-fix.1",
24
+ "@eva/eva.js": "1.2.8-fix.1",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }
@@ -1,366 +0,0 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- import { __decorate, __metadata, __extends, __values, __spread, __awaiter, __generator } from 'tslib';
4
- import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
5
- import { Field } from '@eva/inspector-decorator';
6
- import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
7
- import { Graphics, Sprite } from '@eva/renderer-adapter/dist/miniprogram';
8
-
9
- var _a;
10
-
11
- var MASK_TYPE$1;
12
-
13
- (function (MASK_TYPE) {
14
- MASK_TYPE["Circle"] = "Circle";
15
- MASK_TYPE["Ellipse"] = "Ellipse";
16
- MASK_TYPE["Rect"] = "Rect";
17
- MASK_TYPE["RoundedRect"] = "RoundedRect";
18
- MASK_TYPE["Polygon"] = "Polygon";
19
- MASK_TYPE["Img"] = "Img";
20
- MASK_TYPE["Sprite"] = "Sprite";
21
- })(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
22
-
23
- var MaskStyle = function () {
24
- function MaskStyle() {}
25
-
26
- __decorate([Field({
27
- step: 1
28
- }), __metadata("design:type", Number)], MaskStyle.prototype, "x", void 0);
29
-
30
- __decorate([Field({
31
- step: 1
32
- }), __metadata("design:type", Number)], MaskStyle.prototype, "y", void 0);
33
-
34
- __decorate([Field({
35
- step: 0.1,
36
- if: function _if(mask) {
37
- return mask.type === MASK_TYPE$1.Circle || mask.type === MASK_TYPE$1.RoundedRect;
38
- }
39
- }), __metadata("design:type", Number)], MaskStyle.prototype, "radius", void 0);
40
-
41
- __decorate([Field({
42
- step: 1,
43
- if: function _if(mask) {
44
- return mask.type !== MASK_TYPE$1.Circle;
45
- }
46
- }), __metadata("design:type", Number)], MaskStyle.prototype, "width", void 0);
47
-
48
- __decorate([Field({
49
- step: 1,
50
- if: function _if(mask) {
51
- return mask.type !== MASK_TYPE$1.Circle;
52
- }
53
- }), __metadata("design:type", Number)], MaskStyle.prototype, "height", void 0);
54
-
55
- return MaskStyle;
56
- }();
57
-
58
- var Mask$2 = function (_super) {
59
- __extends(Mask, _super);
60
-
61
- function Mask() {
62
- var _this = _super !== null && _super.apply(this, arguments) || this;
63
-
64
- _this.style = {};
65
- _this.resource = '';
66
- _this.spriteName = '';
67
- return _this;
68
- }
69
-
70
- Mask.prototype.init = function (obj) {
71
- _extends(this, obj);
72
- };
73
-
74
- Mask.componentName = 'Mask';
75
-
76
- __decorate([Field({
77
- type: 'selector',
78
- options: (_a = {}, _a[MASK_TYPE$1.Circle] = MASK_TYPE$1.Circle, _a[MASK_TYPE$1.Ellipse] = MASK_TYPE$1.Ellipse, _a[MASK_TYPE$1.Img] = MASK_TYPE$1.Img, _a[MASK_TYPE$1.Rect] = MASK_TYPE$1.Rect, _a[MASK_TYPE$1.RoundedRect] = MASK_TYPE$1.RoundedRect, _a),
79
- alias: 'type',
80
- default: MASK_TYPE$1.Circle
81
- }), __metadata("design:type", String)], Mask.prototype, "mask_type", void 0);
82
-
83
- __decorate([Field(function () {
84
- return MaskStyle;
85
- }), __metadata("design:type", Object)], Mask.prototype, "style", void 0);
86
-
87
- __decorate([Field({
88
- type: 'resource',
89
- if: function _if(mask) {
90
- return mask.type === MASK_TYPE$1.Img || MASK_TYPE$1.Sprite;
91
- }
92
- }), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
93
-
94
- return Mask;
95
- }(Component);
96
-
97
- var Mask$3 = Mask$2;
98
- var resourceKeySplit = '_s|r|c_';
99
- var propertyForGraphics = {
100
- Circle: ['x', 'y', 'radius'],
101
- Ellipse: ['x', 'y', 'width', 'height'],
102
- Rect: ['x', 'y', 'width', 'height'],
103
- RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
104
- Polygon: ['paths']
105
- };
106
- var functionForGraphics = {
107
- Circle: 'drawCircle',
108
- Ellipse: 'drawEllipse',
109
- Rect: 'drawRect',
110
- RoundedRect: 'drawRoundedRect',
111
- Polygon: 'drawPolygon'
112
- };
113
- var MASK_TYPE;
114
-
115
- (function (MASK_TYPE) {
116
- MASK_TYPE["Circle"] = "Circle";
117
- MASK_TYPE["Ellipse"] = "Ellipse";
118
- MASK_TYPE["Rect"] = "Rect";
119
- MASK_TYPE["RoundedRect"] = "RoundedRect";
120
- MASK_TYPE["Polygon"] = "Polygon";
121
- MASK_TYPE["Img"] = "Img";
122
- MASK_TYPE["Sprite"] = "Sprite";
123
- })(MASK_TYPE || (MASK_TYPE = {}));
124
-
125
- var Mask = function (_super) {
126
- __extends(Mask, _super);
127
-
128
- function Mask() {
129
- var _this = _super !== null && _super.apply(this, arguments) || this;
130
-
131
- _this.name = 'Mask';
132
- _this.changedCache = {};
133
- _this.maskSpriteCache = {};
134
- return _this;
135
- }
136
-
137
- Mask.prototype.init = function () {
138
- this.renderSystem = this.game.getSystem(RendererSystem);
139
- this.renderSystem.rendererManager.register(this);
140
- };
141
-
142
- Mask.prototype.rendererUpdate = function () {
143
- this.changedCache = {};
144
- };
145
-
146
- Mask.prototype.componentChanged = function (changed) {
147
- if (changed.component.name !== 'Mask') return;
148
-
149
- switch (changed.type) {
150
- case OBSERVER_TYPE.ADD:
151
- this.add(changed);
152
- break;
153
-
154
- case OBSERVER_TYPE.REMOVE:
155
- this.remove(changed);
156
- break;
157
-
158
- case OBSERVER_TYPE.CHANGE:
159
- this.change(changed);
160
- break;
161
- }
162
- };
163
-
164
- Mask.prototype.add = function (changed) {
165
- var component = changed.component;
166
-
167
- if (!(component.type in MASK_TYPE)) {
168
- throw new Error('no have Mask type: ' + component.type);
169
- }
170
-
171
- if (!component.style) {
172
- throw new Error('no have Mask style: ' + component.type);
173
- }
174
-
175
- var mask;
176
-
177
- switch (component.type) {
178
- case MASK_TYPE.Circle:
179
- mask = this.createGraphics(component);
180
- break;
181
-
182
- case MASK_TYPE.Ellipse:
183
- mask = this.createGraphics(component);
184
- break;
185
-
186
- case MASK_TYPE.Rect:
187
- mask = this.createGraphics(component);
188
- break;
189
-
190
- case MASK_TYPE.RoundedRect:
191
- mask = this.createGraphics(component);
192
- break;
193
-
194
- case MASK_TYPE.Polygon:
195
- mask = this.createGraphics(component);
196
- break;
197
-
198
- case MASK_TYPE.Img:
199
- mask = this.createSprite(component);
200
- break;
201
-
202
- case MASK_TYPE.Sprite:
203
- mask = this.createSprite(component);
204
- break;
205
- }
206
-
207
- if (!mask) {
208
- throw new Error('no have mask instance, check your mask params: ' + component.type);
209
- }
210
-
211
- var container = this.containerManager.getContainer(changed.gameObject.id);
212
- container.mask = mask;
213
- container.addChild(mask);
214
- };
215
-
216
- Mask.prototype.remove = function (changed) {
217
- var container = this.containerManager.getContainer(changed.gameObject.id);
218
- container.removeChild(container.mask);
219
- container.mask.destroy({
220
- children: true
221
- });
222
- container.mask = null;
223
- delete this.maskSpriteCache[changed.gameObject.id];
224
- };
225
-
226
- Mask.prototype.change = function (changed) {
227
- if (this.changedCache[changed.gameObject.id]) return;
228
- var component = changed.component;
229
-
230
- if (changed.prop.prop[0] === 'type') {
231
- this.changedCache[changed.gameObject.id] = true;
232
-
233
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
234
- this.remove(changed);
235
- this.add(changed);
236
- component._lastType = component.type;
237
- } else {
238
- this.redrawGraphics(changed);
239
- }
240
- } else if (changed.prop.prop[0] === 'style') {
241
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
242
- this.changeSpriteStyle(component);
243
- } else {
244
- this.redrawGraphics(changed);
245
- }
246
- } else if (changed.prop.prop[0] === 'resource') {
247
- this.changedCache[changed.gameObject.id] = true;
248
- this.changeSprite(component);
249
- } else if (changed.prop.prop[0] === 'spriteName') {
250
- this.changedCache[changed.gameObject.id] = true;
251
- this.changeSprite(component);
252
- }
253
- };
254
-
255
- Mask.prototype.createGraphics = function (component) {
256
- var graphics = new Graphics();
257
- this.draw(graphics, component);
258
- return graphics;
259
- };
260
-
261
- Mask.prototype.redrawGraphics = function (changed) {
262
- var container = this.containerManager.getContainer(changed.gameObject.id);
263
- var graphics = container.mask;
264
- graphics.clear();
265
- this.draw(graphics, changed.component);
266
- };
267
-
268
- Mask.prototype.draw = function (graphics, component) {
269
- var e_1, _a;
270
-
271
- var params = [];
272
-
273
- try {
274
- for (var _b = __values(propertyForGraphics[component.type]), _c = _b.next(); !_c.done; _c = _b.next()) {
275
- var key = _c.value;
276
- params.push(component.style[key]);
277
- }
278
- } catch (e_1_1) {
279
- e_1 = {
280
- error: e_1_1
281
- };
282
- } finally {
283
- try {
284
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
285
- } finally {
286
- if (e_1) throw e_1.error;
287
- }
288
- }
289
-
290
- graphics.beginFill(0x000000, 1);
291
- graphics[functionForGraphics[component.type]].apply(graphics, __spread(params));
292
- graphics.endFill();
293
- };
294
-
295
- Mask.prototype.createSprite = function (component) {
296
- var sprite = new Sprite(null);
297
- this.maskSpriteCache[component.gameObject.id] = sprite;
298
- this.setSprite(component, sprite);
299
- return sprite.sprite;
300
- };
301
-
302
- Mask.prototype.changeSpriteStyle = function (component) {
303
- var sprite = this.maskSpriteCache[component.gameObject.id];
304
- sprite.sprite.width = component.style.width;
305
- sprite.sprite.height = component.style.height;
306
- sprite.sprite.position.x = component.style.x;
307
- sprite.sprite.position.y = component.style.y;
308
- };
309
-
310
- Mask.prototype.changeSprite = function (component) {
311
- var sprite = this.maskSpriteCache[component.gameObject.id];
312
- this.setSprite(component, sprite);
313
- };
314
-
315
- Mask.prototype.setSprite = function (component, sprite) {
316
- return __awaiter(this, void 0, void 0, function () {
317
- var res, asyncId, img, texture;
318
- return __generator(this, function (_a) {
319
- switch (_a.label) {
320
- case 0:
321
- _a.trys.push([0, 2,, 3]);
322
-
323
- asyncId = this.increaseAsyncId(component.gameObject.id);
324
- return [4, resource.getResource(component.resource)];
325
-
326
- case 1:
327
- res = _a.sent();
328
- if (!this.validateAsyncId(component.gameObject.id, asyncId)) return [2];
329
- return [3, 3];
330
-
331
- case 2:
332
- _a.sent();
333
-
334
- throw new Error('mask resource load error');
335
-
336
- case 3:
337
- if (component.type === MASK_TYPE.Sprite) {
338
- img = component.resource + resourceKeySplit + component.spriteName;
339
- texture = res.instance[img];
340
- sprite.image = texture;
341
- } else {
342
- sprite.image = res.data.image;
343
- }
344
-
345
- sprite.sprite.width = component.style.width;
346
- sprite.sprite.height = component.style.height;
347
- sprite.sprite.position.x = component.style.x;
348
- sprite.sprite.position.y = component.style.y;
349
- return [2];
350
- }
351
- });
352
- });
353
- };
354
-
355
- Mask.systemName = 'Mask';
356
- Mask = __decorate([decorators.componentObserver({
357
- Mask: ['type', {
358
- prop: ['style'],
359
- deep: true
360
- }, 'resource', 'spriteName']
361
- })], Mask);
362
- return Mask;
363
- }(Renderer);
364
-
365
- var Mask$1 = Mask;
366
- export { MASK_TYPE$1 as MASK_TYPE, Mask$3 as Mask, Mask$1 as MaskSystem };