UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 7.48 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rextouchhelperplugin=e();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(o=n.key,i=void 0,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(o,"string"))?i:String(i)),n);}var o,i;}function n(t,e,n){return e&&r(t.prototype,e),n&&r(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function i(t,e){return i=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},i(t,e)}function u(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function a(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var r,n=o(t);if(e){var i=o(this).constructor;r=Reflect.construct(n,arguments,i);}else r=n.apply(this,arguments);return u(this,r)}}function f(){return f="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(n){var i=Object.getOwnPropertyDescriptor(n,e);return i.get?i.get.call(arguments.length<3?t:r):i.value}},f.apply(this,arguments)}function c(t){return function(t){if(Array.isArray(t))return s(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return s(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}var l=[],y=function(t,e){for(var r=t.scene,n=r.input.cameras.getCamerasBelowPointer(e),o=r.input.manager,i=[t],u=0,a=n.length;u<a;u++)if(o.hitTest(e,i,n[u],p),p.length>0)return p.length=0,!0;return p.length=0,!1},p=[],h=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width},d=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height},g=Phaser.Geom.Rectangle,v=Phaser.Math.Vector2,m=Phaser.Math.RotateAround,b=void 0,w=function(t,e,r){return void 0===e?e=new v:!0===e&&(void 0===j&&(j=new v),e=j),t.getTopLeft?t.getTopLeft(e):(e.x=t.x-h(t)*t.originX,e.y=t.y-d(t)*t.originY,T(t,e,r))},x=function(t,e,r){return void 0===e?e=new v:!0===e&&(void 0===j&&(j=new v),e=j),t.getTopRight?t.getTopRight(e):(e.x=t.x-h(t)*t.originX+h(t),e.y=t.y-d(t)*t.originY,T(t,e,r))},O=function(t,e,r){return void 0===e?e=new v:!0===e&&(void 0===j&&(j=new v),e=j),t.getBottomLeft?t.getBottomLeft(e):(e.x=t.x-h(t)*t.originX,e.y=t.y-d(t)*t.originY+d(t),T(t,e,r))},P=function(t,e,r){return void 0===e?e=new v:!0===e&&(void 0===j&&(j=new v),e=j),t.getBottomRight?t.getBottomRight(e):(e.x=t.x-h(t)*t.originX+h(t),e.y=t.y-d(t)*t.originY+d(t),T(t,e,r))},j=void 0,T=function(t,e,r){(void 0===r&&(r=!1),0!==t.rotation&&m(e,t.x,t.y,t.rotation),r&&t.parentContainer)&&t.parentContainer.getBoundsTransformMatrix().transformPoint(e.x,e.y,e);return e},k=function(t,e,r,n,o){if(!t)return !1;if(n&&!n(t,e,r))return !1;var i=function(t,e){if(void 0===e?e=new g:!0===e&&(void 0===b&&(b=new g),e=b),t.getBounds)return t.getBounds(e);var r,n,o,i,u,a,f,c;if(t.parentContainer){var s=t.parentContainer.getBoundsTransformMatrix();w(t,e),s.transformPoint(e.x,e.y,e),r=e.x,n=e.y,x(t,e),s.transformPoint(e.x,e.y,e),o=e.x,i=e.y,O(t,e),s.transformPoint(e.x,e.y,e),u=e.x,a=e.y,P(t,e),s.transformPoint(e.x,e.y,e),f=e.x,c=e.y;}else w(t,e),r=e.x,n=e.y,x(t,e),o=e.x,i=e.y,O(t,e),u=e.x,a=e.y,P(t,e),f=e.x,c=e.y;return e.x=Math.min(r,o,u,f),e.y=Math.min(n,i,a,c),e.width=Math.max(r,o,u,f)-e.x,e.height=Math.max(n,i,a,c)-e.y,e}(t,!0);return !!i.contains(e,r)&&!(o&&!o(t,e,r))},R=Phaser.Scene,S=function(){function r(t){e(this,r),t instanceof R&&(t=t.game),this.ticker=t.loop,this.topObjects={};}return n(r,[{key:"destroy",value:function(){this.ticker=void 0,this.topObjects=void 0;}},{key:"isAtTop",value:function(t,e){var r,n=this.ticker.frame,o=this.topObjects[t];return o?(r=o.tick<n||o.tick===n&&(void 0!==e&&o.key===e))&&(o.tick=n,o.key=e):(this.topObjects[t]={tick:n,key:e},r=!0),r}},{key:"clear",value:function(){return function(e){if("object"!==t(e)||null===e)return e;if(Array.isArray(e))e.length=0;else for(var r in e)delete e[r];}(this.topObjects),this}}]),r}(),A=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&i(t,e);}(u,Phaser.Plugins.BasePlugin);var r=a(u);function u(t){return e(this,u),r.call(this,t)}return n(u,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this),this.touchGroup=new S(this.game);}},{key:"destroy",value:function(){this.touchGroup.destroy(),f(o(u.prototype),"destroy",this).call(this);}},{key:"isAtTop",value:function(t,e){return this.touchGroup.isAtTop(t,e)}}]),u}(),B={hitTest:function(t,e,r,n,o){var i,u,a,f=t.input,s=f.manager;void 0===e&&(e=f.topOnly),void 0===o&&(o=[]),void 0===r&&(r=f._list),void 0===n&&(n=s.pointers,i=s.pointersTotal),void 0===i&&(i=n.length);for(var y=0;y<i;y++){u=n[y];for(var p=0,h=(a=f.cameras.getCamerasBelowPointer(u)).length;p<h;p++){var d;(d=o).push.apply(d,c(s.hitTest(u,r,a[p],l)));}}return f.sortGameObjects(o),e&&o.length&&o.splice(1),l.length=0,o},isPointerInHitArea:function(t,e,r,n){if(e)return !(r&&!r(t,e))&&(!!y(t,e)&&!(n&&!n(t,e)));for(var o=t.scene.input.manager,i=o.pointersTotal,u=o.pointers,a=0;a<i;a++)if(e=u[a],(!r||r(t,e))&&y(t,e)&&(!n||n(t,e)))return !0;return !1},isPointerInBounds:function(t,e,r,n){if(e)return k(t,e.worldX,e.worldY,r,n);for(var o=t.scene.input.manager,i=o.pointersTotal,u=o.pointers,a=0;a<i;a++)if(e=u[a],k(t,e.worldX,e.worldY,r,n))return !0;return !1}};return Object.assign(A.prototype,B),A}));