phaser3-rex-plugins
Version:
2 lines (1 loc) • 8.77 kB
JavaScript
!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).rexlineplugin=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 i(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=n.key,o=void 0,"symbol"==typeof(o=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.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)}(r,"string"))?o:String(o)),n);}var r,o;}function n(t,e,n){return e&&i(t.prototype,e),n&&i(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function r(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&&s(t,e);}function o(t){return o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},o(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(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 i,n=o(t);if(e){var r=o(this).constructor;i=Reflect.construct(n,arguments,r);}else i=n.apply(this,arguments);return u(this,i)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=o(t)););return t}(t,e);if(n){var r=Object.getOwnPropertyDescriptor(n,e);return r.get?r.get.call(arguments.length<3?t:i):r.value}},h.apply(this,arguments)}var c=Phaser.Game,d=function(t){return t instanceof c},f=Phaser.Scene,l=function(t){return t instanceof f},y=function(e){return null==e||"object"!==t(e)?null:d(e)?e:d(e.game)?e.game:l(e)?e.sys.game:l(e.scene)?e.scene.sys.game:void 0},v=Phaser.GameObjects,p=void 0,g=function(t,e){if(p||(p={},y(t).events.once("destroy",(function(){for(var t in p)p[t].destroy();p=void 0;}))),!p.hasOwnProperty(e)){var i=y(t).scene.systemScene;(t=new v[e](i)).setOrigin(0),p[e]=t;}return p[e]},m=function(t,e,i,n,r,o){var s=g(this,"Image").setTexture(t,e).setDisplaySize(r,o);this.draw(s,i,n);},x=function(t,e,i,n,r,o){var s=g(this,"TileSprite").setTexture(t,e).setSize(r,o);this.draw(s,i,n);},b=Phaser.Math.Distance.Between,w=Phaser.Math.Angle.Between,O=Phaser.GameObjects.RenderTexture,S=Phaser.Utils.Objects.GetValue,P=function(t){r(s,t);var i=a(s);function s(t,n){var r;e(this,s),(r=i.call(this,t)).redraw=!1,r._tileSprite=void 0,r._image=void 0;var o=S(n,"start",void 0);"string"==typeof o?(r.setLineStartPosition(0,0),r.setLineStartTexture(o,void 0),r.setLineStartOrigin(void 0)):(r.setLineStartPosition(S(o,"x",0),S(o,"y",0)),r.setLineStartTexture(S(o,"key",void 0),S(o,"frame",void 0)),r.setLineStartOrigin(S(o,"origin",void 0)));var u=S(n,"end",void 0);"string"==typeof u?(r.setLineEndPosition(0,0),r.setLineEndTexture(u,void 0),r.setLineEndOrigin(void 0)):(r.setLineEndPosition(S(u,"x",0),S(u,"y",0)),r.setLineEndTexture(S(u,"key",void 0),S(u,"frame",void 0)),r.setLineEndOrigin(S(u,"origin",void 0)));var a=S(n,"body",void 0);return "string"==typeof a?(r.setLineBodyTexture(a,void 0),r.setLineBodyExtendMode(0),r.setLineBodyWidth(void 0)):(r.setLineBodyTexture(S(a,"key",void 0),S(a,"frame",void 0)),r.setLineBodyExtendMode(S(a,"extendMode",1)),r.setLineBodyWidth(S(a,"width",void 0))),r}return n(s,[{key:"x0",get:function(){return this._x0},set:function(t){this.redraw|=this._x0!==t,this._x0=t;}},{key:"y0",get:function(){return this._y0},set:function(t){this.redraw|=this._y0!==t,this._y0=t;}},{key:"x1",get:function(){return this._x1},set:function(t){this.redraw|=this._x1!==t,this._x1=t;}},{key:"y1",get:function(){return this._y1},set:function(t){this.redraw|=this._y1!==t,this._y1=t;}},{key:"setLineStartPosition",value:function(t,e){return this.x0=t,this.y0=e,this}},{key:"setLineEndPosition",value:function(t,e){return this.x1=t,this.y1=e,this}},{key:"setLineStartTexture",value:function(t,e){return this.lineStartTexture=t,this.lineStartFrameName=e,this.redraw=!0,this}},{key:"setLineStartOrigin",value:function(t){return void 0===t&&(t=0),this.lineStartOrigin=t,this.redraw=!0,this}},{key:"lineStartFrame",get:function(){return this.scene.sys.textures.getFrame(this.lineStartTexture,this.lineStartFrameName)}},{key:"setLineEndTexture",value:function(t,e){return this.lineEndTexture=t,this.lineEndFrameName=e,this.redraw=!0,this}},{key:"setLineEndOrigin",value:function(t){return void 0===t&&(t=1),this.lineEndOrigin=t,this.redraw=!0,this}},{key:"lineEndFrame",get:function(){return this.scene.sys.textures.getFrame(this.lineEndTexture,this.lineEndFrameName)}},{key:"setLineBodyTexture",value:function(t,e){return this.lineBodyTexture=t,this.lineBodyFrameName=e,this.redraw=!0,this}},{key:"setLineBodyWidth",value:function(t){return this.lineBodyWidth=t,this.redraw=!0,this}},{key:"setLineBodyExtendMode",value:function(t){return "string"==typeof t&&(t=T[t]),this.lineBodyExtendMode=t,this}},{key:"lineBodyFrame",get:function(){return this.scene.sys.textures.getFrame(this.lineBodyTexture,this.lineBodyFrameName)}},{key:"renderWebGL",value:function(t,e,i,n){this.updateTexture(),h(o(s.prototype),"renderWebGL",this).call(this,t,e,i,n);}},{key:"renderCanvas",value:function(t,e,i,n){this.updateTexture(),h(o(s.prototype),"renderCanvas",this).call(this,t,e,i,n);}}]),s}(O),T={scale:0,repeat:1},L={updateTexture:function(){if(!this.redraw)return this;this.redraw=!1;var t,e,i=this.lineStartFrame,n=this.lineEndFrame,r=this.lineBodyFrame,o=0,s=b(this.x0,this.y0,this.x1,this.y1),u=0,a=w(this.x0,this.y0,this.x1,this.y1);if(i&&(s+=o=this.lineStartOrigin*i.cutWidth,u=i.cutHeight),n&&(s+=(1-this.lineEndOrigin)*n.cutWidth,u=Math.max(u,n.cutHeight)),r){var h=void 0!==this.lineBodyWidth?this.lineBodyWidth:r.cutHeight;u=Math.max(u,h);}if(s=Math.floor(s),u=Math.floor(u),s<=0||u<=0)return this.setPosition(this.x0,this.y0).setSize(1,1).setRotation(a),this;this.width===s&&this.height===u&&this.setSize(s+1,u+1),this.setSize(s,u).setPosition(this.x0,this.y0).setRotation(a).setOrigin(0,0);var c=this.width;i&&(t=0,e=(this.height-i.cutHeight)/2,this.drawFrame(this.lineStartTexture,this.lineStartFrameName,t,e),c-=i.cutWidth),n&&(t=this.width-n.cutWidth,e=(this.height-n.cutHeight)/2,this.drawFrame(this.lineEndTexture,this.lineEndFrameName,t,e),c-=n.cutWidth),r&&c>0&&h>0&&(t=i?i.cutWidth:0,e=(this.height-h)/2,0===this.lineBodyExtendMode?m.call(this,this.lineBodyTexture,this.lineBodyFrameName,t,e,c,h):x.call(this,this.lineBodyTexture,this.lineBodyFrameName,t,e,c,h));var d=1-(s-o)/s;this.setOrigin(d,.5);}};function B(t){var e=new P(this.scene,t);return this.scene.add.existing(e),e}Object.assign(P.prototype,L);var E=Phaser.GameObjects.BuildGameObject;function j(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=new P(this.scene,t);return E(this.scene,i,t),i}var k=function(t){return null==t||""===t||0===t.length},_=function(t){r(o,Phaser.Plugins.BasePlugin);var i=a(o);function o(t){var n;return e(this,o),n=i.call(this,t),t.registerGameObject("rexLine",B,j),n}return n(o,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}}]),o}();return function(e,i,n,r){if(void 0===r&&(r="."),"object"===t(e)){if(k(i)){if(null==n)return;"object"===t(n)&&(e=n);}else {"string"==typeof i&&(i=i.split(r));var o=i.pop(),s=function(e,i,n){var r=e;if(k(i));else {var o;"string"==typeof i&&(i=i.split("."));for(var s=0,u=i.length;s<u;s++){var a;null!=r[o=i[s]]&&"object"===t(r[o])||(a=s===u-1?void 0===n?{}:n:{},r[o]=a),r=r[o];}}return r}(e,i);s[o]=n;}}}(window,"RexPlugins.GameObjects.Line",P),_}));