@eva/plugin-renderer-event 1.2.0 → 1.3.0-alpha.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.
@@ -0,0 +1,374 @@
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
+ this.EVA = this.EVA || {};
4
+ this.EVA.plugin = this.EVA.plugin || {};
5
+ this.EVA.plugin.renderer = this.EVA.plugin.renderer || {};
6
+
7
+ this.EVA.plugin.renderer.event = function (exports, pluginRenderer, eva_js, pixi_js) {
8
+ 'use strict';
9
+
10
+ var _extendStatics = function extendStatics(d, b) {
11
+ _extendStatics = Object.setPrototypeOf || {
12
+ __proto__: []
13
+ } instanceof Array && function (d, b) {
14
+ d.__proto__ = b;
15
+ } || function (d, b) {
16
+ for (var p in b) {
17
+ if (b.hasOwnProperty(p)) d[p] = b[p];
18
+ }
19
+ };
20
+
21
+ return _extendStatics(d, b);
22
+ };
23
+
24
+ function __extends(d, b) {
25
+ _extendStatics(d, b);
26
+
27
+ function __() {
28
+ this.constructor = d;
29
+ }
30
+
31
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
+ }
33
+
34
+ function __decorate(decorators, target, key, desc) {
35
+ var c = arguments.length,
36
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
37
+ d;
38
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) {
39
+ if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
40
+ }
41
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
42
+ }
43
+
44
+ function __values(o) {
45
+ var s = typeof Symbol === "function" && Symbol.iterator,
46
+ m = s && o[s],
47
+ i = 0;
48
+ if (m) return m.call(o);
49
+ if (o && typeof o.length === "number") return {
50
+ next: function next() {
51
+ if (o && i >= o.length) o = void 0;
52
+ return {
53
+ value: o && o[i++],
54
+ done: !o
55
+ };
56
+ }
57
+ };
58
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
59
+ }
60
+
61
+ function __read(o, n) {
62
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
63
+ if (!m) return o;
64
+ var i = m.call(o),
65
+ r,
66
+ ar = [],
67
+ e;
68
+
69
+ try {
70
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
71
+ ar.push(r.value);
72
+ }
73
+ } catch (error) {
74
+ e = {
75
+ error: error
76
+ };
77
+ } finally {
78
+ try {
79
+ if (r && !r.done && (m = i["return"])) m.call(i);
80
+ } finally {
81
+ if (e) throw e.error;
82
+ }
83
+ }
84
+
85
+ return ar;
86
+ }
87
+
88
+ function __spread() {
89
+ for (var ar = [], i = 0; i < arguments.length; i++) {
90
+ ar = ar.concat(__read(arguments[i]));
91
+ }
92
+
93
+ return ar;
94
+ }
95
+
96
+ var hitAreaFunc = {
97
+ Circle: pixi_js.Circle,
98
+ Ellipse: pixi_js.Ellipse,
99
+ Polygon: pixi_js.Polygon,
100
+ Rect: pixi_js.Rectangle,
101
+ RoundedRect: pixi_js.RoundedRectangle
102
+ };
103
+ var propertyForHitArea = {
104
+ Circle: ['x', 'y', 'radius'],
105
+ Ellipse: ['x', 'y', 'width', 'height'],
106
+ Rect: ['x', 'y', 'width', 'height'],
107
+ RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
108
+ Polygon: ['paths']
109
+ };
110
+
111
+ var Event$2 = function (_super) {
112
+ __extends(Event, _super);
113
+
114
+ function Event() {
115
+ var _this = _super !== null && _super.apply(this, arguments) || this;
116
+
117
+ _this.name = 'Event';
118
+ return _this;
119
+ }
120
+
121
+ Event.prototype.init = function (_a) {
122
+ var _b = (_a === void 0 ? {} : _a).moveWhenInside,
123
+ moveWhenInside = _b === void 0 ? false : _b;
124
+ this.renderSystem = this.game.getSystem(pluginRenderer.RendererSystem);
125
+ this.renderSystem.rendererManager.register(this);
126
+
127
+ try {
128
+ this.renderSystem.application.renderer.plugins.interaction.moveWhenInside = moveWhenInside;
129
+ } catch (e) {
130
+ console.error('Setting moveWhenInside error.', e);
131
+ }
132
+ };
133
+
134
+ Event.prototype.componentChanged = function (changed) {
135
+ switch (changed.type) {
136
+ case eva_js.OBSERVER_TYPE.ADD:
137
+ this.add(changed);
138
+ break;
139
+
140
+ case eva_js.OBSERVER_TYPE.REMOVE:
141
+ this.remove(changed);
142
+ break;
143
+
144
+ case eva_js.OBSERVER_TYPE.CHANGE:
145
+ this.change(changed);
146
+ break;
147
+ }
148
+ };
149
+
150
+ Event.prototype.add = function (changed) {
151
+ var container = this.containerManager.getContainer(changed.gameObject.id);
152
+ container.interactive = true;
153
+ container.interactiveChildren = true;
154
+ var component = changed.component;
155
+
156
+ if (component.hitArea) {
157
+ this.addHitArea(changed, container, component.hitArea);
158
+ }
159
+
160
+ container.on('pointertap', function (e) {
161
+ component.emit('tap', {
162
+ stopPropagation: function stopPropagation() {
163
+ return e.stopPropagation();
164
+ },
165
+ data: {
166
+ pointerId: e.data.pointerId,
167
+ position: {
168
+ x: e.data.global.x,
169
+ y: e.data.global.y
170
+ }
171
+ },
172
+ gameObject: component.gameObject
173
+ });
174
+ });
175
+ container.on('pointerdown', function (e) {
176
+ component.emit('touchstart', {
177
+ stopPropagation: function stopPropagation() {
178
+ return e.stopPropagation();
179
+ },
180
+ data: {
181
+ pointerId: e.data.pointerId,
182
+ position: {
183
+ x: e.data.global.x,
184
+ y: e.data.global.y
185
+ }
186
+ },
187
+ gameObject: component.gameObject
188
+ });
189
+ });
190
+ container.on('pointermove', function (e) {
191
+ component.emit('touchmove', {
192
+ stopPropagation: function stopPropagation() {
193
+ return e.stopPropagation();
194
+ },
195
+ data: {
196
+ pointerId: e.data.pointerId,
197
+ position: {
198
+ x: e.data.global.x,
199
+ y: e.data.global.y
200
+ }
201
+ },
202
+ gameObject: component.gameObject
203
+ });
204
+ });
205
+ container.on('pointerup', function (e) {
206
+ component.emit('touchend', {
207
+ stopPropagation: function stopPropagation() {
208
+ return e.stopPropagation();
209
+ },
210
+ data: {
211
+ pointerId: e.data.pointerId,
212
+ position: {
213
+ x: e.data.global.x,
214
+ y: e.data.global.y
215
+ }
216
+ },
217
+ gameObject: component.gameObject
218
+ });
219
+ });
220
+ container.on('pointerupoutside', function (e) {
221
+ component.emit('touchendoutside', {
222
+ stopPropagation: function stopPropagation() {
223
+ return e.stopPropagation();
224
+ },
225
+ data: {
226
+ pointerId: e.data.pointerId,
227
+ position: {
228
+ x: e.data.global.x,
229
+ y: e.data.global.y
230
+ }
231
+ },
232
+ gameObject: component.gameObject
233
+ });
234
+ });
235
+ container.on('pointercancel', function (e) {
236
+ component.emit('touchcancel', {
237
+ stopPropagation: function stopPropagation() {
238
+ return e.stopPropagation();
239
+ },
240
+ data: {
241
+ pointerId: e.data.pointerId,
242
+ position: {
243
+ x: e.data.global.x,
244
+ y: e.data.global.y
245
+ }
246
+ },
247
+ gameObject: component.gameObject
248
+ });
249
+ });
250
+ };
251
+
252
+ Event.prototype.remove = function (changed) {
253
+ var container = this.containerManager.getContainer(changed.gameObject.id);
254
+ container.interactive = false;
255
+ container.off('tap');
256
+ container.off('pointerdown');
257
+ container.off('pointermove');
258
+ container.off('pointerup');
259
+ container.off('pointerupoutside');
260
+ container.off('pointercancel');
261
+ changed.component.removeAllListeners();
262
+ };
263
+
264
+ Event.prototype.change = function (changed) {
265
+ var container = this.containerManager.getContainer(changed.gameObject.id);
266
+ container.interactive = true;
267
+ var component = changed.component;
268
+
269
+ if (component.hitArea) {
270
+ this.addHitArea(changed, container, component.hitArea);
271
+ } else {
272
+ component.hitArea = null;
273
+ }
274
+ };
275
+
276
+ Event.prototype.addHitArea = function (changed, container, hitArea) {
277
+ var e_1, _a, _b;
278
+
279
+ var type = hitArea.type,
280
+ style = hitArea.style;
281
+
282
+ if (!hitAreaFunc[type]) {
283
+ console.error(changed.gameObject.name + "'s hitArea type is not defined");
284
+ return;
285
+ }
286
+
287
+ var params = [];
288
+
289
+ try {
290
+ for (var _c = __values(propertyForHitArea[type]), _d = _c.next(); !_d.done; _d = _c.next()) {
291
+ var key = _d.value;
292
+ params.push(style[key]);
293
+ }
294
+ } catch (e_1_1) {
295
+ e_1 = {
296
+ error: e_1_1
297
+ };
298
+ } finally {
299
+ try {
300
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
301
+ } finally {
302
+ if (e_1) throw e_1.error;
303
+ }
304
+ }
305
+
306
+ var hitAreaShape = new ((_b = hitAreaFunc[type]).bind.apply(_b, __spread([void 0], params)))();
307
+ container.hitArea = hitAreaShape;
308
+ };
309
+
310
+ Event.systemName = 'Event';
311
+ Event = __decorate([eva_js.decorators.componentObserver({
312
+ Event: [{
313
+ prop: ['hitArea'],
314
+ deep: true
315
+ }]
316
+ })], Event);
317
+ return Event;
318
+ }(pluginRenderer.Renderer);
319
+
320
+ var Event$3 = Event$2;
321
+ exports.HIT_AREA_TYPE = void 0;
322
+
323
+ (function (HIT_AREA_TYPE) {
324
+ HIT_AREA_TYPE["Circle"] = "Circle";
325
+ HIT_AREA_TYPE["Ellipse"] = "Ellipse";
326
+ HIT_AREA_TYPE["Polygon"] = "Polygon";
327
+ HIT_AREA_TYPE["Rect"] = "Rect";
328
+ HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
329
+ })(exports.HIT_AREA_TYPE || (exports.HIT_AREA_TYPE = {}));
330
+
331
+ var Event = function (_super) {
332
+ __extends(Event, _super);
333
+
334
+ function Event() {
335
+ var _this = _super !== null && _super.apply(this, arguments) || this;
336
+
337
+ _this.hitArea = undefined;
338
+ return _this;
339
+ }
340
+
341
+ Event.prototype.init = function (params) {
342
+ params && _extends(this, params);
343
+ };
344
+
345
+ Event.prototype.emit = function (en) {
346
+ var args = [];
347
+
348
+ for (var _i = 1; _i < arguments.length; _i++) {
349
+ args[_i - 1] = arguments[_i];
350
+ }
351
+
352
+ return _super.prototype.emit.apply(this, __spread([en], args));
353
+ };
354
+
355
+ Event.prototype.once = function (en, fn, context) {
356
+ return _super.prototype.once.call(this, en, fn, context);
357
+ };
358
+
359
+ Event.prototype.on = function (en, fn, context) {
360
+ return _super.prototype.on.call(this, en, fn, context);
361
+ };
362
+
363
+ Event.componentName = 'Event';
364
+ return Event;
365
+ }(eva_js.Component);
366
+
367
+ var Event$1 = Event;
368
+ exports.Event = Event$1;
369
+ exports.EventSystem = Event$3;
370
+ Object.defineProperty(exports, '__esModule', {
371
+ value: true
372
+ });
373
+ return exports;
374
+ }({}, EVA.plugin.renderer, EVA, PIXI);
@@ -0,0 +1 @@
1
+ function _extends(){return(_extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).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.event=function(t,e,n,o){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function i(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function a(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var o,r,i=n.call(t),a=[];try{for(;(void 0===e||e-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(t){r={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return a}function p(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(a(arguments[e]));return t}var c,l={Circle:o.Circle,Ellipse:o.Ellipse,Polygon:o.Polygon,Rect:o.Rectangle,RoundedRect:o.RoundedRectangle},d={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},u=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Event",e}return i(o,t),o.prototype.init=function(t){var n=(void 0===t?{}:t).moveWhenInside,o=void 0!==n&&n;this.renderSystem=this.game.getSystem(e.RendererSystem),this.renderSystem.rendererManager.register(this);try{this.renderSystem.application.renderer.plugins.interaction.moveWhenInside=o}catch(t){console.error("Setting moveWhenInside error.",t)}},o.prototype.componentChanged=function(t){switch(t.type){case n.OBSERVER_TYPE.ADD:this.add(t);break;case n.OBSERVER_TYPE.REMOVE:this.remove(t);break;case n.OBSERVER_TYPE.CHANGE:this.change(t)}},o.prototype.add=function(t){var e=this.containerManager.getContainer(t.gameObject.id);e.interactive=!0,e.interactiveChildren=!0;var n=t.component;n.hitArea&&this.addHitArea(t,e,n.hitArea),e.on("pointertap",(function(t){n.emit("tap",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})})),e.on("pointerdown",(function(t){n.emit("touchstart",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})})),e.on("pointermove",(function(t){n.emit("touchmove",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})})),e.on("pointerup",(function(t){n.emit("touchend",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})})),e.on("pointerupoutside",(function(t){n.emit("touchendoutside",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})})),e.on("pointercancel",(function(t){n.emit("touchcancel",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y}},gameObject:n.gameObject})}))},o.prototype.remove=function(t){var e=this.containerManager.getContainer(t.gameObject.id);e.interactive=!1,e.off("tap"),e.off("pointerdown"),e.off("pointermove"),e.off("pointerup"),e.off("pointerupoutside"),e.off("pointercancel"),t.component.removeAllListeners()},o.prototype.change=function(t){var e=this.containerManager.getContainer(t.gameObject.id);e.interactive=!0;var n=t.component;n.hitArea?this.addHitArea(t,e,n.hitArea):n.hitArea=null},o.prototype.addHitArea=function(t,e,n){var o,r,i,a=n.type,c=n.style;if(l[a]){var u=[];try{for(var s=function(t){var e="function"==typeof Symbol&&Symbol.iterator,n=e&&t[e],o=0;if(n)return n.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&o>=t.length&&(t=void 0),{value:t&&t[o++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(d[a]),f=s.next();!f.done;f=s.next()){var y=f.value;u.push(c[y])}}catch(t){o={error:t}}finally{try{f&&!f.done&&(r=s.return)&&r.call(s)}finally{if(o)throw o.error}}var g=new((i=l[a]).bind.apply(i,p([void 0],u)));e.hitArea=g}else console.error(t.gameObject.name+"'s hitArea type is not defined")},o.systemName="Event",o=function(t,e,n,o){var r,i=arguments.length,a=i<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,o);else for(var p=t.length-1;p>=0;p--)(r=t[p])&&(a=(i<3?r(a):i>3?r(e,n,a):r(e,n))||a);return i>3&&a&&Object.defineProperty(e,n,a),a}([n.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],o)}(e.Renderer);t.HIT_AREA_TYPE=void 0,(c=t.HIT_AREA_TYPE||(t.HIT_AREA_TYPE={})).Circle="Circle",c.Ellipse="Ellipse",c.Polygon="Polygon",c.Rect="Rect",c.RoundedRect="RoundedRect";var s=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.hitArea=void 0,e}return i(e,t),e.prototype.init=function(t){t&&_extends(this,t)},e.prototype.emit=function(e){for(var n=[],o=1;o<arguments.length;o++)n[o-1]=arguments[o];return t.prototype.emit.apply(this,p([e],n))},e.prototype.once=function(e,n,o){return t.prototype.once.call(this,e,n,o)},e.prototype.on=function(e,n,o){return t.prototype.on.call(this,e,n,o)},e.componentName="Event",e}(n.Component);return t.Event=s,t.EventSystem=u,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA.plugin.renderer,EVA,PIXI);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-event",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-alpha.1",
4
4
  "description": "@eva/plugin-renderer-event",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-event.esm.js",
@@ -18,8 +18,8 @@
18
18
  "license": "MIT",
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
- "@eva/plugin-renderer": "1.2.0",
22
- "@eva/eva.js": "1.2.0",
21
+ "@eva/plugin-renderer": "1.3.0-alpha.1",
22
+ "@eva/eva.js": "1.3.0-alpha.1",
23
23
  "pixi.js": "^4.8.7"
24
24
  }
25
25
  }