shaku
Version:
A simple and effective JavaScript game development framework that knows its place!
2 lines • 168 kB
JavaScript
/*! For license information please see shaku.min.js.LICENSE.txt */
(()=>{"use strict";var t={3155:t=>{t.exports=class{constructor(t){this._url=t,this._waitingCallbacks=[]}get ready(){return null===this._waitingCallbacks}onReady(t){this.valid||this.ready?t(this):this._waitingCallbacks.push(t)}waitForReady(){return new Promise(((t,e)=>{this.onReady(t)}))}_notifyReady(){if(this._waitingCallbacks){for(let t=0;t<this._waitingCallbacks.length;++t)this._waitingCallbacks[t](this);this._waitingCallbacks=null}}get url(){return this._url}get valid(){throw new Error("Not Implemented!")}load(t){throw new Error("Not Implemented!")}create(t,e){throw new Error("Not Supported for this asset type.")}destroy(){throw new Error("Not Implemented!")}}},7148:(t,e,i)=>{const r=i(499),s=i(9563),n=i(3603),o=i(7058),a=i(2262),l=i(167),h=i(1252),u=(i(3155),i(2493),i(2493)),d=(i(2544),i(5259).getLogger("assets"));r.prototype.isSoundAsset=!0,n.prototype.isBinaryAsset=!0,o.prototype.isJsonAsset=!0,a.prototype.isTextureAsset=!0,l.prototype.isFontTextureAsset=!0,h.prototype.isMsdfFontTextureAsset=!0,u.prototype.isTextureAtlasAsset=!0;var c=0;t.exports=new class extends s{constructor(){super(),this._loaded=null,this._waitingAssets=new Set,this._failedAssets=new Set,this._successfulLoadedAssetsCount=0,this.root="",this.suffix=""}#t(t){return t?this.root+t+this.suffix:t}get pendingAssets(){return Array.from(this._waitingAssets)}get failedAssets(){return Array.from(this._failedAssets)}waitForAll(){return new Promise(((t,e)=>{d.debug("Waiting for all assets..");let i=()=>0!==this._failedAssets.size?(d.warn("Done waiting for assets: had errors."),e(this.failedAssets)):0===this._waitingAssets.size?(d.debug("Done waiting for assets: everything loaded successfully."),t()):void setTimeout(i,1);i()}))}setup(){return new Promise(((t,e)=>{d.info("Setup assets manager.."),this._loaded={},t()}))}startFrame(){}endFrame(){}#e(t,e){let i=this._loaded[t]||null;if(i&&e&&!(i instanceof e))throw new Error(`Asset with URL '${t}' is already loaded, but has unexpected type (expecting ${e})!`);return i}async#i(t,e){let i=t.url,r=t.constructor.name;return this._loaded[i]=t,this._waitingAssets.add(i),new Promise((async(s,n)=>{d.debug(`Load asset [${r}] from URL '${i}'.`);try{await t.load(e)}catch(t){return d.warn(`Failed to load asset [${r}] from URL '${i}'.`),this._failedAssets.add(i),n(t)}if(this._waitingAssets.delete(i),!t.valid)return d.warn(`Failed to load asset [${r}] from URL '${i}'.`),this._failedAssets.add(i),n("Loaded asset is not valid!");d.debug(`Successfully loaded asset [${r}] from URL '${i}'.`),this._successfulLoadedAssetsCount++,s(t)}))}getCached(t){return t=this.#t(t),this._loaded[t]||null}#r(t,e,i){t=this.#t(t);let r=this.#e(t,e);var s=!1;r||(r=new e(t),s=!0);let n=new Promise((async(t,e)=>{s&&await this.#i(r,i),r.onReady((()=>{t(r)}))}));return n.asset=r,n}#s(t,e,i,r){t=this.#t(t);var s=new e(t||"_runtime_asset_"+c+++"_");r&&this._waitingAssets.add(t);let n=new Promise((async(r,n)=>{if(t&&this._loaded[t])return n(`Asset of type '${e.name}' to create with URL '${t}' already exist in cache!`);await i(s),t&&(this._loaded[t]=s),r(s)}));return n.asset=s,n}loadSound(t){return this.#r(t,r,void 0)}loadTexture(t,e){return this.#r(t,a,e)}createRenderTarget(t,e,i,r){if(!e||!i)throw new Error("Missing or invalid size!");return this.#s(t,a,(t=>{t.createRenderTarget(e,i,r)}))}createTextureAtlas(t,e,i,r,s){if(!e||!e.length)throw new Error("Missing or invalid sources!");return this.#s(t,u,(async n=>{try{await n._build(e,i,r,s),this._waitingAssets.delete(t),this._successfulLoadedAssetsCount++}catch(t){d.warn(`Failed to create texture atlas: '${t}'.`),this._failedAssets.add(url)}}),!0)}loadFontTexture(t,e){return this.#r(t,l,e)}loadMsdfFontTexture(t,e){return this.#r(t,h,e)}loadJson(t){return this.#r(t,o)}createJson(t,e){return e?this.#s(t,o,(t=>{t.create(e)})):reject("Missing or invalid data!")}loadBinary(t){return this.#r(t,n)}createBinary(t,e){return e?this.#s(t,n,(t=>{t.create(e)})):reject("Missing or invalid data!")}free(t){t=this.#t(t);let e=this._loaded[t];e&&(e.destroy(),delete this._loaded[t])}clearCache(){for(let t in this._loaded)this._loaded[t].destroy();this._loaded={},this._waitingAssets=new Set,this._failedAssets=new Set}destroy(){this.clearCache()}}},3603:(t,e,i)=>{const r=i(3155);t.exports=class extends r{constructor(t){super(t),this._data=null}load(){return new Promise(((t,e)=>{var i=new XMLHttpRequest;i.open("GET",this.url,!0),i.responseType="arraybuffer",i.onload=()=>{4==i.readyState&&(i.response?(this._data=new Uint8Array(i.response),this._notifyReady(),t()):e(i.statusText))},i.onerror=t=>{e(t)},i.send()}))}create(t){return new Promise(((e,i)=>{if(Array.isArray(t)&&(t=new Uint8Array(t)),!(t instanceof Uint8Array))return i("Binary asset source must be of type 'Uint8Array'!");this._data=t,this._notifyReady(),e()}))}get valid(){return Boolean(this._data)}destroy(){this._data=null}get data(){return this._data}string(){return(new TextDecoder).decode(this._data)}}},167:(t,e,i)=>{const r=i(3155),s=i(2544),n=i(4731),o=i(2262);class a extends r{constructor(t){super(t),this._fontName=null,this._fontSize=null,this._placeholderChar=null,this._sourceRects=null,this._texture=null,this._lineHeight=0}get lineHeight(){return this._lineHeight}get fontName(){return this._fontName}get fontSize(){return this._fontSize}get placeholderCharacter(){return this._placeholderChar}get texture(){return this._texture}load(t){return new Promise((async(e,i)=>{if(!t||!t.fontName)return i("When loading font texture you must provide params with a 'fontName' value!");this._placeholderChar=(t.missingCharPlaceholder||"?")[0];let r=void 0===t.smoothFont||t.smoothFont,h=t.extraPadding||{x:0,y:0},u=t.maxTextureWidth||1024,d=t.charactersSet||a.defaultCharactersSet;-1===d.indexOf(this._placeholderChar)&&(d+=this._placeholderChar);let c=new FontFace(t.fontName,`url(${this.url})`);await c.load(),document.fonts.add(c),this._fontName=t.fontName,this._fontSize=t.fontSize||52;let f=this.fontSize.toString()+"px "+this.fontName,_=function(t,e,i,r){let s=document.createElement("pre");s.style.fontFamily=t,s.style.fontSize=e+"px",s.style.paddingBottom=s.style.paddingLeft=s.style.paddingTop=s.style.paddingRight="0px",s.style.marginBottom=s.style.marginLeft=s.style.marginTop=s.style.marginRight="0px",s.textContent="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ",document.body.appendChild(s);let n=s.getBoundingClientRect().height+(r||0);return document.body.removeChild(s),Math.ceil(n)}(this.fontName,this.fontSize,0,h.y),g=function(t,e,i,r){let s=document.createElement("canvas").getContext("2d");s.font=e.toString()+"px "+t;let n=0,o="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";for(let t=0;t<o.length;++t)n=Math.max(n,s.measureText(o[t]).width+(r||0));return Math.ceil(n)}(this.fontName,this.fontSize,0,h.x);this._lineHeight=_;let m=new s(g+20,_+10),p=Math.floor(u/m.x),x=Math.min(d.length*m.x,u),y=Math.ceil(d.length/p)*m.y;(t.enforceTexturePowerOfTwo||void 0===t.enforceTexturePowerOfTwo)&&(x=l(x),y=l(y)),this._sourceRects={};let w=document.createElement("canvas");w.width=x,w.height=y,r||(w.style.webkitFontSmoothing="none",w.style.fontSmooth="never",w.style.textRendering="geometricPrecision");let b=w.getContext("2d");b.textBaseline="bottom",b.font=f,b.fillStyle="#ffffffff",b.imageSmoothingEnabled=r;let v=0,T=0;for(let e=0;e<d.length;++e){let i=d[e],r=Math.ceil(b.measureText(i).width+h.x);v+r>x&&(T+=Math.round(_+5),v=0);const s=t.sourceRectOffsetAdjustment||{x:0,y:0};let o=new n(v+s.x,T+s.y,r,_);this._sourceRects[i]=o,b.fillText(i,v,T+_),v+=Math.round(r+10)}if(!r){let t=b.getImageData(0,0,b.canvas.width,b.canvas.height),e=t.data;for(let t=0;t<e.length;t+=4)e[t+3]>0&&(e[t+3]<255||e[t]<255||e[t+1]<255||e[t+2]<255)&&(e[t+3]=0);b.putImageData(t,0,0)}let S=new Image;S.src=w.toDataURL("image/png"),S.onload=()=>{let t=new o(this.url+"__font-texture");t.fromImage(S),this._texture=t,this._notifyReady(),e()}}))}get width(){return this._texture._width}get height(){return this._texture._height}getSize(){return this._texture.getSize()}get valid(){return Boolean(this._texture)}getSourceRect(t){return this._sourceRects[t]||this._sourceRects[this.placeholderCharacter]}getPositionOffset(t){return s.zero()}getXAdvance(t){return this.getSourceRect(t).width}destroy(){this._texture&&this._texture.destroy(),this._fontName=null,this._fontSize=null,this._placeholderChar=null,this._sourceRects=null,this._texture=null,this._lineHeight=0}}function l(t){let e=2;for(;e<t;){if(e>=t)return e;e*=2}return e}a.defaultCharactersSet=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾",t.exports=a},7817:(t,e,i)=>{t.exports=i(7148)},7058:(t,e,i)=>{const r=i(3155);t.exports=class extends r{constructor(t){super(t),this._data=null}load(){return new Promise(((t,e)=>{var i=new XMLHttpRequest;i.open("GET",this.url,!0),i.responseType="json",i.onload=()=>{4==i.readyState&&(i.response?(this._data=i.response,this._notifyReady(),t()):200===i.status?e("Response is not a valid JSON!"):e(i.statusText))},i.onerror=t=>{e(t)},i.send()}))}create(t){return new Promise(((e,i)=>{try{t=t?"string"==typeof t?JSON.parse(t):JSON.parse(JSON.stringify(t)):{}}catch(t){return i("Data is not a valid JSON serializable object!")}this._data=t,this._notifyReady(),e()}))}get data(){return this._data}get valid(){return Boolean(this._data)}destroy(){this._data=null}}},1252:(t,e,i)=>{const r=i(2544),s=i(4731),n=i(2262),o=i(167),a=i(7058),l=i(5387);t.exports=class extends o{constructor(t){super(t),this._positionOffsets=null,this._xAdvances=null}load(t){return new Promise((async(e,i)=>{if(!t||!t.jsonUrl||!t.textureUrl)return i("When loading an msdf font you must provide params with a 'jsonUrl' and a 'textureUrl'!");let o=new a(t.jsonUrl),h=new n(t.textureUrl);await Promise.all([o.load(),h.load()]);let u=o.data;if(h.filter=l.Linear,u.common.pages>1)throw new Error("Can't use MSDF font with several pages");if(this._placeholderChar=(t.missingCharPlaceholder||"?")[0],!u.info.charset.includes(this._placeholderChar))throw new Error("The atlas' charset doesn't include the given placeholder character");this._fontName=u.info.face,this._fontSize=u.info.size,this._lineHeight=u.common.lineHeight,this._sourceRects={},this._positionOffsets={},this._xAdvances={},this._kernings={};for(const t of u.chars){let e=t.char,i=new s(t.x,t.y,t.width,t.height);this._sourceRects[e]=i,this._positionOffsets[e]=new r(t.xoffset,t.yoffset),this._xAdvances[e]=t.xadvance}this._texture=h,this._notifyReady(),e()}))}get width(){return this._texture._width}get height(){return this._texture._height}getSize(){return this._texture.getSize()}getPositionOffset(t){return this._positionOffsets[t]||this._positionOffsets[this.placeholderCharacter]}getXAdvance(t){return this._xAdvances[t]||this._xAdvances[this.placeholderCharacter]}destroy(){super.destroy(),this._positionOffsets=null,this._xAdvances=null,this._kernings=null}}},499:(t,e,i)=>{const r=i(3155);t.exports=class extends r{constructor(t){super(t),this._valid=!1}load(){return new Promise(((t,e)=>{var i=new XMLHttpRequest;i.open("GET",this.url,!0),i.responseType="arraybuffer",i.onload=()=>{this._valid=!0,this._notifyReady(),t()},i.onerror=t=>{e(t)},i.send()}))}get valid(){return this._valid}destroy(){this._valid=!1}}},2262:(t,e,i)=>{const r=i(9327),s=i(4397),n=i(5259).getLogger("assets");var o=null;function a(t){return 0==(t&t-1)}t.exports=class extends s{constructor(t){super(t),this._image=null,this._width=0,this._height=0,this._texture=null,this._ctxForPixelData=null}static _setWebGl(t){o=t}load(t){return t=t||{},new Promise(((e,i)=>{if(!o)return i("Can't load textures before initializing gfx manager!");const r=new Image;void 0!==t.crossOrigin&&(r.crossOrigin=t.crossOrigin),r.onload=async()=>{try{await this.create(r,t),this._notifyReady(),e()}catch(t){i(t)}},r.onerror=()=>{i("Failed to load texture image!")},r.src=this.url}))}createRenderTarget(t,e,i){o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,!1),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);const r=t,s=e,n=o.createTexture();o.bindTexture(o.TEXTURE_2D,n);var a=o.RGBA;if(void 0!==i)switch(i){case 1:a=o.LUMINANCE;break;case 3:a=o.RGB;break;case 4:a=o.RGBA;break;default:throw new Error("Unknown render target format!")}{const t=0,e=a,i=0,n=a,l=o.UNSIGNED_BYTE,h=null;o.texImage2D(o.TEXTURE_2D,t,e,r,s,i,n,l,h),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE)}this._width=t,this._height=e,this._texture=n,this._notifyReady()}fromImage(t,e){if(0===t.width)throw new Error("Image to build texture from must be loaded and have valid size!");if(this.valid)throw new Error("Texture asset is already initialized!");e=e||{},o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL,Boolean(e.flipY)),o.pixelStorei(o.UNPACK_PREMULTIPLY_ALPHA_WEBGL,Boolean(e.premultiplyAlpha)),this._image=t,this._width=t.width,this._height=t.height;const i=o.createTexture();o.bindTexture(o.TEXTURE_2D,i);const r=o.RGBA,s=o.RGBA,l=o.UNSIGNED_BYTE;o.bindTexture(o.TEXTURE_2D,i),o.texImage2D(o.TEXTURE_2D,0,r,s,l,t),e.generateMipMaps&&(a(t.width)&&a(t.height)&&n.warn("Tried to generate MipMaps for a texture with size that is *not* a power of two. This might not work as expected."),o.generateMipmap(o.TEXTURE_2D)),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_S,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_WRAP_T,o.CLAMP_TO_EDGE),o.texParameteri(o.TEXTURE_2D,o.TEXTURE_MIN_FILTER,o.LINEAR),this._texture=i,this._notifyReady()}create(t,e){return new Promise((async(i,r)=>{if("string"==typeof t){let r=new Image;r.onload=()=>{this.fromImage(t,e),this._notifyReady(),i()},void 0!==e.crossOrigin&&(r.crossOrigin=e.crossOrigin),r.src=t}else this.fromImage(t,e),i()}))}get image(){return this._image}get width(){return this._width}get height(){return this._height}get _glTexture(){return this._texture}getPixel(t,e){if(!this._image)throw new Error("'getPixel()' only works on textures loaded from image!");if(!this._ctxForPixelData){let t=document.createElement("canvas");t.width=1,t.height=1,this._ctxForPixelData=t.getContext("2d")}let i=this._ctxForPixelData;i.drawImage(this._image,t,e,1,1,0,0,1,1);let s=i.getImageData(0,0,1,1).data;return r.fromBytesArray(s)}getPixelsData(t,e,i,s){if(!this._image)throw new Error("'getPixel()' only works on textures loaded from image!");if(t=t||0,e=e||0,i=i||this.width-t,s=s||this.height-e,!this._ctxForPixelData){let t=document.createElement("canvas");t.width=i,t.height=s,this._ctxForPixelData=t.getContext("2d")}let n=this._ctxForPixelData;n.drawImage(this._image,t,e,i,s,0,0,i,s);let o=n.getImageData(t,e,i,s).data,a=[];for(let t=0;t<i;++t){let e=[];a.push(e);for(let n=0;n<s;++n)e.push(r.fromBytesArray(o,4*t+4*n*i))}return a}get valid(){return Boolean(this._texture)}destroy(){o.deleteTexture(this._texture),this._image=null,this._width=this._height=0,this._ctxForPixelData=null,this._texture=null}}},4397:(t,e,i)=>{const r=i(3155),{TextureFilterMode:s}=i(5387),{TextureWrapMode:n}=i(2464),o=i(2544);t.exports=class extends r{constructor(t){super(t),this._filter=null,this._wrapMode=null}get filter(){return this._filter}set filter(t){this._filter=t}get wrapMode(){return this._wrapMode}set wrapMode(t){this._wrapMode=t}get image(){throw new Error("Not Implemented!")}get width(){throw new Error("Not Implemented!")}get height(){throw new Error("Not Implemented!")}getSize(){return new o(this.width,this.height)}get _glTexture(){throw new Error("Not Implemented!")}}},2493:(t,e,i)=>{const r=i(3624),{Rectangle:s}=i(3624),n=(i(2544),i(3155)),o=i(2262),a=i(8609);i(5259).getLogger("assets");var l=null;function h(t,e,i,s){e=e||l.MAX_TEXTURE_SIZE,i=i||l.MAX_TEXTURE_SIZE;let n=r.ItemsSorter.arrangeRectangles(t,(t=>{let i=1;for(;i<t;)i*=2;return t=i,Math.min(t,e)}),s);if(n.height>i){n.height=i,n.leftovers=[];for(let t=n.rectangles.length-1;t>=0;--t){let e=n.rectangles[t];e.y+e.height>i&&(n.rectangles.splice(t,1),n.leftovers.push(e.source))}}return n}function u(t){return new Promise(((e,i)=>{const r=new Image;r.crossOrigin="Anonymous",r.src=t,r.__origin_url=t,r.onload=()=>{e(r)},r.onerror=t=>{i(t)}}))}t.exports=class extends n{constructor(t){super(t),this.__textures=[],this.__sources={}}static _setWebGl(t){l=t}async _build(t,e,i,r){if(this.__textures.length)throw new Error("Texture Atlas already built!");return new Promise((async(n,d)=>{for(t=await async function(t){return new Promise((async(e,i)=>{let r=[],s=[];for(let e=0;e<t.length;++e){let n=t[e];"string"==typeof n?r.push(u(n)):n instanceof Image?n.width?s.push(n):r.push(new Promise(((t,e)=>{n.onload=t(n),n.onerror=e}))):i(`Invalid source type: ${n}. All sources must be either Image instances or URLs (string).`)}for(let t of r)s.push(await t);e(s)}))}(t),e>l.MAX_TEXTURE_SIZE&&(e=l.MAX_TEXTURE_SIZE),i>l.MAX_TEXTURE_SIZE&&(i=l.MAX_TEXTURE_SIZE);t&&t.length;){let n=h(t,e,i,r),l=new o(`_atlas_${this.url}_${this.__textures.length}`),d=document.createElement("canvas");d.width=n.width,d.height=n.height;let c=d.getContext("2d"),f=0;for(let t of n.rectangles){c.drawImage(t.source,t.x,t.y);let e=t.source.src,i=t.source.__origin_url,r=e.substr(location.origin.length),n=l.url+"_"+(f++).toString()+"_"+e.replaceAll("/","_").replaceAll(":",""),o=new s(t.x,t.y,t.width,t.height),h=new a(n,l,o,this);this.__sources[e]=this.__sources[r]=this.__sources[r.substr(1)]=h,i&&(this.__sources[i]=this.__sources[e])}let _=d.toDataURL(),g=await u(_);l.fromImage(g),l.utilized=n.utilized,this.__textures.push(l),t=n.leftovers}n()}))}get textures(){return this.__textures.slice(0)}getTexture(t){return this.__sources[t]||null}get valid(){return Boolean(this.__textures.length)}destroy(){for(let t of this.__textures)t.destroy();this.__textures=[],this.__sources={}}}},8609:(t,e,i)=>{const r=i(4397),s=i(4731);t.exports=class extends r{constructor(t,e,i,r){super(t),this._texture=e,this._sourceRect=i,this._atlas=r}get sourceRectangle(){return this._sourceRect}get sourceRectangleNormalized(){return this._sourceRectNormalized||(this._sourceRectNormalized=new s(this._sourceRect.x/this.width,this._sourceRect.y/this.height,this._sourceRect.width/this.width,this._sourceRect.height/this.height)),this._sourceRectNormalized}get texture(){return this._texture}get atlas(){return this._atlas}get image(){return this.texture.image}get width(){return this.texture.width}get height(){return this.texture.height}get _glTexture(){return this.texture._glTexture}get valid(){return Boolean(this.texture.valid)}destroy(){}}},4843:(t,e,i)=>{const r=i(9563),s=(i(2544),i(2433)),n=i(5528),o=i(9481),a=i(1282),l=i(4153),h=i(1596),u=i(6527),d=i(6601),c=i(5259).getLogger("collision");t.exports=new class extends r{constructor(){super(),this.resolver=new n}setup(){return new Promise(((t,e)=>{c.info("Setup collision manager.."),this.resolver._init(),this.resolver.setHandler("point","point",h.pointPoint),this.resolver.setHandler("point","circle",h.pointCircle),this.resolver.setHandler("point","rect",h.pointRectangle),this.resolver.setHandler("point","lines",h.pointLine),this.resolver.setHandler("point","tilemap",h.pointTilemap),this.resolver.setHandler("circle","circle",h.circleCircle),this.resolver.setHandler("circle","rect",h.circleRectangle),this.resolver.setHandler("circle","lines",h.circleLine),this.resolver.setHandler("circle","tilemap",h.circleTilemap),this.resolver.setHandler("rect","rect",h.rectangleRectangle),this.resolver.setHandler("rect","lines",h.rectangleLine),this.resolver.setHandler("rect","tilemap",h.rectangleTilemap),this.resolver.setHandler("lines","lines",h.lineLine),this.resolver.setHandler("lines","tilemap",h.lineTilemap),t()}))}createWorld(t){return new s(this.resolver,t)}get RectangleShape(){return l}get PointShape(){return a}get CircleShape(){return o}get LinesShape(){return u}get TilemapShape(){return d}startFrame(){}endFrame(){}destroy(){}}},2433:(t,e,i)=>{const r=i(9327),s=i(2544),n=i(9668),o=(i(6323),i(9135),i(7565)),a=i(4731),l=(i(5528),i(1282)),h=i(9481),u=(i(1772),i(5259).getLogger("collision"));t.exports=class{constructor(t,e){this.resolver=t,e=void 0===e?new s(512,512):"number"==typeof e?new s(e,e):e.clone(),this._gridCellSize=e,this._grid={},this._shapesToUpdate=new Set,this._cellsToDelete=new Set,this.resetStats()}resetStats(){this._stats={updatedShapes:0,addedShapes:0,deletedGridCells:0,createdGridCell:0,broadPhaseShapesChecksPrePredicate:0,broadPhaseShapesChecksPostPredicate:0,broadPhaseCalls:0,collisionChecks:0,collisionMatches:0}}get stats(){return this._stats}#n(){if(this._cellsToDelete.size>0){this._stats.deletedGridCells+=this._cellsToDelete.size;for(let t of this._cellsToDelete)this._grid[t]&&0===this._grid[t].size&&delete this._grid[t];this._cellsToDelete.clear()}if(this._shapesToUpdate.size>0){for(let t of this._shapesToUpdate)this.#o(t);this._shapesToUpdate.clear()}}#a(t,e){let i=t+","+e,r=this._grid[i];return r||(this._stats.createdGridCells++,this._grid[i]=r=new Set),r}#o(t){if(t._world!==this)return;this._stats.updatedShapes++;let e=t._getBoundingBox(),i=Math.floor(e.left/this._gridCellSize.x),r=Math.floor(e.top/this._gridCellSize.y),s=Math.ceil(e.right/this._gridCellSize.x),n=Math.ceil(e.bottom/this._gridCellSize.y);if(t._worldRange){if(t._worldRange[0]===i&&t._worldRange[1]===r&&t._worldRange[2]===s&&t._worldRange[3]===n)return;let e=t._worldRange[0],o=t._worldRange[1],a=t._worldRange[2],l=t._worldRange[3];for(let h=e;h<a;++h)for(let e=o;e<l;++e){if(h>=i&&h<s&&e>=r&&e<n)continue;let o=h+","+e,a=this._grid[o];a&&(a.delete(t),0===a.size&&this._cellsToDelete.add(o))}for(let h=i;h<s;++h)for(let i=r;i<n;++i)h>=e&&h<a&&i>=o&&i<l||this.#a(h,i).add(t)}else{this._stats.addedShapes++;for(let e=i;e<s;++e)for(let i=r;i<n;++i)this.#a(e,i).add(t)}t._worldRange=[i,r,s,n]}_queueUpdate(t){this._shapesToUpdate.add(t)}iterateShapes(t){for(let e in this._grid){let i=this._grid[e];if(i)for(let e of i)if(!1===t(e))return}}addShape(t){t._setParent(this),this.#o(t),this.#n()}removeShape(t){if(t._world===this){if(t._worldRange){let e=t._worldRange[0],i=t._worldRange[1],r=t._worldRange[2],s=t._worldRange[3];for(let n=e;n<r;++n)for(let e=i;e<s;++e){let i=n+","+e,r=this._grid[i];r&&(r.delete(t),0===r.size&&this._cellsToDelete.add(i))}}this._shapesToUpdate.delete(t),t._setParent(null),this.#n()}else u.warn("Shape to remove is not in this collision world!")}#l(t,e,i,r){let s=t._getBoundingBox(),n=Math.floor(s.left/this._gridCellSize.x),o=Math.floor(s.top/this._gridCellSize.y),a=Math.ceil(s.right/this._gridCellSize.x),l=Math.ceil(s.bottom/this._gridCellSize.y);this._stats.broadPhaseCalls++;let h=new Set;for(let s=n;s<a;++s)for(let n=o;n<l;++n){let o=s+","+n,a=this._grid[o];if(a)for(let s of a)if((!i||0!=(s.collisionFlags&i))&&!h.has(s)&&(h.add(s),s!==t&&(this._stats.broadPhaseShapesChecksPrePredicate++,(!r||r(s))&&(this._stats.broadPhaseShapesChecksPostPredicate++,!Boolean(e(s))))))return}}testCollision(t,e,i,r){this.#n();var s=null;if(e){var n=[];this.#l(t,(t=>(n.push(t),!0)),i,r),function(t,e){let i=t.getCenter();e.sort(((t,e)=>t.getCenter().distanceTo(i)-t._getRadius()-(e.getCenter().distanceTo(i)-e._getRadius())))}(t,n);var o=this.resolver.getHandlers(t);for(let e of n)if(this._stats.collisionChecks++,s=this.resolver.testWithHandler(t,e,o[e.shapeId])){this._stats.collisionMatches++;break}}else o=this.resolver.getHandlers(t),this.#l(t,(e=>(this._stats.collisionChecks++,(s=this.resolver.testWithHandler(t,e,o[e.shapeId]))&&this._stats.collisionMatches++,!s)),i,r);return s}testCollisionMany(t,e,i,r,s){this.#n();var n=[],o=this.resolver.getHandlers(t);return this.#l(t,(e=>{this._stats.collisionChecks++;let i=this.resolver.testWithHandler(t,e,o[e.shapeId]);return!i||(this._stats.collisionMatches++,n.push(i),!s||!1!==s(i))}),i,r),e&&function(t,e){let i=t.getCenter();e.sort(((t,e)=>t.second.getCenter().distanceTo(i)-t.second._getRadius()-(e.second.getCenter().distanceTo(i)-e.second._getRadius())))}(t,n),n}pick(t,e,i,r,s){let o=(e||0)<=1?new l(t):new h(new n(t,e));return this.testCollisionMany(o,i,r,s).map((t=>t.second))}setDebugDrawBatch(t){this.__debugDrawBatch=t}getOrCreateDebugDrawBatch(){return this.__debugDrawBatch||this.setDebugDrawBatch(new o.ShapesBatch),this.__debugDrawBatch}debugDraw(t,e,i,s){let n=this.getOrCreateDebugDrawBatch();n.begin(),this.#n(),t||((t=r.black).a*=.75),e||((e=r.red).a*=.75),void 0===i&&(i=.5),t.a*=.75*i,e.a*=.75*i;let l=new Set,h=s?s.getRegion():o._internal.getRenderingRegionInternal(!1),u=Math.floor(h.left/this._gridCellSize.x),d=Math.floor(h.top/this._gridCellSize.y),c=u+Math.ceil(h.width/this._gridCellSize.x),f=d+Math.ceil(h.height/this._gridCellSize.y);for(let r=u;r<=c;++r)for(let s=d;s<=f;++s){let o=this._grid[r+","+s],h=o&&o.size?e:t,u=new a(r*this._gridCellSize.x,s*this._gridCellSize.y,this._gridCellSize.x,2),d=new a(r*this._gridCellSize.x,s*this._gridCellSize.y,2,this._gridCellSize.y);if(n.drawRectangle(u,h),n.drawRectangle(d,h),o)for(let t of o)l.has(t)||(l.add(t),t.debugDraw(i,n))}n.end()}}},6740:(t,e,i)=>{t.exports=i(4843)},5528:(t,e,i)=>{i(2544);const r=i(6323),s=(i(9135),i(5259).getLogger("collision"));t.exports=class{constructor(){this._handlers={}}_init(){}setHandler(t,e,i){this._handlers[t]||(this._handlers[t]={}),this._handlers[t][e]=i,t!==e&&(this._handlers[e]||(this._handlers[e]={}),this._handlers[e][t]=(t,e)=>i(e,t))}test(t,e){let i=this.#h(t,e);return this.testWithHandler(t,e,i)}testWithHandler(t,e,i){if(!i)return s.warn(`Missing collision handler for shapes '${t.shapeId}' and '${e.shapeId}'.`),null;let n=i(t,e);if(n){let i=n.isVector2?n:null;return new r(i,t,e)}return null}getHandlers(t){return this._handlers[t.shapeId]}#h(t,e){let i=this._handlers[t.shapeId];return i&&i[e.shapeId]||null}}},1596:t=>{const e={pointPoint:function(t,e){return!!t._position.approximate(e._position)&&t._position},pointCircle:function(t,e){return t._position.distanceTo(e._circle.center)<=e._circle.radius&&t._position},pointRectangle:function(t,e){return!!e._rect.containsVector(t._position)&&t._position},pointLine:function(t,e){for(let i=0;i<e._lines.length;++i)if(e._lines[i].containsVector(t._position))return t._position;return!1},pointTilemap:function(t,i){if(i._intBoundingRect.containsVector(t._position)){let r=i.getTileAt(t._position);return!!r&&e.pointRectangle(t,r)}return!(!i._borderThickness||!i._boundingRect.containsVector(t._position))&&t._position},circleCircle:function(t,e){return t._circle.center.distanceTo(e._circle.center)<=t._circle.radius+e._circle.radius},circleRectangle:function(t,e){return e._rect.collideCircle(t._circle)},circleLine:function(t,e){for(let i=0;i<e._lines.length;++i)if(e._lines[i].distanceToVector(t._circle.center)<=t._circle.radius)return!0;return!1},circleTilemap:function(t,i){let r=!1;return i.iterateTilesAtRegion(t._getBoundingBox(),(i=>{if(e.circleRectangle(t,i))return r=!0,!1})),r},rectangleRectangle:function(t,e){return t._rect.collideRect(e._rect)},rectangleLine:function(t,e){for(let i=0;i<e._lines.length;++i)if(t._rect.collideLine(e._lines[i]))return!0;return!1},rectangleTilemap:function(t,e){let i=!1;return e.iterateTilesAtRegion(t._getBoundingBox(),(t=>(i=!0,!1))),i},lineLine:function(t,e){for(let i=0;i<t._lines.length;++i)for(let r=0;r<e._lines.length;++r)if(t._lines[i].collideLine(e._lines[r]))return!0;return!1},lineTilemap:function(t,i){let r=!1;return i.iterateTilesAtRegion(t._getBoundingBox(),(i=>{if(e.rectangleLine(i,t))return r=!0,!1})),r}};t.exports=e},6323:(t,e,i)=>{i(2544),i(9135),t.exports=class{constructor(t,e,i){this.position=t,this.first=e,this.second=i}}},9481:(t,e,i)=>{const r=i(9135),s=(i(7565),i(9668),i(4731));t.exports=class extends r{constructor(t){super(),this.setShape(t)}get shapeId(){return"circle"}setShape(t){this._circle=t,this._position=t.center,this._boundingBox=new s(t.center.x-t.radius,t.center.y-t.radius,2*t.radius,2*t.radius),this._shapeChanged()}_getRadius(){return this._circle.radius}getCenter(){return this._position.clone()}_getBoundingBox(){return this._boundingBox}debugDraw(t,e){void 0===t&&(t=1);let i=this._getDebugColor();i.a*=t;let r=!(e=this._getDebugDrawBatch(e)).isDrawing;r&&e.begin(),e.drawCircle(this._circle,i,14),r&&e.end()}}},6527:(t,e,i)=>{const r=i(9135),s=(i(7565),i(1708),i(4731)),n=i(9668);t.exports=class extends r{constructor(t){super(),this._lines=[],this.addLines(t)}get shapeId(){return"lines"}addLines(t){Array.isArray(t)||(t=[t]);for(let e=0;e<t.length;++e)this._lines.push(t[e]);let e=[];for(let t=0;t<this._lines.length;++t)e.push(this._lines[t].from),e.push(this._lines[t].to);this._boundingBox=s.fromPoints(e),this._circle=new n(this._boundingBox.getCenter(),Math.max(this._boundingBox.width,this._boundingBox.height)),this._shapeChanged()}setLines(t){this._lines=[],this.addLines(t)}_getRadius(){return this._circle.radius}getCenter(){return this._circle.center.clone()}_getBoundingBox(){return this._boundingBox}debugDraw(t,e){void 0===t&&(t=1);let i=this._getDebugColor();i.a*=t;let r=!(e=this._getDebugDrawBatch(e)).isDrawing;r&&e.begin();for(let t=0;t<this._lines.length;++t)e.drawLine(this._lines[t].from,this._lines[t].to,i);r&&e.end()}}},1282:(t,e,i)=>{const r=i(9135),s=(i(7565),i(2544),i(4731)),n=i(9668);t.exports=class extends r{constructor(t){super(),this.setPosition(t)}get shapeId(){return"point"}setPosition(t){this._position=t.clone(),this._boundingBox=new s(t.x,t.y,1,1),this._shapeChanged()}getPosition(){return this._position.clone()}getCenter(){return this._position.clone()}_getRadius(){return 1}_getBoundingBox(){return this._boundingBox}debugDraw(t,e){void 0===t&&(t=1);let i=this._getDebugColor();i.a*=t;let r=!(e=this._getDebugDrawBatch(e)).isDrawing;r&&e.begin(),e.drawCircle(new n(this.getPosition(),3),i,4),r&&e.end()}}},4153:(t,e,i)=>{i(4731);const r=i(9135);i(7565),t.exports=class extends r{constructor(t){super(),this.setShape(t)}get shapeId(){return"rect"}setShape(t){this._rect=t,this._center=t.getCenter(),this._radius=this._rect.getBoundingCircle().radius,this._shapeChanged()}_getRadius(){return this._radius}_getBoundingBox(){return this._rect}getCenter(){return this._center.clone()}debugDraw(t,e){void 0===t&&(t=1);let i=this._getDebugColor();i.a*=t;let r=!(e=this._getDebugDrawBatch(e)).isDrawing;r&&e.begin(),e.drawRectangle(this._rect,i),r&&e.end()}}},9135:(t,e,i)=>{i(1772);const r=i(9327);i(4731),i(2544),i(2433);const s=[r.red,r.blue,r.green,r.yellow,r.purple,r.teal,r.brown,r.orange,r.khaki,r.darkcyan,r.cornflowerblue,r.darkgray,r.chocolate,r.aquamarine,r.cadetblue,r.magenta,r.seagreen,r.pink,r.olive,r.violet];t.exports=class{constructor(){this._world=null,this._worldRange=null,this._debugColor=null,this._forceDebugColor=null,this._collisionFlags=Number.MAX_SAFE_INTEGER}get shapeId(){throw new Error("Not Implemented!")}get collisionFlags(){return this._collisionFlags}set collisionFlags(t){return this._debugColor=null,this._collisionFlags=t,this._collisionFlags}_getDebugDrawBatch(t){if(!t&&!this._world)throw new Error("Can't debug-draw a collision shape that is not under any collision world without providing a shapes batch to use!");return t||this._world.getOrCreateDebugDrawBatch()}setDebugColor(t){this._forceDebugColor=t}debugDraw(t,e){throw new Error("Not Implemented!")}getCenter(){throw new Error("Not Implemented!")}remove(){this._world&&this._world.removeShape(this)}_getDebugColor(){return this._forceDebugColor?this._forceDebugColor.clone():(this._debugColor||(this._debugColor=this._getDefaultDebugColorFor(this.collisionFlags)),this._debugColor.clone())}_getDefaultDebugColorFor(t){return s[t%s.length]}_getRadius(){throw new Error("Not Implemented!")}_getBoundingBox(){throw new Error("Not Implemented!")}_setParent(t){if(t!==this._world){if(this._world&&t)throw new Error("Cannot add collision shape to world while its already in another world!");this._world=t,this._worldRange=null}}_shapeChanged(){this._world&&this._world._queueUpdate(this)}}},6601:(t,e,i)=>{const r=i(9135),s=i(4731),n=i(2544),o=(i(7565),i(4153));t.exports=class extends r{constructor(t,e,i,r){super(),r=r||0,this._offset=t.clone(),this._intBoundingRect=new s(t.x,t.y,e.x*i.x,e.y*i.y),this._boundingRect=this._intBoundingRect.resize(2*r),this._center=this._boundingRect.getCenter(),this._radius=this._boundingRect.getBoundingCircle().radius,this._borderThickness=r,this._gridSize=e.clone(),this._tileSize=i.clone(),this._tiles={}}get shapeId(){return"tilemap"}_indexToKey(t){if(t.x<0||t.y<0||t.x>=this._gridSize.x||t.y>=this._gridSize.y)throw new Error(`Collision tile with index ${t.x},${t.y} is out of bounds!`);return t.x+","+t.y}setTile(t,e,i){let r=this._indexToKey(t);if(e){let e=this._tiles[r]||new o(new s(this._offset.x+t.x*this._tileSize.x,this._offset.y+t.y*this._tileSize.y,this._tileSize.x,this._tileSize.y));void 0!==i&&(e.collisionFlags=i),this._tiles[r]=e}else delete this._tiles[r]}getTileAt(t){let e=new n(Math.floor(t.x/this._tileSize.x),Math.floor(t.y/this._tileSize.y)),i=e.x+","+e.y;return this._tiles[i]||null}iterateTilesAtRegion(t,e){let i=t.getTopLeft(),r=t.getBottomRight(),s=new n(Math.floor(i.x/this._tileSize.x),Math.floor(i.y/this._tileSize.y)),o=new n(Math.floor(r.x/this._tileSize.x),Math.floor(r.y/this._tileSize.y));for(let t=s.x;t<=o.x;++t)for(let i=s.y;i<=o.y;++i){let r=t+","+i,s=this._tiles[r];if(s&&!1===e(s))return}}getTilesAtRegion(t){let e=[];return this.iterateTilesAtRegion(t,(t=>{e.push(t)})),e}_getRadius(){return this._radius}_getBoundingBox(){return this._boundingRect}getCenter(){return this._center.clone()}debugDraw(t,e){void 0===t&&(t=1);for(let i in this._tiles){let r=this._tiles[i];r.setDebugColor(this._forceDebugColor),r.debugDraw(t,e)}}}},3223:t=>{const e={AlphaBlend:"alpha",Opaque:"opaque",Additive:"additive",Multiply:"multiply",Subtract:"subtract",Screen:"screen",Overlay:"overlay",Invert:"invert",Darken:"darken",DestIn:"dest-in",DestOut:"dest-out"};Object.defineProperty(e,"_values",{value:new Set(Object.values(e)),writable:!1}),Object.freeze(e),t.exports={BlendModes:e}},2726:(t,e,i)=>{const r=i(4731),s=(i(2544),i(5529));i(8329),i(4353),t.exports=class{constructor(t){this.__region=null,this.__gfx=t,this.__viewport=null,this.orthographic()}get viewport(){return this.__viewport}set viewport(t){return this.__viewport=t,t}getRegion(){return this.__region.clone()}orthographicOffset(t,e,i,s){let n=e||!this.viewport?this.__gfx.getCanvasSize():this.viewport.getSize(),o=new r(t.x,t.y,n.x,n.y);this.orthographic(o,i,s)}orthographic(t,e,i){void 0===t&&(t=this.__gfx._internal.getRenderingRegionInternal()),this.__region=t,this.projection=s.createOrthographic(t.left,t.right,t.bottom,t.top,e||-1,i||400)}}},8871:(t,e,i)=>{const r=i(5529),s=i(8329),n=i(4353),o=i(2726);i(2544),t.exports=class extends o{constructor(t){super(t),this.projection=null,this.view=null,this.perspective(),this.setViewLookat(new s(0,5,-10),s.zero())}calcVisibleFrustum(){if(!this.projection||!this.view)throw new Error("You must set both projection and view matrices to calculate visible frustum!");const t=new n;return t.setFromProjectionMatrix(r.multiply(this.projection,this.view)),t}setViewLookat(t,e){this.view=r.createLookAt(t||new s(0,0,-500),e||s.zeroReadonly,s.upReadonly)}getDirection(){const t=this.view.values;return new s(-t[8],-t[9],-t[10]).normalizeSelf()}getViewProjection(){return r.multiply(this.view,this.projection)}getProjectionView(){return r.multiply(this.projection,this.view)}perspective(t,e,i,s){this.projection=r.createPerspective(t||Math.PI/2,e||1,i||.1,s||1e3)}unproject(t,e=0){const i=[],r=this.getProjectionView().inverted(),n=this.viewport||Shaku.gfx.getRenderingRegion();return function(t,e,i,r){var s=i[2],n=i[3],o=e[0],a=e[1],l=e[2];o-=i[0],a=n-a-1,a-=i[1],t[0]=2*o/s-1,t[1]=2*a/n-1,t[2]=2*l-1,function(t,e,i){var r=e[0],s=e[1],n=e[2],o=i[0],a=i[1],l=i[2],h=i[3],u=i[4],d=i[5],c=i[6],f=i[7],_=i[8],g=i[9],m=i[10],p=i[11],x=i[12],y=i[13],w=i[14],b=1/(r*h+s*f+n*p+i[15]);t[0]=(r*o+s*u+n*_+x)*b,t[1]=(r*a+s*d+n*g+y)*b,t[2]=(r*l+s*c+n*m+w)*b}(t,t,r.values)}(i,[t.x,t.y,e],[n.x,n.y,n.width,n.height],r),new s(i[0],i[1],i[2])}}},8117:t=>{const e={StaticDraw:"static",DynamicDraw:"dynamic",StreamDraw:"stream"};Object.defineProperty(e,"_values",{value:new Set(Object.values(e)),writable:!1}),Object.freeze(e),t.exports={BuffersUsage:e}},2069:(t,e,i)=>{const{BlendModes:r}=i(3223),{BuffersUsage:s}=i(8117),n=i(5529),o=i(5259).getLogger("gfx-draw-batch");class a{constructor(){this.setBuffersUsage(s.StreamDraw),this.__currDrawingParams=null,this.__staticBuffers=!1,this.__drawing=!1}makeStatic(){if(this.__validateBatch(),!this.isDrawing)throw new Error("Must call 'makeStatic()' between 'begin()' and 'end()'.");this.setBuffersUsage(this.BuffersUsage.StaticDraw),this.__staticBuffers=!0}get defaultEffect(){return null}get BuffersUsage(){return s}destroy(){}get isDestroyed(){return!1}__validateBatch(){if(this.isDestroyed)throw new Error("Can't perform this action after the batch was destroyed!")}setBuffersUsage(t){switch(t){case s.DynamicDraw:this.__buffersUsage=a._gfx._internal.gl.DYNAMIC_DRAW;break;case s.StreamDraw:this.__buffersUsage=a._gfx._internal.gl.STREAM_DRAW;break;case s.StaticDraw:this.__buffersUsage=a._gfx._internal.gl.STATIC_DRAW;break;default:this.__buffersUsage=a._gfx._internal.gl.DYNAMIC_DRAW,o.warn("Illegal buffers usage value: "+t)}}get isDrawing(){return this.__drawing}__validateDrawing(t){if(!this.isDrawing)throw new Error("Can't perform this action without calling 'begin()' first!");if(t&&this.__staticBuffers)throw new Error("Can't perform this action after batch has turned static!")}begin(t,e,i,r){if(this.isDrawing)throw new Error("Can't call Drawing Batch 'begin' twice without calling 'end()' first!");this.__validateBatch();let s=this.__currDrawingParams&&this.__currDrawingParams.texture||null;e=e||this.defaultEffect,t=t||this.defaultBlendMode,this.__currDrawingParams={blendMode:t,effect:e,transform:i||n.identity,overrideEffectFlags:r,hasVertexColor:e.hasVertexColor,texture:s},this.__drawing=!0}endWithoutDraw(){this.__validateBatch(),this.__validateDrawing(!1),this.__staticBuffers||(this.clear(),this.__currDrawingParams=null),this.__drawing=!1}end(){this.__validateBatch(),this.__validateDrawing(!1),this._drawBatch(),this.__staticBuffers||(this.clear(),this.__currDrawingParams=null),this.__drawing=!1}present(){this._drawBatch()}clear(){if(this.__staticBuffers)throw new Error("Can't clear batch after it was turned static. You can only destroy it.")}get isStatic(){return this.__staticBuffers}get defaultBlendMode(){return r.AlphaBlend}_drawBatch(){this.__validateBatch(),this.__validateDrawing(!1);let t=this.__currDrawingParams.effect,e=a._gfx;e._internal.useEffect(t,this.__currDrawingParams.overrideEffectFlags),e._internal.setBlendMode(this.__currDrawingParams.blendMode),t.setWorldMatrix(this.__currDrawingParams.transform),e._internal.setActiveTexture(this.__currDrawingParams.texture),this._onSetEffect(t,this.__currDrawingParams.texture)}_onSetEffect(t,e){}}a._gfx=null,t.exports=a},8333:(t,e,i)=>{const{Rectangle:r}=i(3624),s=i(2544),n=(i(8329),i(5529)),o=i(4288),a=i(2069),l=i(5259).getLogger("gfx-sprite-batch"),h=new s(0,0),u=new s(0,0),d=new s(0,0),c=new s(0,0);t.exports=class extends a{constructor(t){super(),this.#u(t||500),this.__maxLinesCount=Math.floor(this._buffers.positionArray.length/6),this.__linesCount=0,this.__dirty=!1,this.onOverflow=null,this.snapPixels=!1,this.linesStrip=!1}get#d(){return a._gfx}get#c(){return a._gfx._internal.gl}#u(t){let e=this.#c;this._buffers={positionBuffer:e.createBuffer(),positionArray:new Float32Array(6*t),colorsBuffer:e.createBuffer(),colorsArray:new Float32Array(8*t),indexBuffer:e.createBuffer()};let i,r=3*t;r<=256&&(i=Uint8Array,this.__indicesType=e.UNSIGNED_BYTE),r<=65535?(i=Uint16Array,this.__indicesType=e.UNSIGNED_SHORT):(i=Uint32Array,this.__indicesType=e.UNSIGNED_INT);let s=new i(3*t);for(let t=0;t<s.length;t++)s[t]=t;function n(t){t&&(t._index=0)}e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this._buffers.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,s,e.STATIC_DRAW),n(this._buffers.positionArray),n(this._buffers.colorsArray)}clear(){super.clear(),this._buffers.positionArray._index=0,this._buffers.colorsArray._index=0,this.__linesCount=0,this.__dirty=!1}destroy(){let t=this.#c;this._buffers&&(this._buffers.positionBuffer&&t.deleteBuffer(this._buffers.positionBuffer),this._buffers.colorsBuffer&&t.deleteBuffer(this._buffers.colorsBuffer)),this._buffers=null}get isDestroyed(){return!1===Boolean(this._buffers)}get defaultEffect(){return this.#d.builtinEffects.Shapes}drawVertices(t){if(this.__validateDrawing(!0),!this.linesStrip&&t.length%2!=0)return void l.warn("Tried to push vertices that are not multiplication of 2!");let e=0,i=this._buffers.colorsArray,r=this._buffers.positionArray;for(let s of t)this.__currDrawingParams.hasVertexColor&&(i[i._index++]=s.color.r||0,i[i._index++]=s.color.g||0,i[i._index++]=s.color.b||0,i[i._index++]=s.color.a||0),r[r._index++]=s.position.x||0,r[r._index++]=s.position.y||0,r[r._index++]=s.position.z||0,(1==e++||this.linesStrip)&&(this.__linesCount++,this.__linesCount>=this.__maxLinesCount&&this._handleFullBuffer(),e=0);this.__dirty=!0}drawQuad(t,e,i,r,s,n){let o=this.#d.Sprite.build(null,t,e,void 0,i,r,s,n);this.#f(o)}drawRectangle(t,e,i,s,n){(t.isVector2||t.isVector3)&&(t=new r(0,0,t.x,t.y)),this.drawQuad(t.getCenter(),t.getSize(),e,i,s,n)}drawCircle(t,e,i,r,n){if(this.__validateDrawing(!0),void 0===i)i=24;else if(i<2)return;let a;if(r?"number"==typeof r&&(r=new s(1,r)):r=s.oneReadonly,n){let t=Math.cos(n),e=Math.sin(n);a=function(i){let r=i.x*t-i.y*e,s=i.x*e+i.y*t;return i.x=r,i.y=s,i}}const l=2*Math.PI/i;let h=new s(t.radius*Math.cos(0)*r.x,t.radius*Math.sin(0)*r.y);a&&a(h);for(let n=1;n<=i;n++){let i=new s(t.radius*Math.cos(n*l)*r.x,t.radius*Math.sin(n*l)*r.y);a&&a(i),this.linesStrip?(1===n&&this.drawVertices([new o(h.add(t.center),null,e)]),this.drawVertices([new o(i.add(t.center),null,e)])):this.drawVertices([new o(h.add(t.center),null,e),new o(i.add(t.center),null,e)]),h=i}}#f(t,e){this.__validateDrawing(!0),this.__dirty=!0;{let i=t.size.x,r=t.size.y,s=-i*t.origin.x,a=-r*t.origin.y;h.x=s,h.y=a,u.x=s+i,u.y=a,d.x=s,d.y=a+r,c.x=s+i,c.y=a+r;let l=!0;if(t.skew&&(t.skew.x&&(h.x+=t.skew.x*t.origin.y,u.x+=t.skew.x*t.origin.y,d.x-=t.skew.x*(1-t.origin.y),c.x-=t.skew.x*(1-t.origin.y),l=!1),t.skew.y&&(h.y+=t.skew.y*t.origin.x,d.y+=t.skew.y*t.origin.x,u.y-=t.skew.y*(1-t.origin.x),c.y-=t.skew.y*(1-t.origin.x),l=!1)),t.rotation){let f=Math.cos(t.rotation),_=Math.sin(t.rotation);function g(t){let e=t.x*f-t.y*_,i=t.x*_+t.y*f;t.x=e,t.y=i}g(h),g(u),g(d),g(c),l=!1}h.x+=t.position.x,h.y+=t.position.y,u.x+=t.position.x,u.y+=t.position.y,d.x+=t.position.x,d.y+=t.position.y,c.x+=t.position.x,c.y+=t.position.y,e&&!e.isIdentity&&(h.copy(void 0!==h.z?n.transformVector3(e,h):n.transformVector2(e,h)),u.copy(void 0!==u.z?n.transformVector3(e,u):n.transformVector2(e,u)),d.copy(void 0!==d.z?n.transformVector3(e,d):n.transformVector2(e,d)),c.copy(void 0!==c.z?n.transformVector3(e,c):n.transformVector2(e,c))),this.snapPixels&&(h.floorSelf(),u.floorSelf(),d.floorSelf(),c.floorSelf()),this.linesStrip?this.drawVertices([new o(h,null,t.color),new o(u,null,t.color),new o(c,null,t.color),new o(d,null,t.color),new o(h,null,t.color)]):this.drawVertices([new o(h,null,t.color),new o(u,null,t.color),new o(u,null,t.color),new o(c,null,t.color),new o(c,null,t.color),new o(d,null,t.color),new o(d,null,t.color),new o(h,null,t.color)])}}get linesInBatch(){return this.__linesCount}get maxLinesCount(){return this.__maxLinesCount}get isFull(){return this.__linesCount>=this.__maxLinesCount}_handleFullBuffer(){this.onOverflow&&this.onOverflow(),this._drawBatch(),this.clear()}_drawBatch(){let t=this.__currDrawingParams.effect,e=this.#c,i=this.#d,r=this._buffers.positionArray,s=this.__currDrawingParams.hasVertexColor?this._buffers.colorsArray:null,n=this._buffers.positionBuffer,o=this._buffers.colorsBuffer,a=this._buffers.indexBuffer,l=this.__dirty;if(r._index<=1)return;t=t||this.defaultEffect,super._drawBatch();const h=r._index/3;t.setPositionsAttribute(n,!0),l&&e.bufferData(e.ARRAY_BUFFER,r,this.__buffersUsage,0,r._index),this.__currDrawingParams.hasVertexColor&&o&&(t.setColorsAttribute(o,!0),l&&s&&e.bufferData(e.ARRAY_BUFFER,s,this.__buffersUsage,0,s._index)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,a),e.drawElements(this.linesStrip?e.LINE_STRIP:e.LINES,h,this.__indicesType,0),i._internal.drawCallsCount++,i._internal.drawShapePolygonsCount+=h/2,this.__dirty=!1,this.__staticBuffers&&(this._buffers.positionArray=this._buffers.colorsArray=null)}}},1772:(t,e,i)=>{const{Rectangle:r}=i(3624),s=i(2544),n=(i(8329),i(5529)),o=i(4288),a=i(2069),l=i(5259).getLogger("gfx-sprite-batch"),h=new s(0,0),u=new s(0,0),d=new s(0,0),c=new s(0,0);t.exports=class extends a{constructor(t){super(),this.#u(t||500),this.__maxPolyCount=Math.floor(this._buffers.positionArray.length/9),this.__polyCount=0,this.__dirty=!1,this.onOverflow=null,this.snapPixels=!1}get#d(){return a._gfx}get#c(){return a._gfx._internal.gl}#u(t){let e=this.#c;this._buffers={positionBuffer:e.createBuffer(),positionArray:new Float32Array(9*t),colorsBuffer:e.createBuffer(),colorsArray:new Float32Array(12*t),indexBuffer:e.createBuffer()};let i,r=3*t;r<=256&&(i=Uint8Array,this.__indicesType=e.UNSIGNED_BYTE),r<=65535?(i=Uint16Array,this.__indicesType=e.UNSIGNED_SHORT):(i=Uint32Array,this.__indicesType=e.UNSIGNED_INT);let s=new i(3*t);for(let t=0;t<s.length;t++)s[t]=t;function n(t){t&&(t._index=0)}e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this._buffers.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,s,e.STATIC_DRAW),n(this._buffers.positionArray),n(this._buffers.colorsArray)}clear(){super.clear(),this._buffers.positionArray._index=0,this._buffers.colorsArray._index=0,this.__polyCount=0,this.__dirty=!1}destroy(){let t=this.#c;this._buffers&&(this._buffers.positionBuffer&&t.deleteBuffer(this._buffers.positionBuffer),this._buffers.colorsBuffer&&t.deleteBuffer(this._buffers.colorsBuffer)),this._buffers=null}get isDestroyed(){return!1===Boolean(this._buffers)}get defaultEffect(){return this.#d.builtinEffects.Shapes}drawLine(t,e,i,r){r=r||1,length=t.distanceTo(e);let n=s.radiansBetween(t,e),o=r>1?new s(t.x,t.y-r/2):t,a=new s(length,r);this.drawQuad(o,a,i,n,new s(0,.5))}drawVertices(t){if(this.__validateDrawing(!0),t.length%3!=0)return void l.warn("Tried to push vertices that are not multiplication of 3!");let e=0,i=this._buffers.colorsArray,r=this._buffers.positionArray;for(let s of t)this.__currDrawingParams.hasVertexColor&&(i[i._index++]=s.color.r||0,i[i._index++]=s.color.g||0,i[i._index++]=s.color.b||0,i[i._index++]=s.color.a||0),r[r._index++]=s.position.x||0,r[r._index++]=s.position.y||0,r[r._index++]=s.position.z||0,2==e++&&(this.__polyCount++,this.__polyCount>=this.__maxPolyCount&&this._handleFullBuffer(),e=0);this.__dirty=!0}drawQuad(t,e,i,r,s,n){let o=this.#d.Sprite.build(null,t,e,void 0,i,r,s,n);this.#f(o)}addPoint(t,e){this.drawVertices([new o(t,null,e),new o(t.add(2,0),null,e),new o(t.add(0,2),null,e)])}drawRectangle(t,e,i,n){(t.isVector2||t.isVector3)&&(t=new r(0,0,t.x,t.y));let o=n?t.getPosition().addSelf(a.mul(n)):t.getCenter();n=n||s.halfReadonly;let a=t.getSize();this.drawQuad(o,a,e,i,n)}drawCircle(t,e,i,r,n,a){if(this.__validateDrawing(!0),void 0===i)i=24;else if(i<2)return;let l;if(r||(r=e),n?"number"==typeof n&&(n=new s(1,n)):n=s.oneReadonly,a){let t=Math.cos(a),e=Math.sin(a);l=function(i){let r=i.x*t-i.y*e,s=i.x*e+i.y*t;return i.x=r,i.y=s,i}}const h=2*Math.PI/i;let u=new s(t.radius*Math.cos(0)*n.x,t.radius*Math.sin(0)*n.y);l&&l(u);for(let a=1;a<=i;a++){let i=new s(t.radius*Math.cos(a*h)*n.x,t.radius*Math.sin(a*h)*n.y);l&&l(i),this.drawVertices([new o(t.center,null,e),new o(u.add(t.center),null,r),new o(i.add(t.center),null,r)]),u=i}}#f(t,e){this.__validateDrawing(!0),this.__dirty=!0;{let i=t.size.x,r=t.size.y,s=-i*t.origin.x,a=-r*t.origin.y;h.x=s,h.y=a,u.x=s+i,u.y=a,d.x=s,d.y=a+r,c.x=s+i,c.y=a+r;let l=!0;if(t.skew&&(t.skew.x&&(h.x+=t.skew.x*t.origin.y,u.x+=t.skew.x*t.origin.y,d.x-=t.skew.x*(1-t.origin.y),c.x-=t.skew.x*(1-t.origin.y),l=!1),t.skew.y&&(h.y+=t.skew.y*t.origin.x,d.y+=t.skew.y*t.origin.x,u.y-=t.skew.y*(1-t.origin.x),c.y-=t.skew.y*(1-t.origin.x),l=!1)),t.rotation){let f=Math.cos(t.rotation),_=Math.sin(t.rotation);function g(t){let e=t.x*f-t.y*_,i=t.x*_+t.y*f;t.x=e,t.y=i}g(h),g(u),g(d),g(c),l=!1}h.x+=t.position.x,h.y+=t.position.y,u.x+=t.position.x,u.y+=t.position.y,d.x+=t.position.x,d.y+=t.position.y,c.x+=t.position.x,c.y+=t.position.y,e&&!e.isIdentity&&(h.copy(void 0!==h.z?n.transformVector3(e,h):n.transformVector2(e,h)),u.copy(void 0!==u.z?n.transformVector3(e,u):n.transformVector2(e,u)),d.copy(void 0!==d.z?n.transformVector3(e,d):n.transformVector2(e,d)),c.copy(void 0!==c.z?n.transformVector3(e,c):n.transformVector2(e,c))),this.snapPixels&&(h.floorSelf(),u.floorSelf(),d.floorSelf(),c.floorSelf()),this.drawVertices([new o(h,null,t.color),new o(u,null,t.color),new o(d,null,t.color),new o(u,null,t.color),new o(d,null,t.color),new o(c,null,t.color)])}}get polygonsInBatch(){return this.__polyCount}get maxPolygonsCount(){return this.__maxPolyCount}get isFull(){return this.__polyCount>=this.__maxPolyCount}_handleFullBuffer(){this.onOverflow&&this.onOverflow(),this._drawBatch(),this.clear()}_drawBatch(){let t=this.__currDrawingParams.effect,e=this.#c,i=this.#d,r=this._buffers.positionArray,s=this.__currDrawingParams.hasVertexColor?this._buffers.colorsArray:null,n=this._buffers.positionBuffer,o=this._buffers.colorsBuffer,a=this._buffers.indexBuffer,l=this.__dirty,h=this.polygonsInBatch;0!==h&&(super._drawBatch(),t.setPositionsAttribute(n,!0),l&&e.bufferData(e.ARRAY_BUFFER,r,this.__buffersUsage,0,3*h*3),this.__currDrawingParams.hasVertexColor&&o&&(t.setColorsAttribute(o,!0),l&&s&&e.bufferData(e.ARRAY_BUFFER,s,this.__buffersUsage,0,3*h*4)),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,a),e.drawElements(e.TRIANGLES,3*h,this.__indicesType,0),i._internal.drawCallsCount++,i._internal.drawShapePolygonsCount+=h,this.__dirty