UNPKG

phaser4-rex-plugins

Version:
2 lines (1 loc) 5.76 kB
var t,e;t=void 0,e=function(){const t=Phaser.Game;var e=function(e){return e instanceof t};const i=Phaser.Scene;var s=function(t){return t instanceof i},r=function(t){return null==t||"object"!=typeof t?null:e(t)?t:e(t.game)?t.game:s(t)?t.sys.game:s(t.scene)?t.scene.sys.game:void 0};const n=Phaser.GameObjects;var h=void 0,o=function(t,e){if(h||(h={},r(t).events.once("destroy",(function(){for(var t in h)h[t].destroy();h=void 0}))),!h.hasOwnProperty(e)){var i=r(t).scene.systemScene;(t=new n[e](i)).setOrigin(0),h[e]=t}return h[e]},a=function(t,e,i,s,r,n){var h=o(this,"Image").setTexture(t,e).setDisplaySize(r,n);this.draw(h,i,s).render()},d=function(t,e,i,s,r,n){var h=o(this,"TileSprite").setTexture(t,e).setSize(r,n);this.draw(h,i,s).render()};const u=Phaser.Math.Distance.Between,l=Phaser.Math.Angle.Between,y=Phaser.GameObjects.RenderTexture,c=Phaser.Utils.Objects.GetValue;class x extends y{constructor(t,e){super(t),this.redraw=!1,this._tileSprite=void 0,this._image=void 0;var i=c(e,"start",void 0);"string"==typeof i?(this.setLineStartPosition(0,0),this.setLineStartTexture(i,void 0),this.setLineStartOrigin(void 0)):(this.setLineStartPosition(c(i,"x",0),c(i,"y",0)),this.setLineStartTexture(c(i,"key",void 0),c(i,"frame",void 0)),this.setLineStartOrigin(c(i,"origin",void 0)));var s=c(e,"end",void 0);"string"==typeof s?(this.setLineEndPosition(0,0),this.setLineEndTexture(s,void 0),this.setLineEndOrigin(void 0)):(this.setLineEndPosition(c(s,"x",0),c(s,"y",0)),this.setLineEndTexture(c(s,"key",void 0),c(s,"frame",void 0)),this.setLineEndOrigin(c(s,"origin",void 0)));var r=c(e,"body",void 0);"string"==typeof r?(this.setLineBodyTexture(r,void 0),this.setLineBodyExtendMode(0),this.setLineBodyWidth(void 0)):(this.setLineBodyTexture(c(r,"key",void 0),c(r,"frame",void 0)),this.setLineBodyExtendMode(c(r,"extendMode",1)),this.setLineBodyWidth(c(r,"width",void 0)))}get x0(){return this._x0}set x0(t){this.redraw|=this._x0!==t,this._x0=t}get y0(){return this._y0}set y0(t){this.redraw|=this._y0!==t,this._y0=t}get x1(){return this._x1}set x1(t){this.redraw|=this._x1!==t,this._x1=t}get y1(){return this._y1}set y1(t){this.redraw|=this._y1!==t,this._y1=t}setLineStartPosition(t,e){return this.x0=t,this.y0=e,this}setLineEndPosition(t,e){return this.x1=t,this.y1=e,this}setLineStartTexture(t,e){return this.lineStartTexture=t,this.lineStartFrameName=e,this.redraw=!0,this}setLineStartOrigin(t){return void 0===t&&(t=0),this.lineStartOrigin=t,this.redraw=!0,this}get lineStartFrame(){return this.scene.sys.textures.getFrame(this.lineStartTexture,this.lineStartFrameName)}setLineEndTexture(t,e){return this.lineEndTexture=t,this.lineEndFrameName=e,this.redraw=!0,this}setLineEndOrigin(t){return void 0===t&&(t=1),this.lineEndOrigin=t,this.redraw=!0,this}get lineEndFrame(){return this.scene.sys.textures.getFrame(this.lineEndTexture,this.lineEndFrameName)}setLineBodyTexture(t,e){return this.lineBodyTexture=t,this.lineBodyFrameName=e,this.redraw=!0,this}setLineBodyWidth(t){return this.lineBodyWidth=t,this.redraw=!0,this}setLineBodyExtendMode(t){return"string"==typeof t&&(t=g[t]),this.lineBodyExtendMode=t,this}get lineBodyFrame(){return this.scene.sys.textures.getFrame(this.lineBodyTexture,this.lineBodyFrameName)}renderWebGL(t,e,i,s){this.updateTexture(),super.renderWebGL(t,e,i,s)}renderCanvas(t,e,i,s){this.updateTexture(),super.renderCanvas(t,e,i,s)}}const g={scale:0,repeat:1};var v={updateTexture:function(){if(!this.redraw)return this;this.redraw=!1;var t,e,i=this.lineStartFrame,s=this.lineEndFrame,r=this.lineBodyFrame,n=0,h=u(this.x0,this.y0,this.x1,this.y1),o=0,y=l(this.x0,this.y0,this.x1,this.y1);if(i&&(h+=n=this.lineStartOrigin*i.cutWidth,o=i.cutHeight),s&&(h+=(1-this.lineEndOrigin)*s.cutWidth,o=Math.max(o,s.cutHeight)),r){var c=void 0!==this.lineBodyWidth?this.lineBodyWidth:r.cutHeight;o=Math.max(o,c)}if(h=Math.floor(h),o=Math.floor(o),h<=0||o<=0)return this.setPosition(this.x0,this.y0).setSize(1,1).setRotation(y),this;this.width===h&&this.height===o&&this.setSize(h+1,o+1),this.setSize(h,o).setPosition(this.x0,this.y0).setRotation(y).setOrigin(0,0);var x=this.width;i&&(t=0,e=(this.height-i.cutHeight)/2,this.stamp(this.lineStartTexture,this.lineStartFrameName,t,e,{originX:0,originY:0}),x-=i.cutWidth),s&&(t=this.width-s.cutWidth,e=(this.height-s.cutHeight)/2,this.stamp(this.lineEndTexture,this.lineEndFrameName,t,e,{originX:0,originY:0}),x-=s.cutWidth),r&&x>0&&c>0&&(t=i?i.cutWidth:0,e=(this.height-c)/2,0===this.lineBodyExtendMode?a.call(this,this.lineBodyTexture,this.lineBodyFrameName,t,e,x,c):d.call(this,this.lineBodyTexture,this.lineBodyFrameName,t,e,x,c));var g=1-(h-n)/h;this.setOrigin(g,.5)}};function m(t){var e=new x(this.scene,t);return this.scene.add.existing(e),e}Object.assign(x.prototype,v);const f=Phaser.GameObjects.BuildGameObject;function p(t,e){void 0===t&&(t={}),void 0!==e&&(t.add=e);var i=new x(this.scene,t);return f(this.scene,i,t),i}var L=function(t){return null==t||""===t||0===t.length};class B extends Phaser.Plugins.BasePlugin{constructor(t){super(t),t.registerGameObject("rexLine",m,p)}start(){this.game.events.on("destroy",this.destroy,this)}}return function(t,e,i,s){if(void 0===s&&(s="."),"object"==typeof t)if(L(e)){if(null==i)return;"object"==typeof i&&(t=i)}else{"string"==typeof e&&(e=e.split(s));var r=e.pop(),n=function(t,e,i){var s=t;if(L(e));else{var r;"string"==typeof e&&(e=e.split("."));for(var n=0,h=e.length;n<h;n++){var o;null!=s[r=e[n]]&&"object"==typeof s[r]||(o=n===h-1?void 0===i?{}:i:{},s[r]=o),s=s[r]}}return s}(t,e);n[r]=i}}(window,"RexPlugins.GameObjects.Line",x),B},"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();