@eva/plugin-renderer-mask 2.0.0-beta.1 → 2.0.0-beta.3

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