@eva/plugin-renderer-mask 1.2.2-alpha.0 → 1.2.2-alpha.4

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.
@@ -1,10 +1,10 @@
1
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
2
 
3
- this.EVA = this.EVA || {};
4
- this.EVA.plugin = this.EVA.plugin || {};
5
- this.EVA.plugin.renderer = this.EVA.plugin.renderer || {};
3
+ window.EVA = window.EVA || {};
4
+ window.EVA.plugin = window.EVA.plugin || {};
5
+ window.EVA.plugin.renderer = window.EVA.plugin.renderer || {};
6
6
 
7
- this.EVA.plugin.renderer.mask = function (exports, eva_js, pluginRenderer, rendererAdapter) {
7
+ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter) {
8
8
  'use strict';
9
9
 
10
10
  var _extendStatics = function extendStatics(d, b) {
@@ -567,3 +567,5 @@ this.EVA.plugin.renderer.mask = function (exports, eva_js, pluginRenderer, rende
567
567
  });
568
568
  return exports;
569
569
  }({}, EVA, EVA.plugin.renderer, EVA.rendererAdapter);
570
+
571
+ window.EVA.plugin.renderer.mask = window.EVA.plugin.renderer.mask || _EVA_IIFE_mask;
@@ -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}).apply(this,arguments)}this.EVA=this.EVA||{},this.EVA.plugin=this.EVA.plugin||{},this.EVA.plugin.renderer=this.EVA.plugin.renderer||{},this.EVA.plugin.renderer.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),y={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},d={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.")}(y[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[d[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;return s(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,t.resource.getResource(e.resource)];case 1:return n=a.sent(),[3,3];case 2:throw a.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(o=e.resource+"_s|r|c_"+e.spriteName,i=n.instance[o],r.image=i):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);
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)}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),y={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},d={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.")}(y[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[d[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;return s(this,(function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,t.resource.getResource(e.resource)];case 1:return n=a.sent(),[3,3];case 2:throw a.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(o=e.resource+"_s|r|c_"+e.spriteName,i=n.instance[o],r.image=i):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);
@@ -0,0 +1,311 @@
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 { __extends, __decorate, __values, __spread, __awaiter, __generator } from 'tslib';
4
+ import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
5
+ import { type } 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
+ var MASK_TYPE$1;
9
+
10
+ (function (MASK_TYPE) {
11
+ MASK_TYPE["Circle"] = "Circle";
12
+ MASK_TYPE["Ellipse"] = "Ellipse";
13
+ MASK_TYPE["Rect"] = "Rect";
14
+ MASK_TYPE["RoundedRect"] = "RoundedRect";
15
+ MASK_TYPE["Polygon"] = "Polygon";
16
+ MASK_TYPE["Img"] = "Img";
17
+ MASK_TYPE["Sprite"] = "Sprite";
18
+ })(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
19
+
20
+ var Mask$2 = function (_super) {
21
+ __extends(Mask, _super);
22
+
23
+ function Mask() {
24
+ var _this = _super !== null && _super.apply(this, arguments) || this;
25
+
26
+ _this.style = {};
27
+ _this.resource = '';
28
+ _this.spriteName = '';
29
+ return _this;
30
+ }
31
+
32
+ Mask.prototype.init = function (obj) {
33
+ _extends(this, obj);
34
+ };
35
+
36
+ Mask.componentName = 'Mask';
37
+
38
+ __decorate([type('string')], Mask.prototype, "resource", void 0);
39
+
40
+ __decorate([type('string')], Mask.prototype, "spriteName", void 0);
41
+
42
+ return Mask;
43
+ }(Component);
44
+
45
+ var Mask$3 = Mask$2;
46
+ var resourceKeySplit = '_s|r|c_';
47
+ var propertyForGraphics = {
48
+ Circle: ['x', 'y', 'radius'],
49
+ Ellipse: ['x', 'y', 'width', 'height'],
50
+ Rect: ['x', 'y', 'width', 'height'],
51
+ RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
52
+ Polygon: ['paths']
53
+ };
54
+ var functionForGraphics = {
55
+ Circle: 'drawCircle',
56
+ Ellipse: 'drawEllipse',
57
+ Rect: 'drawRect',
58
+ RoundedRect: 'drawRoundedRect',
59
+ Polygon: 'drawPolygon'
60
+ };
61
+ var MASK_TYPE;
62
+
63
+ (function (MASK_TYPE) {
64
+ MASK_TYPE["Circle"] = "Circle";
65
+ MASK_TYPE["Ellipse"] = "Ellipse";
66
+ MASK_TYPE["Rect"] = "Rect";
67
+ MASK_TYPE["RoundedRect"] = "RoundedRect";
68
+ MASK_TYPE["Polygon"] = "Polygon";
69
+ MASK_TYPE["Img"] = "Img";
70
+ MASK_TYPE["Sprite"] = "Sprite";
71
+ })(MASK_TYPE || (MASK_TYPE = {}));
72
+
73
+ var Mask = function (_super) {
74
+ __extends(Mask, _super);
75
+
76
+ function Mask() {
77
+ var _this = _super !== null && _super.apply(this, arguments) || this;
78
+
79
+ _this.name = 'Mask';
80
+ _this.changedCache = {};
81
+ _this.maskSpriteCache = {};
82
+ return _this;
83
+ }
84
+
85
+ Mask.prototype.init = function () {
86
+ this.renderSystem = this.game.getSystem(RendererSystem);
87
+ this.renderSystem.rendererManager.register(this);
88
+ };
89
+
90
+ Mask.prototype.rendererUpdate = function () {
91
+ this.changedCache = {};
92
+ };
93
+
94
+ Mask.prototype.componentChanged = function (changed) {
95
+ if (changed.component.name !== 'Mask') return;
96
+
97
+ switch (changed.type) {
98
+ case OBSERVER_TYPE.ADD:
99
+ this.add(changed);
100
+ break;
101
+
102
+ case OBSERVER_TYPE.REMOVE:
103
+ this.remove(changed);
104
+ break;
105
+
106
+ case OBSERVER_TYPE.CHANGE:
107
+ this.change(changed);
108
+ break;
109
+ }
110
+ };
111
+
112
+ Mask.prototype.add = function (changed) {
113
+ var component = changed.component;
114
+
115
+ if (!(component.type in MASK_TYPE)) {
116
+ throw new Error('no have Mask type: ' + component.type);
117
+ }
118
+
119
+ if (!component.style) {
120
+ throw new Error('no have Mask style: ' + component.type);
121
+ }
122
+
123
+ var mask;
124
+
125
+ switch (component.type) {
126
+ case MASK_TYPE.Circle:
127
+ mask = this.createGraphics(component);
128
+ break;
129
+
130
+ case MASK_TYPE.Ellipse:
131
+ mask = this.createGraphics(component);
132
+ break;
133
+
134
+ case MASK_TYPE.Rect:
135
+ mask = this.createGraphics(component);
136
+ break;
137
+
138
+ case MASK_TYPE.RoundedRect:
139
+ mask = this.createGraphics(component);
140
+ break;
141
+
142
+ case MASK_TYPE.Polygon:
143
+ mask = this.createGraphics(component);
144
+ break;
145
+
146
+ case MASK_TYPE.Img:
147
+ mask = this.createSprite(component);
148
+ break;
149
+
150
+ case MASK_TYPE.Sprite:
151
+ mask = this.createSprite(component);
152
+ break;
153
+ }
154
+
155
+ if (!mask) {
156
+ throw new Error('no have mask instance, check your mask params: ' + component.type);
157
+ }
158
+
159
+ var container = this.containerManager.getContainer(changed.gameObject.id);
160
+ container.mask = mask;
161
+ container.addChild(mask);
162
+ };
163
+
164
+ Mask.prototype.remove = function (changed) {
165
+ var container = this.containerManager.getContainer(changed.gameObject.id);
166
+ container.removeChild(container.mask);
167
+ container.mask.destroy({
168
+ children: true
169
+ });
170
+ container.mask = null;
171
+ delete this.maskSpriteCache[changed.gameObject.id];
172
+ };
173
+
174
+ Mask.prototype.change = function (changed) {
175
+ if (this.changedCache[changed.gameObject.id]) return;
176
+ var component = changed.component;
177
+
178
+ if (changed.prop.prop[0] === 'type') {
179
+ this.changedCache[changed.gameObject.id] = true;
180
+
181
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
182
+ this.remove(changed);
183
+ this.add(changed);
184
+ } else {
185
+ this.redrawGraphics(changed);
186
+ }
187
+ } else if (changed.prop.prop[0] === 'style') {
188
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
189
+ this.changeSpriteStyle(component);
190
+ } else {
191
+ this.redrawGraphics(changed);
192
+ }
193
+ } else if (changed.prop.prop[0] === 'resource') {
194
+ this.changedCache[changed.gameObject.id] = true;
195
+ this.changeSprite(component);
196
+ } else if (changed.prop.prop[0] === 'spriteName') {
197
+ this.changedCache[changed.gameObject.id] = true;
198
+ this.changeSprite(component);
199
+ }
200
+ };
201
+
202
+ Mask.prototype.createGraphics = function (component) {
203
+ var graphics = new Graphics();
204
+ this.draw(graphics, component);
205
+ return graphics;
206
+ };
207
+
208
+ Mask.prototype.redrawGraphics = function (changed) {
209
+ var container = this.containerManager.getContainer(changed.gameObject.id);
210
+ var graphics = container.mask;
211
+ graphics.clear();
212
+ this.draw(graphics, changed.component);
213
+ };
214
+
215
+ Mask.prototype.draw = function (graphics, component) {
216
+ var e_1, _a;
217
+
218
+ var params = [];
219
+
220
+ try {
221
+ for (var _b = __values(propertyForGraphics[component.type]), _c = _b.next(); !_c.done; _c = _b.next()) {
222
+ var key = _c.value;
223
+ params.push(component.style[key]);
224
+ }
225
+ } catch (e_1_1) {
226
+ e_1 = {
227
+ error: e_1_1
228
+ };
229
+ } finally {
230
+ try {
231
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
232
+ } finally {
233
+ if (e_1) throw e_1.error;
234
+ }
235
+ }
236
+
237
+ graphics.beginFill(0x000000, 1);
238
+ graphics[functionForGraphics[component.type]].apply(graphics, __spread(params));
239
+ graphics.endFill();
240
+ };
241
+
242
+ Mask.prototype.createSprite = function (component) {
243
+ var sprite = new Sprite(null);
244
+ this.maskSpriteCache[component.gameObject.id] = sprite;
245
+ this.setSprite(component, sprite);
246
+ return sprite.sprite;
247
+ };
248
+
249
+ Mask.prototype.changeSpriteStyle = function (component) {
250
+ var sprite = this.maskSpriteCache[component.gameObject.id];
251
+ sprite.sprite.width = component.style.width;
252
+ sprite.sprite.height = component.style.height;
253
+ sprite.sprite.position.x = component.style.x;
254
+ sprite.sprite.position.y = component.style.y;
255
+ };
256
+
257
+ Mask.prototype.changeSprite = function (component) {
258
+ var sprite = this.maskSpriteCache[component.gameObject.id];
259
+ this.setSprite(component, sprite);
260
+ };
261
+
262
+ Mask.prototype.setSprite = function (component, sprite) {
263
+ return __awaiter(this, void 0, void 0, function () {
264
+ var res, img, texture;
265
+ return __generator(this, function (_a) {
266
+ switch (_a.label) {
267
+ case 0:
268
+ _a.trys.push([0, 2,, 3]);
269
+
270
+ return [4, resource.getResource(component.resource)];
271
+
272
+ case 1:
273
+ res = _a.sent();
274
+ return [3, 3];
275
+
276
+ case 2:
277
+ _a.sent();
278
+
279
+ throw new Error('mask resource load error');
280
+
281
+ case 3:
282
+ if (component.type === MASK_TYPE.Sprite) {
283
+ img = component.resource + resourceKeySplit + component.spriteName;
284
+ texture = res.instance[img];
285
+ sprite.image = texture;
286
+ } else {
287
+ sprite.image = res.data.image;
288
+ }
289
+
290
+ sprite.sprite.width = component.style.width;
291
+ sprite.sprite.height = component.style.height;
292
+ sprite.sprite.position.x = component.style.x;
293
+ sprite.sprite.position.y = component.style.y;
294
+ return [2];
295
+ }
296
+ });
297
+ });
298
+ };
299
+
300
+ Mask.systemName = 'Mask';
301
+ Mask = __decorate([decorators.componentObserver({
302
+ Mask: ['type', {
303
+ prop: ['style'],
304
+ deep: true
305
+ }, 'resource', 'spriteName']
306
+ })], Mask);
307
+ return Mask;
308
+ }(Renderer);
309
+
310
+ var Mask$1 = Mask;
311
+ export { MASK_TYPE$1 as MASK_TYPE, Mask$3 as Mask, Mask$1 as MaskSystem };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-mask",
3
- "version": "1.2.2-alpha.0",
3
+ "version": "1.2.2-alpha.4",
4
4
  "description": "@eva/plugin-renderer-mask",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-mask.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.2.2-alpha.0",
23
- "@eva/renderer-adapter": "1.2.2-alpha.0",
24
- "@eva/eva.js": "1.2.2-alpha.0",
22
+ "@eva/plugin-renderer": "1.2.2-alpha.4",
23
+ "@eva/renderer-adapter": "1.2.2-alpha.4",
24
+ "@eva/eva.js": "1.2.2-alpha.4",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }