@eva/plugin-renderer-event 1.2.7-editor.9 → 1.2.8-alpha.0
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,4 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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
3
|
window.EVA = window.EVA || {};
|
|
4
4
|
window.EVA.plugin = window.EVA.plugin || {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return _extends=Object.assign
|
|
1
|
+
function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n])}return t},_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_event=function(t,e,o,n){"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 o in e)e.hasOwnProperty(o)&&(t[o]=e[o])},r(t,e)};function a(t,e){function o(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function i(t,e){var o="function"==typeof Symbol&&t[Symbol.iterator];if(!o)return t;var n,r,a=o.call(t),i=[];try{for(;(void 0===e||e-- >0)&&!(n=a.next()).done;)i.push(n.value)}catch(t){r={error:t}}finally{try{n&&!n.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}return i}function p(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(i(arguments[e]));return t}var l,c={Circle:n.Circle,Ellipse:n.Ellipse,Polygon:n.Polygon,Rect:n.Rectangle,RoundedRect:n.RoundedRectangle},d={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},s=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Event",e}return a(n,t),n.prototype.init=function(t){var o=(void 0===t?{}:t).moveWhenInside,n=void 0!==o&&o;this.renderSystem=this.game.getSystem(e.RendererSystem),this.renderSystem.rendererManager.register(this);try{this.renderSystem.application.renderer.plugins.interaction.moveWhenInside=n}catch(t){console.error("Setting moveWhenInside error.",t)}},n.prototype.componentChanged=function(t){switch(t.type){case o.OBSERVER_TYPE.ADD:this.add(t);break;case o.OBSERVER_TYPE.REMOVE:this.remove(t);break;case o.OBSERVER_TYPE.CHANGE:this.change(t)}},n.prototype.add=function(t){var e=this.containerManager.getContainer(t.gameObject.id);e.interactive=!0,e.interactiveChildren=!0;var o=t.component;o.hitArea&&this.addHitArea(t,e,o.hitArea),e.on("pointertap",(function(t){o.emit("tap",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})})),e.on("pointerdown",(function(t){o.emit("touchstart",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})})),e.on("pointermove",(function(t){o.emit("touchmove",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})})),e.on("pointerup",(function(t){o.emit("touchend",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})})),e.on("pointerupoutside",(function(t){o.emit("touchendoutside",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})})),e.on("pointercancel",(function(t){o.emit("touchcancel",{stopPropagation:function(){return t.stopPropagation()},data:{pointerId:t.data.pointerId,position:{x:t.data.global.x,y:t.data.global.y},localPosition:e.worldTransform.applyInverse(t.data.global)},gameObject:o.gameObject})}))},n.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()},n.prototype.change=function(t){var e=this.containerManager.getContainer(t.gameObject.id);e.interactive=!0;var o=t.component;o.hitArea?this.addHitArea(t,e,o.hitArea):o.hitArea=null},n.prototype.addHitArea=function(t,e,o){var n,r,a,i=o.type,l=o.style;if(c[i]){var s=[];try{for(var u=function(t){var e="function"==typeof Symbol&&Symbol.iterator,o=e&&t[e],n=0;if(o)return o.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}(d[i]),f=u.next();!f.done;f=u.next()){var g=f.value;s.push(l[g])}}catch(t){n={error:t}}finally{try{f&&!f.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}var y=new((a=c[i]).bind.apply(a,p([void 0],s)));e.hitArea=y}else console.error(t.gameObject.name+"'s hitArea type is not defined")},n.systemName="Event",n=function(t,e,o,n){var r,a=arguments.length,i=a<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,o,n);else for(var p=t.length-1;p>=0;p--)(r=t[p])&&(i=(a<3?r(i):a>3?r(e,o,i):r(e,o))||i);return a>3&&i&&Object.defineProperty(e,o,i),i}([o.decorators.componentObserver({Event:[{prop:["hitArea"],deep:!0}]})],n),n}(e.Renderer),u=s;t.HIT_AREA_TYPE=void 0,(l=t.HIT_AREA_TYPE||(t.HIT_AREA_TYPE={})).Circle="Circle",l.Ellipse="Ellipse",l.Polygon="Polygon",l.Rect="Rect",l.RoundedRect="RoundedRect";var f=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.hitArea=void 0,e}return a(e,t),e.prototype.init=function(t){t&&_extends(this,t)},e.prototype.emit=function(e){for(var o=[],n=1;n<arguments.length;n++)o[n-1]=arguments[n];return t.prototype.emit.apply(this,p([e],o))},e.prototype.once=function(e,o,n){return t.prototype.once.call(this,e,o,n)},e.prototype.on=function(e,o,n){return t.prototype.on.call(this,e,o,n)},e.componentName="Event",e}(o.Component),g=f;return t.Event=g,t.EventSystem=u,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA.plugin.renderer,EVA,PIXI);window.EVA.plugin.renderer.event=window.EVA.plugin.renderer.event||_EVA_IIFE_event;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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, __values, __spread, __decorate } from 'tslib';
|
|
4
|
+
import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
|
|
5
|
+
import { OBSERVER_TYPE, decorators, Component } from '@eva/eva.js/dist/miniprogram';
|
|
6
|
+
import { Circle, Ellipse, Polygon, Rectangle, RoundedRectangle } from '@eva/miniprogram-pixi';
|
|
7
|
+
var hitAreaFunc = {
|
|
8
|
+
Circle: Circle,
|
|
9
|
+
Ellipse: Ellipse,
|
|
10
|
+
Polygon: Polygon,
|
|
11
|
+
Rect: Rectangle,
|
|
12
|
+
RoundedRect: RoundedRectangle
|
|
13
|
+
};
|
|
14
|
+
var propertyForHitArea = {
|
|
15
|
+
Circle: ['x', 'y', 'radius'],
|
|
16
|
+
Ellipse: ['x', 'y', 'width', 'height'],
|
|
17
|
+
Rect: ['x', 'y', 'width', 'height'],
|
|
18
|
+
RoundedRect: ['x', 'y', 'width', 'height', 'radius'],
|
|
19
|
+
Polygon: ['paths']
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var Event$2 = function (_super) {
|
|
23
|
+
__extends(Event, _super);
|
|
24
|
+
|
|
25
|
+
function Event() {
|
|
26
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
27
|
+
|
|
28
|
+
_this.name = 'Event';
|
|
29
|
+
return _this;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Event.prototype.init = function (_a) {
|
|
33
|
+
var _b = (_a === void 0 ? {} : _a).moveWhenInside,
|
|
34
|
+
moveWhenInside = _b === void 0 ? false : _b;
|
|
35
|
+
this.renderSystem = this.game.getSystem(RendererSystem);
|
|
36
|
+
this.renderSystem.rendererManager.register(this);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
this.renderSystem.application.renderer.plugins.interaction.moveWhenInside = moveWhenInside;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
console.error('Setting moveWhenInside error.', e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
Event.prototype.componentChanged = function (changed) {
|
|
46
|
+
switch (changed.type) {
|
|
47
|
+
case OBSERVER_TYPE.ADD:
|
|
48
|
+
this.add(changed);
|
|
49
|
+
break;
|
|
50
|
+
|
|
51
|
+
case OBSERVER_TYPE.REMOVE:
|
|
52
|
+
this.remove(changed);
|
|
53
|
+
break;
|
|
54
|
+
|
|
55
|
+
case OBSERVER_TYPE.CHANGE:
|
|
56
|
+
this.change(changed);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
Event.prototype.add = function (changed) {
|
|
62
|
+
var container = this.containerManager.getContainer(changed.gameObject.id);
|
|
63
|
+
container.interactive = true;
|
|
64
|
+
container.interactiveChildren = true;
|
|
65
|
+
var component = changed.component;
|
|
66
|
+
|
|
67
|
+
if (component.hitArea) {
|
|
68
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
container.on('pointertap', function (e) {
|
|
72
|
+
component.emit('tap', {
|
|
73
|
+
stopPropagation: function stopPropagation() {
|
|
74
|
+
return e.stopPropagation();
|
|
75
|
+
},
|
|
76
|
+
data: {
|
|
77
|
+
pointerId: e.data.pointerId,
|
|
78
|
+
position: {
|
|
79
|
+
x: e.data.global.x,
|
|
80
|
+
y: e.data.global.y
|
|
81
|
+
},
|
|
82
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
83
|
+
},
|
|
84
|
+
gameObject: component.gameObject
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
container.on('pointerdown', function (e) {
|
|
88
|
+
component.emit('touchstart', {
|
|
89
|
+
stopPropagation: function stopPropagation() {
|
|
90
|
+
return e.stopPropagation();
|
|
91
|
+
},
|
|
92
|
+
data: {
|
|
93
|
+
pointerId: e.data.pointerId,
|
|
94
|
+
position: {
|
|
95
|
+
x: e.data.global.x,
|
|
96
|
+
y: e.data.global.y
|
|
97
|
+
},
|
|
98
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
99
|
+
},
|
|
100
|
+
gameObject: component.gameObject
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
container.on('pointermove', function (e) {
|
|
104
|
+
component.emit('touchmove', {
|
|
105
|
+
stopPropagation: function stopPropagation() {
|
|
106
|
+
return e.stopPropagation();
|
|
107
|
+
},
|
|
108
|
+
data: {
|
|
109
|
+
pointerId: e.data.pointerId,
|
|
110
|
+
position: {
|
|
111
|
+
x: e.data.global.x,
|
|
112
|
+
y: e.data.global.y
|
|
113
|
+
},
|
|
114
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
115
|
+
},
|
|
116
|
+
gameObject: component.gameObject
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
container.on('pointerup', function (e) {
|
|
120
|
+
component.emit('touchend', {
|
|
121
|
+
stopPropagation: function stopPropagation() {
|
|
122
|
+
return e.stopPropagation();
|
|
123
|
+
},
|
|
124
|
+
data: {
|
|
125
|
+
pointerId: e.data.pointerId,
|
|
126
|
+
position: {
|
|
127
|
+
x: e.data.global.x,
|
|
128
|
+
y: e.data.global.y
|
|
129
|
+
},
|
|
130
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
131
|
+
},
|
|
132
|
+
gameObject: component.gameObject
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
container.on('pointerupoutside', function (e) {
|
|
136
|
+
component.emit('touchendoutside', {
|
|
137
|
+
stopPropagation: function stopPropagation() {
|
|
138
|
+
return e.stopPropagation();
|
|
139
|
+
},
|
|
140
|
+
data: {
|
|
141
|
+
pointerId: e.data.pointerId,
|
|
142
|
+
position: {
|
|
143
|
+
x: e.data.global.x,
|
|
144
|
+
y: e.data.global.y
|
|
145
|
+
},
|
|
146
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
147
|
+
},
|
|
148
|
+
gameObject: component.gameObject
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
container.on('pointercancel', function (e) {
|
|
152
|
+
component.emit('touchcancel', {
|
|
153
|
+
stopPropagation: function stopPropagation() {
|
|
154
|
+
return e.stopPropagation();
|
|
155
|
+
},
|
|
156
|
+
data: {
|
|
157
|
+
pointerId: e.data.pointerId,
|
|
158
|
+
position: {
|
|
159
|
+
x: e.data.global.x,
|
|
160
|
+
y: e.data.global.y
|
|
161
|
+
},
|
|
162
|
+
localPosition: container.worldTransform.applyInverse(e.data.global)
|
|
163
|
+
},
|
|
164
|
+
gameObject: component.gameObject
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
Event.prototype.remove = function (changed) {
|
|
170
|
+
var container = this.containerManager.getContainer(changed.gameObject.id);
|
|
171
|
+
container.interactive = false;
|
|
172
|
+
container.off('tap');
|
|
173
|
+
container.off('pointerdown');
|
|
174
|
+
container.off('pointermove');
|
|
175
|
+
container.off('pointerup');
|
|
176
|
+
container.off('pointerupoutside');
|
|
177
|
+
container.off('pointercancel');
|
|
178
|
+
changed.component.removeAllListeners();
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
Event.prototype.change = function (changed) {
|
|
182
|
+
var container = this.containerManager.getContainer(changed.gameObject.id);
|
|
183
|
+
container.interactive = true;
|
|
184
|
+
var component = changed.component;
|
|
185
|
+
|
|
186
|
+
if (component.hitArea) {
|
|
187
|
+
this.addHitArea(changed, container, component.hitArea);
|
|
188
|
+
} else {
|
|
189
|
+
component.hitArea = null;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
Event.prototype.addHitArea = function (changed, container, hitArea) {
|
|
194
|
+
var e_1, _a, _b;
|
|
195
|
+
|
|
196
|
+
var type = hitArea.type,
|
|
197
|
+
style = hitArea.style;
|
|
198
|
+
|
|
199
|
+
if (!hitAreaFunc[type]) {
|
|
200
|
+
console.error(changed.gameObject.name + "'s hitArea type is not defined");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var params = [];
|
|
205
|
+
|
|
206
|
+
try {
|
|
207
|
+
for (var _c = __values(propertyForHitArea[type]), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
208
|
+
var key = _d.value;
|
|
209
|
+
params.push(style[key]);
|
|
210
|
+
}
|
|
211
|
+
} catch (e_1_1) {
|
|
212
|
+
e_1 = {
|
|
213
|
+
error: e_1_1
|
|
214
|
+
};
|
|
215
|
+
} finally {
|
|
216
|
+
try {
|
|
217
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
218
|
+
} finally {
|
|
219
|
+
if (e_1) throw e_1.error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
var hitAreaShape = new ((_b = hitAreaFunc[type]).bind.apply(_b, __spread([void 0], params)))();
|
|
224
|
+
container.hitArea = hitAreaShape;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
Event.systemName = 'Event';
|
|
228
|
+
Event = __decorate([decorators.componentObserver({
|
|
229
|
+
Event: [{
|
|
230
|
+
prop: ['hitArea'],
|
|
231
|
+
deep: true
|
|
232
|
+
}]
|
|
233
|
+
})], Event);
|
|
234
|
+
return Event;
|
|
235
|
+
}(Renderer);
|
|
236
|
+
|
|
237
|
+
var Event$3 = Event$2;
|
|
238
|
+
var HIT_AREA_TYPE;
|
|
239
|
+
|
|
240
|
+
(function (HIT_AREA_TYPE) {
|
|
241
|
+
HIT_AREA_TYPE["Circle"] = "Circle";
|
|
242
|
+
HIT_AREA_TYPE["Ellipse"] = "Ellipse";
|
|
243
|
+
HIT_AREA_TYPE["Polygon"] = "Polygon";
|
|
244
|
+
HIT_AREA_TYPE["Rect"] = "Rect";
|
|
245
|
+
HIT_AREA_TYPE["RoundedRect"] = "RoundedRect";
|
|
246
|
+
})(HIT_AREA_TYPE || (HIT_AREA_TYPE = {}));
|
|
247
|
+
|
|
248
|
+
var Event = function (_super) {
|
|
249
|
+
__extends(Event, _super);
|
|
250
|
+
|
|
251
|
+
function Event() {
|
|
252
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
253
|
+
|
|
254
|
+
_this.hitArea = undefined;
|
|
255
|
+
return _this;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
Event.prototype.init = function (params) {
|
|
259
|
+
params && _extends(this, params);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
Event.prototype.emit = function (en) {
|
|
263
|
+
var args = [];
|
|
264
|
+
|
|
265
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
266
|
+
args[_i - 1] = arguments[_i];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return _super.prototype.emit.apply(this, __spread([en], args));
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
Event.prototype.once = function (en, fn, context) {
|
|
273
|
+
return _super.prototype.once.call(this, en, fn, context);
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
Event.prototype.on = function (en, fn, context) {
|
|
277
|
+
return _super.prototype.on.call(this, en, fn, context);
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
Event.componentName = 'Event';
|
|
281
|
+
return Event;
|
|
282
|
+
}(Component);
|
|
283
|
+
|
|
284
|
+
var Event$1 = Event;
|
|
285
|
+
export { Event$1 as Event, Event$3 as EventSystem, HIT_AREA_TYPE };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-renderer-event",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.8-alpha.0",
|
|
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.
|
|
22
|
-
"@eva/eva.js": "1.2.
|
|
21
|
+
"@eva/plugin-renderer": "1.2.8-alpha.0",
|
|
22
|
+
"@eva/eva.js": "1.2.8-alpha.0",
|
|
23
23
|
"pixi.js": "^4.8.7"
|
|
24
24
|
}
|
|
25
25
|
}
|