UNPKG

phaser3-rex-plugins

Version:
2 lines (1 loc) 8.2 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).rexframemanagerplugin=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 r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(n=r.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 r=i.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(n,"string"))?o:String(o)),r);}var n,o;}function r(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(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 s(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,r=n(t);if(e){var o=n(this).constructor;i=Reflect.construct(r,arguments,o);}else i=r.apply(this,arguments);return a(this,i)}}var h,c,u=Phaser.Game,l=function(t){return t instanceof u},f=Phaser.Scene,d=function(t){return t instanceof f},v=function(e){return null==e||"object"!==t(e)?null:l(e)?e:l(e.game)?e.game:d(e)?e.sys.game:d(e.scene)?e.scene.sys.game:void 0},m=function(t,e,i,r,n){if(void 0===h){var o=(a=t.manager.game,v(a).textures.getFrame("__WHITE"));h=o.cutWidth,c=o.cutHeight;}var a;return t.stamp("__WHITE",void 0,e,i,{scaleX:r/h,scaleY:n/c,originX:0,originY:0,erase:!0}),t},y=function(t,e,i,r){this.useDynamicTexture?m(this.texture,t,e,i,r):this.context.clearRect(t,e,i,r);},g=function(t,e,i,r,n){var o=this.context;o.save(),o.translate(t,e),n?r.call(n,this.canvas,o,i):r(this.canvas,o,i),o.restore();},p=function(t,e,i,r,n){var o=this.texture;o.camera.setScroll(-t,-e),n?r.call(n,o,i):r(o,i),o.camera.setScroll(0,0);},b={remove:function(t){var e=this.getFrameIndex(t);return -1===e||(this.addFrameName(e,void 0),this.texture.remove(t)),this},clear:function(){for(var t,e=this.frameNames.length;t<e;t++){var i=this.frameNames[t];void 0!==i&&(this.addFrameName(index,void 0),this.texture.remove(i));}return this}},x={draw:function(t,e,i){var r=this.getFrameIndex(t);if(-1===r&&(r=this.getFrameIndex(void 0)),-1===r)return console.warn("Does not have free space."),this;var n=this.getTopLeftPosition(r),o=n.x,a=n.y,s=this.cellPadding,h=o+s,c=a+s;y.call(this,o,a,this.outerCellWidth,this.outerCellHeight);var u={width:this.cellWidth,height:this.cellHeight};return (this.useDynamicTexture?p:g).call(this,h,c,u,e,i),this.texture.add(t,0,h,c,u.width,u.height),this.addFrameName(r,t),this},paste:function(t,e){var i;if(this.useDynamicTexture){var r=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width}(e),n=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height}(e);h=r<=this.cellWidth&&n<=this.cellHeight?1:Math.max(r/this.cellWidth,n/this.cellHeight),i=function(t,i){var o=e.originX,a=e.originY,s=e.scaleX,c=e.scaleY;e.setOrigin(0,0).setScale(h,h),t.draw(e),e.setOrigin(o,a).setScale(s,c),i.width=r/h,i.height=n/h;};}else {var o=e.canvas;if(!o)return console.warn("Can't get canvas of game object."),this;var a,s;r=o.width,n=o.height;if(r<=this.cellWidth&&n<=this.cellHeight)a=r,s=n;else {var h=Math.max(r/this.cellWidth,n/this.cellHeight);a=r/h,s=n/h;}i=function(t,e,i){e.drawImage(o,0,0,a,s),i.width=a,i.height=s;};}return this.draw(t,i),this},addEmptyFrame:function(t,e,i){var r;return void 0===e&&(e=this.cellWidth),void 0===i&&(i=this.cellHeight),r=this.useDynamicTexture?function(t,r){r.width=e,r.height=i;}:function(t,r,n){n.width=e,n.height=i;},this.draw(t,r),this},addToBitmapFont:function(){var t=this.texture.key,e=this.bitmapFontCache.get(t);e||(e={data:{retroFont:!0,font:t,size:this.cellWidth,lineHeight:this.cellHeight,chars:{}},texture:t,frame:null},this.bitmapFontCache.add(t,e));for(var i=e.data.chars,r=this.frameNames,n=0,o=r.length;n<o;n++){var a=r[n];if(void 0!==a){var s=this.texture.get(a),h=s.cutX,c=s.cutY,u=s.cutWidth,l=s.cutHeight;i[a.charCodeAt(0)]={x:h,y:c,width:u,height:l,centerX:h+u/2,centerY:c+l/2,xOffset:0,yOffset:0,xAdvance:u,data:{},kerning:{},u0:s.u0,v0:s.v0,u1:s.u1,v1:s.v1};}}return this}};Object.assign(x,b);var w=Phaser.Utils.Objects.IsPlainObject,P=Phaser.Utils.Objects.GetValue,O=function(){function t(i,r,n,o,a,s,h,c){var u,l,f;if(e(this,t),w(r)){var d=r;r=P(d,"key"),n=P(d,"width"),o=P(d,"height"),a=P(d,"cellWidth"),s=P(d,"cellHeight"),f=P(d,"cellPadding",0),u=P(d,"columns"),l=P(d,"rows"),h=P(d,"fillColor"),c=P(d,"useDynamicTexture");}else "boolean"==typeof h&&(c=h,h=void 0);void 0===a&&(a=64),void 0===s&&(s=64),void 0===f&&(f=0),this.cellWidth=a,this.cellHeight=s,this.cellPadding=f,u?n=this.outerCellWidth*u:(void 0===n&&(n=4096),u=Math.floor(n/this.outerCellWidth)),l?o=this.outerCellWidth*l:(void 0===o&&(o=4096),l=Math.floor(o/this.outerCellWidth)),void 0===c&&(c=!1);var m=v(i);if(this.useDynamicTexture=c,this.texture=function(t,e,i,r,n){void 0===n&&(n=!1);var o=(t=v(t)).textures;return o.exists(e)&&o.remove(e),o[n?"addDynamicTexture":"createCanvas"](e,i,r)}(m,r,n,o,c),this.canvas=c?void 0:this.texture.getCanvas(),this.context=c?void 0:this.texture.getContext(),this.bitmapFontCache=m.cache.bitmapFont,void 0!==h)if(c)this.texture.fill(h);else {var y=this.context;y.fillStyle=h,y.fillRect(0,0,this.canvas.width,this.canvas.height);}this.key=r,this.width=n,this.height=o,this.columns=u,this.rows=l,this.totalCount=this.columns*this.rows,this.frameNames=Array(this.totalCount);for(var g=0,p=this.frameNames.length;g<p;g++)this.frameNames[g]=void 0;}return r(t,[{key:"outerCellWidth",get:function(){return this.cellWidth+2*this.cellPadding}},{key:"outerCellHeight",get:function(){return this.cellHeight+2*this.cellPadding}},{key:"destroy",value:function(){this.texture=void 0,this.canvas=void 0,this.context=void 0,this.frameNames=void 0,this.bitmapFontCache=void 0;}},{key:"getFrameIndex",value:function(t){return this.frameNames.indexOf(t)}},{key:"contains",value:function(t){return -1!==this.getFrameIndex(t)}},{key:"addFrameName",value:function(t,e){return this.frameNames[t]=e,this}},{key:"isFull",get:function(){return -1===this.getFrameIndex(void 0)}},{key:"getTopLeftPosition",value:function(t,e){void 0===e&&(e={});var i=t%this.columns,r=Math.floor(t/this.columns);return e.x=i*(this.cellWidth+2*this.cellPadding),e.y=r*(this.cellHeight+2*this.cellPadding),e}},{key:"updateTexture",value:function(){return this.useDynamicTexture||this.texture.refresh(),this}}]),t}();return Object.assign(O.prototype,x),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&&o(t,e);}(n,Phaser.Plugins.BasePlugin);var i=s(n);function n(t){return e(this,n),i.call(this,t)}return r(n,[{key:"start",value:function(){this.game.events.on("destroy",this.destroy,this);}},{key:"add",value:function(t,e,i,r,n,o,a,s){return new O(t,e,i,r,n,o,a,s)}}]),n}()}));