rapid-render 0.1.2-1.1 → 0.1.2-1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets.d.ts +9 -8
- package/dist/audio.d.ts +49 -27
- package/dist/game.d.ts +113 -81
- package/dist/index.d.ts +15 -15
- package/dist/input.d.ts +6 -4
- package/dist/interface.d.ts +29 -13
- package/dist/light.d.ts +2 -2
- package/dist/line.d.ts +2 -2
- package/dist/math.d.ts +10 -3
- package/dist/particle.d.ts +16 -13
- package/dist/rapid.global.js +1 -1
- package/dist/rapid.js +4814 -1
- package/dist/rapid.umd.cjs +1 -1
- package/dist/render.d.ts +8 -11
- package/dist/texture.d.ts +14 -18
- package/dist/tilemap.d.ts +83 -22
- package/dist/utils.d.ts +1 -1
- package/package.json +9 -7
- package/dist/depth.d.ts +0 -8
- package/dist/regions/attributes.d.ts +0 -44
- package/dist/regions/graphic_region.d.ts +0 -15
- package/dist/regions/region.d.ts +0 -41
- package/dist/regions/sprite_region.d.ts +0 -18
- package/dist/webgl/glshader.d.ts +0 -38
- package/dist/webgl/uniform.d.ts +0 -14
- package/dist/webgl/utils.d.ts +0 -37
package/dist/rapid.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t,e,s,i,r,n,a,o;exports.ScaleRadio=void 0,(t=exports.ScaleRadio||(exports.ScaleRadio={})).KEEP="keep",t.KEEP_H="keep_h",t.KEEP_W="keep_w",t.IGNORE="ignore",t.EXPAND="expand",exports.LineTextureMode=void 0,(e=exports.LineTextureMode||(exports.LineTextureMode={})).STRETCH="stretch",e.REPEAT="repeat",exports.TextureWrapMode=void 0,(s=exports.TextureWrapMode||(exports.TextureWrapMode={})).REPEAT="repeat",s.CLAMP="clamp",s.MIRROR="mirror",exports.MaskType=void 0,(i=exports.MaskType||(exports.MaskType={})).Include="normal",i.Exclude="inverse",exports.TilemapShape=void 0,(r=exports.TilemapShape||(exports.TilemapShape={})).SQUARE="square",r.ISOMETRIC="isometric",exports.ShaderType=void 0,(n=exports.ShaderType||(exports.ShaderType={})).SPRITE="sprite",n.GRAPHIC="graphic",exports.BlendMode=void 0,(a=exports.BlendMode||(exports.BlendMode={})).Additive="additive",a.Subtractive="subtractive",a.Mix="mix",exports.ParticleShape=void 0,(o=exports.ParticleShape||(exports.ParticleShape={})).POINT="point",o.CIRCLE="circle",o.RECT="rect";var h;exports.ArrayType=void 0,(h=exports.ArrayType||(exports.ArrayType={}))[h.Float32=0]="Float32",h[h.Uint32=1]="Uint32",h[h.Uint16=2]="Uint16";class l{constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case exports.ArrayType.Float32:return Float32Array;case exports.ArrayType.Uint32:return Uint32Array;case exports.ArrayType.Uint16:return Uint16Array}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case exports.ArrayType.Float32:this.typedArray=this.float32;break;case exports.ArrayType.Uint32:this.typedArray=this.uint32;break;case exports.ArrayType.Uint16:this.typedArray=this.uint16}}clear(){this.usedElemNum=0}resize(t=0){if((t+=this.usedElemNum)>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum<<=1;this.setMaxSize(this.maxElemNum)}}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.float32[this.usedElemNum++]=t}pushUint16(t){this.uint16[this.usedElemNum++]=t}pop(t){this.usedElemNum-=t}getArray(t=0,e){return null==e?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.typedArray.length}}class u extends l{constructor(t,e,s=t.ARRAY_BUFFER,i=t.STATIC_DRAW){super(e),this.dirty=!0,this.webglBufferSize=0,this.gl=t,this.buffer=t.createBuffer(),this.type=s,this.usage=i}pushFloat32(t){super.pushFloat32(t),this.dirty=!0}pushUint32(t){super.pushUint32(t),this.dirty=!0}pushUint16(t){super.pushUint16(t),this.dirty=!0}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize?(t.bufferData(this.type,this.getArray(),this.usage),this.webglBufferSize=this.maxElemNum):t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class c extends l{constructor(){super(exports.ArrayType.Float32)}pushMat(){const t=this.usedElemNum-6,e=this.typedArray;this.resize(6),this.pushFloat32(e[t+0]),this.pushFloat32(e[t+1]),this.pushFloat32(e[t+2]),this.pushFloat32(e[t+3]),this.pushFloat32(e[t+4]),this.pushFloat32(e[t+5])}popMat(){this.pop(6)}pushIdentity(){this.resize(6),this.pushFloat32(1),this.pushFloat32(0),this.pushFloat32(0),this.pushFloat32(1),this.pushFloat32(0),this.pushFloat32(0)}translate(t,e){if("number"!=typeof t)return this.translate(t.x,t.y);const s=this.usedElemNum-6,i=this.typedArray;i[s+4]=i[s+0]*t+i[s+2]*e+i[s+4],i[s+5]=i[s+1]*t+i[s+3]*e+i[s+5]}rotate(t){const e=this.usedElemNum-6,s=this.typedArray,i=Math.cos(t),r=Math.sin(t),n=s[e+0],a=s[e+1],o=s[e+2],h=s[e+3];s[e+0]=n*i-a*r,s[e+1]=n*r+a*i,s[e+2]=o*i-h*r,s[e+3]=o*r+h*i}scale(t,e){if("number"!=typeof t)return this.scale(t.x,t.y);e||(e=t);const s=this.usedElemNum-6,i=this.typedArray;i[s+0]=i[s+0]*t,i[s+1]=i[s+1]*t,i[s+2]=i[s+2]*e,i[s+3]=i[s+3]*e}apply(t,e){if("number"!=typeof t)return new f(...this.apply(t.x,t.y));const s=this.usedElemNum-6,i=this.typedArray;return[i[s+0]*t+i[s+2]*e+i[s+4],i[s+1]*t+i[s+3]*e+i[s+5]]}getInverse(){const t=this.usedElemNum-6,e=this.typedArray,s=e[t+0],i=e[t+1],r=e[t+2],n=e[t+3],a=e[t+4],o=e[t+5],h=s*n-i*r;return new Float32Array([n/h,-i/h,-r/h,s/h,(r*o-n*a)/h,(i*a-s*o)/h])}getTransform(){const t=this.usedElemNum-6,e=this.typedArray;return new Float32Array([e[t+0],e[t+1],e[t+2],e[t+3],e[t+4],e[t+5]])}setTransform(t){const e=this.usedElemNum-6,s=this.typedArray;s[e+0]=t[0],s[e+1]=t[1],s[e+2]=t[2],s[e+3]=t[3],s[e+4]=t[4],s[e+5]=t[5]}getGlobalPosition(){const t=this.usedElemNum-6,e=this.typedArray;return new f(e[t+4],e[t+5])}setGlobalPosition(t,e){if("number"!=typeof t)return void this.setGlobalPosition(t.x,t.y);const s=this.usedElemNum-6,i=this.typedArray;i[s+4]=t,i[s+5]=e}getGlobalRotation(){const t=this.usedElemNum-6,e=this.typedArray;return Math.atan2(e[t+1],e[t+0])}setGlobalRotation(t){const e=this.usedElemNum-6,s=this.typedArray,i=this.getGlobalScale(),r=Math.cos(t),n=Math.sin(t);s[e+0]=r*i.x,s[e+1]=n*i.x,s[e+2]=-n*i.y,s[e+3]=r*i.y}getGlobalScale(){const t=this.usedElemNum-6,e=this.typedArray,s=Math.sqrt(e[t+0]*e[t+0]+e[t+1]*e[t+1]),i=Math.sqrt(e[t+2]*e[t+2]+e[t+3]*e[t+3]);return new f(s,i)}setGlobalScale(t,e){if("number"!=typeof t)return void this.setGlobalScale(t.x,t.y);const s=this.getGlobalRotation(),i=Math.cos(s),r=Math.sin(s),n=this.usedElemNum-6,a=this.typedArray;a[n+0]=i*t,a[n+1]=r*t,a[n+2]=-r*e,a[n+3]=i*e}globalToLocal(t){const e=this.getInverse();return new f(e[0]*t.x+e[2]*t.y+e[4],e[1]*t.x+e[3]*t.y+e[5])}localToGlobal(t){return this.apply(t)}toCSSTransform(){const t=this.usedElemNum-6,e=this.typedArray;return`matrix(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]}, ${e[t+4]}, ${e[t+5]})`}identity(){const t=this.usedElemNum-6,e=this.typedArray;e[t+0]=1,e[t+1]=0,e[t+2]=0,e[t+3]=1,e[t+4]=0,e[t+5]=0}applyTransform(t,e=0,s=0){(t.saveTransform??1)&&this.pushMat(),t.afterSave&&t.afterSave();const i=t.x||0,r=t.y||0;(i||r)&&this.translate(i,r),t.position&&this.translate(t.position),t.rotation&&this.rotate(t.rotation),t.scale&&this.scale(t.scale);let n=t.offsetX||0,a=t.offsetY||0;t.offset&&(n+=t.offset.x,a+=t.offset.y);const o=t.origin;return o&&("number"==typeof o?(n-=o*e,a-=o*s):(n-=o.x*e,a-=o.y*s)),{offsetX:n,offsetY:a}}applyTransformAfter(t){t.beforRestore&&t.beforRestore(),(t.restoreTransform??1)&&this.popMat()}}class d extends u{constructor(t,e,s,i){super(t,exports.ArrayType.Uint16,t.ELEMENT_ARRAY_BUFFER,t.STATIC_DRAW),this.setMaxSize(e*i);for(let t=0;t<i;t++)this.addObject(t*s);this.bindBuffer(),this.bufferData()}addObject(t){}}class p{constructor(t,e,s,i=255){this._r=t,this._g=e,this._b=s,this._a=i,this.updateUint()}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0}setRGBA(t,e,s,i){this.r=t,this.g=e,this.b=s,this.a=i,this.updateUint()}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new p(this._r,this._g,this._b,this._a)}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let r=255;return t.length>=8&&(r=parseInt(t.slice(6,8),16)),new p(e,s,i,r)}add(t){return new p(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new p(Math.max(0,this.r-t.r),Math.max(0,this.g-t.g),Math.max(0,this.b-t.b),Math.max(0,this.a-t.a))}divide(t){return t instanceof p?new p(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new p(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof p?new p(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new p(this.r*t,this.g*t,this.b*t,this.a*t)}clamp(){this.r=Math.max(0,Math.min(255,this.r)),this.g=Math.max(0,Math.min(255,this.g)),this.b=Math.max(0,Math.min(255,this.b)),this.a=Math.max(0,Math.min(255,this.a))}}p.Red=new p(255,0,0,255),p.Green=new p(0,255,0,255),p.Blue=new p(0,0,255,255),p.Yellow=new p(255,255,0,255),p.Purple=new p(128,0,128,255),p.Orange=new p(255,165,0,255),p.Pink=new p(255,192,203,255),p.Gray=new p(128,128,128,255),p.Brown=new p(139,69,19,255),p.Cyan=new p(0,255,255,255),p.Magenta=new p(255,0,255,255),p.Lime=new p(192,255,0,255),p.White=new p(255,255,255,255),p.Black=new p(0,0,0,255),p.TRANSPARENT=new p(0,0,0,0);class f{constructor(t,e){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0}set(t,e){return Array.isArray(t)?(this.x=t[0],this.y=t[0]):e?(this.x=t,this.y=e):(this.x=t,this.y=t),this}add(t){return new f(this.x+t.x,this.y+t.y)}subtract(t){return new f(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof f?new f(this.x*t.x,this.y*t.y):new f(this.x*t,this.y*t)}divide(t){return t instanceof f?new f(this.x/t.x,this.y/t.y):new f(this.x/t,this.y/t)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}clone(){return new f(this.x,this.y)}copy(t){this.x=t.x,this.y=t.y}equal(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}angle(){return Math.atan2(this.y,this.x)}middle(t){return new f((this.x+t.x)/2,(this.y+t.y)/2)}abs(){return new f(Math.abs(this.x),Math.abs(this.y))}floor(){return new f(Math.floor(this.x),Math.floor(this.y))}ceil(){return new f(Math.ceil(this.x),Math.ceil(this.y))}snap(t){return new f(Math.round(this.x/t)*t,Math.round(this.y/t)*t)}stringify(){return`Vec2(${this.x}, ${this.y})`}static FromArray(t){return t.map((t=>new f(t[0],t[1])))}static fromAngle(t){return new f(Math.cos(t),Math.sin(t))}angleBetween(t){const e=this.dot(t),s=this.length()*t.length(),i=Math.max(-1,Math.min(1,e/s));return Math.acos(i)}}f.ZERO=new f(0,0),f.ONE=new f(1,1),f.UP=new f(0,1),f.DOWN=new f(0,-1),f.LEFT=new f(-1,0),f.RIGHT=new f(1,0);class m{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,s,i){return new f(m.float(t,e),m.float(s,i))}static direction(t){const e=m.angle();return new f(Math.cos(e)*t,Math.sin(e)*t)}static randomColor(t,e){return new p(m.float(t.r,e.r),m.float(t.g,e.g),m.float(t.b,e.b),m.float(t.a,e.a))}static pick(t){return t[m.int(0,t.length-1)]}static pickWeight(t){if(!t||0===t.length)return null;let e=0;for(const s of t)e+=s[1];const s=Math.random()*e;let i=0;for(const e of t)if(i+=e[1],s<=i)return e[0];return t[t.length-1][0]}static scalarOrRange(t,e){if(void 0===t)return e;if(Array.isArray(t)){if("number"==typeof t[0])return m.float(t[0],t[1]);if(t[0]instanceof f)return m.vector(t[0].x,t[1].x,t[0].y,t[1].y);if(t[0]instanceof p)return m.randomColor(t[0],t[1])}return"number"==typeof t?t:t.clone()}}class x{constructor(t){this.render=t}createLightShadowMaskPolygon(t,e,s){const i=[];t.forEach((t=>{for(let e=0;e<t.length;e++){const s=t[e],r=t[(e+1)%t.length];i.push([s,r])}})),s=s||Math.sqrt(Math.pow(this.render.width,2)+Math.pow(this.render.height,2));const r=[];return i.forEach((([t,i])=>{const n=new f(t.x-e.x,t.y-e.y),a=new f(i.x-e.x,i.y-e.y),o=i.subtract(t).perpendicular(),h=Math.abs(o.dot(n))/(o.length()*n.length())+.01,l=Math.abs(o.dot(a))/(o.length()*a.length())+.01,u=s/h,c=s/l,d=new f(n.x,n.y).normalize(),p=new f(a.x,a.y).normalize(),m=new f(t.x+d.x*u,t.y+d.y*u),x=new f(i.x+p.x*c,i.y+p.y*c);r.push([t,i,x,m])})),r}}const g=(t,e,s,i)=>{const r=[],n=i?Math.atan2(e.y,e.x):Math.atan2(-e.y,-e.x),a=Math.PI;for(let e=0;e<10;e++){const i=n+e/10*a,o=n+(e+1)/10*a,h=Math.cos(i)*s,l=Math.sin(i)*s,u=Math.cos(o)*s,c=Math.sin(o)*s;r.push(t),r.push(t.add(new f(h,l))),r.push(t.add(new f(u,c)))}return r},y=t=>{const e=t.points;if(e.length<2)return{vertices:[],uv:[]};const{normals:s,length:i}=((t,e=!1)=>{const s=[];if(t.length<2||e&&t.length<3)return{normals:s,length:0};const i=t.length;let r=0;if(e)for(let e=0;e<i;e++){const s=t[e],n=t[(e+1)%i];r+=s.distanceTo(n)}else for(let e=0;e<i-1;e++)r+=t[e].distanceTo(t[e+1]);const n=(t,e,s)=>{const i=e.subtract(t).normalize(),r=e.subtract(s).normalize(),n=r.dot(i);if(n<-.999)return{normal:i.perpendicular(),miters:1};{let t=r.add(i).normalize();i.cross(r)<0&&(t=t.multiply(-1));let e=1/Math.sqrt((1-n)/2);return{normal:t,miters:Math.min(e,4)}}};if(e){for(let e=0;e<i-1;e++){const r=0===e?t[i-2]:t[e-1],a=t[e],o=t[e+1];s.push(n(r,a,o))}s.push(s[0])}else for(let e=0;e<i;e++)if(0===e){const e=t[1].subtract(t[0]).normalize();s.push({normal:e.perpendicular(),miters:1})}else if(e===i-1){const i=t[e].subtract(t[e-1]).normalize();s.push({normal:i.perpendicular(),miters:1})}else s.push(n(t[e-1],t[e],t[e+1]));return{normals:s,length:r}})(e,t.closed),r=(t.width||1)/2,n=[],a=[],o=t.roundCap||!1,h=t.textureMode||exports.LineTextureMode.STRETCH;let l=0;const u=t.texture?.width||1;for(let t=0;t<e.length-1;t++){const o=e[t],c=s[t].normal,d=s[t].miters,p=o.add(c.multiply(d*r)),m=o.subtract(c.multiply(d*r)),x=e[t+1],g=s[t+1].normal,y=s[t+1].miters,T=x.add(g.multiply(y*r)),w=x.subtract(g.multiply(y*r)),b=o.distanceTo(x);let E=0,R=0;h===exports.LineTextureMode.STRETCH?(E=l/i,R=(l+b)/i):(E=l/u,R=E+b/u);const v=new f(E,0),S=new f(E,1),A=new f(R,0),M=new f(R,1);n.push(p),a.push(v),n.push(m),a.push(S),n.push(T),a.push(A),n.push(T),a.push(A),n.push(w),a.push(M),n.push(m),a.push(S),l+=b}if(o&&!t.closed){const t=e[0],i=s[0].normal,a=g(t,i,r,!0);n.push(...a);const o=e[e.length-1],h=s[e.length-1].normal,l=g(o,h,r,!1);n.push(...l)}return{vertices:n,uv:a}};var T="precision mediump float;\r\nvarying vec2 vRegion;\r\nvarying vec4 vColor;\r\n\r\nuniform sampler2D uTexture;\r\nuniform int uUseTexture;\r\n\r\nvoid main(void) {\r\n vec4 color;\r\n if(uUseTexture > 0){\r\n color = texture2D(uTexture, vRegion) * vColor;\r\n }else{\r\n color = vColor;\r\n }\r\n // fragment\r\n gl_FragColor = color;\r\n}\r\n",w="precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec4 aColor;\r\nattribute vec2 aRegion;\r\n\r\nvarying vec4 vColor;\r\nuniform mat4 uProjectionMatrix;\r\nuniform vec4 uColor;\r\nvarying vec2 vRegion;\r\n\r\nvoid main(void) {\r\n // vertex s\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n // vertex e\r\n vColor = aColor;\r\n vRegion = aRegion;\r\n}\r\n";const b=(t,e,s)=>{const i=t.createShader(s);if(!i)throw new Error("Unable to create webgl shader");t.shaderSource(i,e),t.compileShader(i);if(!t.getShaderParameter(i,t.COMPILE_STATUS)){const s=t.getShaderInfoLog(i);throw console.error("Shader compilation failed:",s),new Error("Unable to compile shader: "+s+e)}return i};function E(t,e,s,i=!1,r=!1,n="clamp"){const a=t.createTexture();if(!a)throw new Error("unable to create texture");let o;switch(t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,s?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,s?t.LINEAR:t.NEAREST),n){case"repeat":o=t.REPEAT;break;case"mirror":o=t.MIRRORED_REPEAT;break;default:o=t.CLAMP_TO_EDGE}return t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,o),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,r),i?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),a}const R=5126;var v="precision mediump float;\r\nuniform sampler2D uTextures[%TEXTURE_NUM%];\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vec4 color;\r\n %GET_COLOR%\r\n // fragment\r\n gl_FragColor = color * vColor;\r\n}",S="precision mediump float;\r\n\r\nattribute vec2 aPosition;\r\nattribute vec2 aRegion;\r\nattribute float aTextureId;\r\nattribute vec4 aColor;\r\n\r\nuniform mat4 uProjectionMatrix;\r\n\r\nvarying vec2 vRegion;\r\nvarying float vTextureId;\r\nvarying vec4 vColor;\r\n\r\nvoid main(void) {\r\n vRegion = aRegion;\r\n vTextureId = aTextureId;\r\n vColor = aColor;\r\n\r\n // vertex s\r\n gl_Position = uProjectionMatrix * vec4(aPosition, 0.0, 1.0);\r\n // vertex e\r\n}";const A=[{name:"aPosition",size:2,type:R,stride:24},{name:"aRegion",size:2,type:R,stride:24,offset:2*Float32Array.BYTES_PER_ELEMENT},{name:"aTextureId",size:1,type:R,stride:24,offset:4*Float32Array.BYTES_PER_ELEMENT},{name:"aColor",size:4,type:5121,stride:24,offset:5*Float32Array.BYTES_PER_ELEMENT,normalized:!0}],M=[{name:"aPosition",size:2,type:R,stride:20},{name:"aColor",size:4,type:5121,stride:20,offset:2*Float32Array.BYTES_PER_ELEMENT,normalized:!0},{name:"aRegion",size:2,type:R,stride:20,offset:3*Float32Array.BYTES_PER_ELEMENT}];class C{constructor(t,e,s,i,r=0){this.attributeLoc={},this.uniformLoc={},this.textureUnitNum=0,this.attributes=[];const n=function(t,e){if(t.includes("%TEXTURE_NUM%")&&(t=t.replace("%TEXTURE_NUM%",e.toString())),t.includes("%GET_COLOR%")){let s="";for(let t=0;t<e;t++)s+=0==t?`if(vTextureId == ${t}.0)`:t==e-1?"else":`else if(vTextureId == ${t}.0)`,s+=`{color = texture2D(uTextures[${t}], vRegion);}`;t=t.replace("%GET_COLOR%",s)}return t}(s,t.maxTextureUnits-r);this.program=((t,e,s)=>{var i=t.createProgram(),r=b(t,e,35633),n=b(t,s,35632);if(!i)throw new Error("Unable to create program shader");if(t.attachShader(i,r),t.attachShader(i,n),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){const e=t.getProgramInfoLog(i);throw new Error("Unable to link shader program: "+e)}return i})(t.gl,e,n),this.gl=t.gl,this.textureUnitNum=r,this.parseShader(e),this.parseShader(n),i&&this.setAttributes(i)}setUniforms(t,e){const s=this.gl;for(const i of t.getUnifromNames()){const r=this.getUniform(i);t.bind(s,i,r,e)}}getUniform(t){return this.uniformLoc[t]}use(){this.gl.useProgram(this.program)}parseShader(t){const e=this.gl,s=t.match(/attribute\s+\w+\s+(\w+)/g);if(s)for(const t of s){const s=t.split(" ")[2],i=e.getAttribLocation(this.program,s);-1!=i&&(this.attributeLoc[s]=i)}const i=t.match(/uniform\s+\w+\s+(\w+)/g);if(i)for(const t of i){const s=t.split(" ")[2];this.uniformLoc[s]=e.getUniformLocation(this.program,s)}}setAttribute(t){const e=this.attributeLoc[t.name];if(void 0!==e){const s=this.gl;s.vertexAttribPointer(e,t.size,t.type,t.normalized||!1,t.stride,t.offset||0),s.enableVertexAttribArray(e)}}setAttributes(t){this.attributes=t;for(const e of t)this.setAttribute(e)}updateAttributes(){this.setAttributes(this.attributes)}static createCostumShader(t,e,s,i,r=0){let n={[exports.ShaderType.SPRITE]:v,[exports.ShaderType.GRAPHIC]:T}[i],a={[exports.ShaderType.SPRITE]:S,[exports.ShaderType.GRAPHIC]:w}[i];const o={[exports.ShaderType.SPRITE]:A,[exports.ShaderType.GRAPHIC]:M}[i];return n=n.replace("void main(void) {",s+"\nvoid main(void) {"),a=a.replace("void main(void) {",e+"\nvoid main(void) {"),n=n.replace("// fragment","fragment(color);"),a=a.replace(/\/\/ vertex s[\s\S]*?\/\/ vertex e/,"vec2 position = aPosition;\n vertex(position, vRegion);\n gl_Position = uProjectionMatrix * vec4(position, 0.0, 1.0);"),new C(t,a,n,o,r)}}class U{constructor(t){this.usedTextures=[],this.shaders=new Map,this.isCostumShader=!1,this.freeTextureUnitNum=0,this.rapid=t,this.gl=t.gl,this.webglArrayBuffer=new u(t.gl,exports.ArrayType.Float32,t.gl.ARRAY_BUFFER,t.gl.STREAM_DRAW),this.maxTextureUnits=t.maxTextureUnits}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},((t,e)=>e))}addVertex(t,e,...s){const[i,r]=this.rapid.matrixStack.apply(t,e);this.webglArrayBuffer.pushFloat32(i),this.webglArrayBuffer.pushFloat32(r)}useTexture(t){const e=this.usedTextures.indexOf(t);return-1==e?(this.usedTextures.push(t),this.freeTextureUnitNum=this.maxTextureUnits-this.usedTextures.length,[this.usedTextures.length-1,!0]):[e,!1]}enterRegion(t){this.currentShader=t??this.getShader("default"),this.currentShader.use(),this.initializeForNextRender(),this.webglArrayBuffer.bindBuffer(),this.currentShader.updateAttributes(),this.updateProjection(),this.isCostumShader=Boolean(t)}updateProjection(){this.gl.uniformMatrix4fv(this.currentShader.uniformLoc.uProjectionMatrix,!1,this.rapid.projection)}isUnifromChanged(t){return!!t&&(this.costumUnifrom!=t||!!t?.isDirty)}setCurrentUniform(t){t.clearDirty(),this.costumUnifrom=t}exitRegion(){}initDefaultShader(t,e,s){this.setShader("default",t,e,s)}setShader(t,e,s,i){this.webglArrayBuffer.bindBuffer(),this.shaders.set(t,new C(this.rapid,e,s,i)),"default"===t&&(this.defaultShader=this.shaders.get(t))}getShader(t){return this.shaders.get(t)}render(){this.executeRender(),this.initializeForNextRender()}executeRender(){const t=this.gl;for(let e=0;e<this.usedTextures.length;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this.usedTextures[e]);this.webglArrayBuffer.bufferData()}initializeForNextRender(){this.webglArrayBuffer.clear(),this.usedTextures.length=0,this.isCostumShader=!1,this.freeTextureUnitNum=this.maxTextureUnits}hasPendingContent(){return!1}isShaderChanged(t){return(t||this.defaultShader)!=this.currentShader}}class _ extends U{constructor(t){super(t),this.vertex=0,this.offset=f.ZERO,this.drawType=t.gl.TRIANGLE_FAN,this.setShader("default",w,T,M)}startRender(t,e,s,i){i&&this.currentShader?.setUniforms(i,this),this.offset=new f(t,e),this.vertex=0,this.webglArrayBuffer.clear(),s&&s.base&&(this.texture=this.useTexture(s.base.texture)[0])}addVertex(t,e,s,i,r){this.webglArrayBuffer.resize(3),super.addVertex(t+this.offset.x,e+this.offset.y),this.webglArrayBuffer.pushUint32(r),this.webglArrayBuffer.pushFloat32(s),this.webglArrayBuffer.pushFloat32(i),this.vertex+=1}executeRender(){super.executeRender();const t=this.gl;t.uniform1i(this.currentShader.uniformLoc.uUseTexture,void 0===this.texture?0:1),this.texture&&t.uniform1i(this.currentShader.uniformLoc.uTexture,this.texture),t.drawArrays(this.drawType,0,this.vertex),this.drawType=this.rapid.gl.TRIANGLE_FAN,this.vertex=0,this.texture=void 0}}const F=Math.floor(16384);class P extends d{constructor(t,e){super(t,6,4,e)}addObject(t){super.addObject(),this.pushUint16(t),this.pushUint16(t+1),this.pushUint16(t+2),this.pushUint16(t),this.pushUint16(t+3),this.pushUint16(t+2)}}class L extends U{constructor(t){const e=t.gl;super(t),this.batchSprite=0,this.spriteTextureUnits=[],this.spriteTextureUnitIndexOffset=0,this.setShader("default",S,v,A),this.indexBuffer=new P(e,F)}addVertex(t,e,s,i,r,n){super.addVertex(t,e),this.webglArrayBuffer.pushFloat32(s),this.webglArrayBuffer.pushFloat32(i),this.webglArrayBuffer.pushFloat32(r),this.webglArrayBuffer.pushUint32(n)}renderSprite(t,e,s,i,r,n,a,o,h,l,u,c,d,p=0){(1+p>this.freeTextureUnitNum||this.batchSprite>=F||this.isUnifromChanged(u)||this.rapid.projectionDirty)&&(this.render(),u&&this.isUnifromChanged(u)&&(this.currentShader.setUniforms(u,this),this.setCurrentUniform(u)),this.rapid.projectionDirty&&this.updateProjection()),this.batchSprite++,this.webglArrayBuffer.resize(20);const[f,m]=this.useTexture(t);m&&(this.spriteTextureUnits.push(f),this.spriteTextureUnitIndexOffset=this.spriteTextureUnits[0]);const x=f-this.spriteTextureUnitIndexOffset,g=c?n:i,y=c?i:n,T=d?a:r,w=d?r:a,b=o,E=o+e,R=h,v=h+s;this.addVertex(b,R,g,T,x,l),this.addVertex(E,R,y,T,x,l),this.addVertex(E,v,y,w,x,l),this.addVertex(b,v,g,w,x,l)}executeRender(){if(super.executeRender(),this.batchSprite<=0)return;const t=this.gl;this.spriteTextureUnits.length>0&&this.gl.uniform1iv(this.currentShader.uniformLoc.uTextures,this.spriteTextureUnits),t.drawElements(t.TRIANGLES,6*this.batchSprite,t.UNSIGNED_SHORT,0)}enterRegion(t){super.enterRegion(t),this.indexBuffer.bindBuffer()}initializeForNextRender(){super.initializeForNextRender(),this.batchSprite=0,this.spriteTextureUnits.length=0}hasPendingContent(){return this.batchSprite>0}}class D{constructor(t,e){this.cache=new Map,this.render=t,this.antialias=e}async textureFromUrl(t,e=this.antialias,s=exports.TextureWrapMode.CLAMP){let i=this.cache.get(t);if(!i){const r=await this.loadImage(t);i=N.fromImageSource(this.render,r,e,s),this.cache.set(t,i)}return new I(i)}textureFromFrameBufferObject(t){return new I(t)}textureFromSource(t,e=this.antialias,s=exports.TextureWrapMode.CLAMP){let i=this.cache.get(t);return i||(i=N.fromImageSource(this.render,t,e,s),this.cache.set(t,i)),new I(i)}async loadImage(t){return new Promise((e=>{const s=new Image;s.onload=()=>{e(s)},s.src=t}))}createText(t){return new k(this.render,t)}destroy(t){t instanceof I?(t.base?.destroy(this.render.gl),this.removeCache(t)):(t.destroy(this.render.gl),this.removeCache(t))}createFrameBufferObject(t,e,s=this.antialias){return new B(this.render,t,e,s)}removeCache(t){const e=t instanceof I?t.base?.texture:t.texture;e&&this.cache.forEach(((t,s)=>{t===e&&this.cache.delete(s)}))}}class N{constructor(t,e,s,i=exports.TextureWrapMode.CLAMP){this.texture=t,this.width=e,this.height=s,this.wrapMode=i}static fromImageSource(t,e,s=!1,i=exports.TextureWrapMode.CLAMP){return new N(E(t.gl,e,s,!1,!1,i),e.width,e.height)}destroy(t){t.deleteTexture(this.texture)}}class I{constructor(t){this.scale=1,this.setBaseTextur(t)}setBaseTextur(t){t&&(this.base=t,this.setClipRegion(0,0,t.width,t.height))}setClipRegion(t,e,s,i){if(this.base)return this.clipX=t/this.base.width,this.clipY=e/this.base.height,this.clipW=this.clipX+s/this.base.width,this.clipH=this.clipY+i/this.base.height,this.width=s*this.scale,this.height=i*this.scale,this}static fromImageSource(t,e,s=!1){return new I(N.fromImageSource(t,e,s))}createSpritesHeet(t,e){if(!this.base)return[];const s=[],i=Math.floor(this.base.width/t),r=Math.floor(this.base.height/e);for(let n=0;n<r;n++)for(let r=0;r<i;r++){const i=this.clone();i.setClipRegion(r*t,n*e,t,e),s.push(i)}return s}clone(){return new I(this.base)}}class k extends I{constructor(t,e){super(),this.scale=.5,this.rapid=t,this.options=e,this.text=e.text||" ",this.updateTextImage()}updateTextImage(){const t=this.createTextCanvas();this.setBaseTextur(N.fromImageSource(this.rapid,t,!0))}createTextCanvas(){const t=document.createElement("canvas"),e=t.getContext("2d");if(!e)throw new Error("Failed to get canvas context");e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";const s=this.text.split("\n");let i=0,r=0;for(const t of s){const s=e.measureText(t);i=Math.max(i,s.width),r+=this.options.fontSize||16}t.width=2*i,t.height=2*r,e.scale(2,2),e.font=`${this.options.fontSize||16}px ${this.options.fontFamily||"Arial"}`,e.fillStyle=this.options.color||"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";let n=0;for(const t of s)e.fillText(t,0,n),n+=this.options.fontSize||16;return t}setText(t){this.text!=t&&(this.text=t,this.updateTextImage())}}class B extends N{constructor(t,e,s,i=!1){const r=t.gl,n=E(r,{width:e,height:s},i,!0,!1),a=r.createFramebuffer();if(!a)throw r.deleteTexture(n),new Error("Failed to create WebGL framebuffer");r.bindFramebuffer(r.FRAMEBUFFER,a),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,n,0);const o=r.createRenderbuffer();if(!o)throw r.deleteFramebuffer(a),r.deleteTexture(n),new Error("Failed to create depth-stencil renderbuffer");r.bindRenderbuffer(r.RENDERBUFFER,o),r.renderbufferStorage(r.RENDERBUFFER,r.STENCIL_INDEX8,e,s),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.STENCIL_ATTACHMENT,r.RENDERBUFFER,o),super(n,e,s),this.gl=r,this.framebuffer=a,r.bindTexture(r.TEXTURE_2D,null),r.bindFramebuffer(r.FRAMEBUFFER,null)}bind(){const t=this.gl;t.bindTexture(t.TEXTURE_2D,null),t.bindFramebuffer(t.FRAMEBUFFER,this.framebuffer),t.clearColor(.5,.2,.5,.5),t.clear(t.COLOR_BUFFER_BIT)}unbind(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}resize(t,e){this.width=t,this.height=e,this.gl.bindTexture(this.gl.TEXTURE_2D,this.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,e,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,null),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}destroy(t){t.deleteFramebuffer(this.framebuffer),super.destroy(t)}}class O{constructor(t,e){this.textures=new Map,this.width=t,this.height=e}setTile(t,e){e instanceof I&&(e={texture:e}),this.textures.set(t,e)}getTile(t){return this.textures.get(t)}}class G{constructor(t){this.rapid=t}getYSortRow(t,e){const s=new Map;if(!t)return s;for(const i of t){const t=Math.floor(i.ySort/e);s.has(t)||s.set(t,[]),s.get(t).push(i)}return s}getOffset(t){let e=(t.errorX??2)+1,s=(t.errorY??2)+1;if("number"==typeof t.error){const i=(t.error??2)+1;e=i,s=i}else t.error&&(e=t.error.x+1,s=t.error.y+1);return{errorX:e,errorY:s}}renderYSortRow(t,e){if(e&&0!==e.length)for(const s of e)s.render?s.render():s.entity?s.entity.onRender(t):s.renderSprite&&t.renderSprite(s.renderSprite)}getTileData(t,e){const s=e.shape??exports.TilemapShape.SQUARE,i=t.width,r=s===exports.TilemapShape.ISOMETRIC?t.height/2:t.height,n=this.rapid.matrixStack,{errorX:a,errorY:o}=this.getOffset(e),h=new f(0,0),l=new f(this.rapid.width,0),u=new f(0,this.rapid.height),c=new f(this.rapid.width,this.rapid.height),d=n.globalToLocal(h),p=n.globalToLocal(l),m=n.globalToLocal(u),x=n.globalToLocal(c),g=Math.min(d.x,p.x,m.x,x.x),y=Math.max(d.x,p.x,m.x,x.x),T=Math.min(d.y,p.y,m.y,x.y),w=Math.max(d.y,p.y,m.y,x.y),b=new f(Math.floor(g/i)-a,Math.floor(T/r)-o),E=new f(Math.ceil(y/i)+a,Math.ceil(w/r)+o);return{startTile:b,viewportWidth:E.x-b.x,viewportHeight:E.y-b.y,height:r}}renderLayer(t,e){this.rapid.matrixStack.applyTransform(e);const s=e.tileSet,{startTile:i,viewportWidth:r,viewportHeight:n,height:a}=this.getTileData(s,e),o=this.getYSortRow(e.ySortCallback,a),h=e.ySortCallback&&e.ySortCallback.length>0;for(let a=0;a<n;a++){const n=a+i.y,l=o.get(n)??[];if(n<0||n>=t.length)this.renderYSortRow(this.rapid,l);else{for(let a=0;a<r;a++){const r=a+i.x;if(r<0||r>=t[n].length)continue;const o=t[n][r],h=s.getTile(o);if(!h)continue;const u=this.mapToLocal(new f(r,n),e),c=this.rapid.matrixStack.localToGlobal(u).y+(h.ySortOffset??0),d=e.eachTile&&e.eachTile(o,r,n)||{};l.push({ySort:c,renderSprite:{...h,x:u.x+(h.x||0),y:u.y+(h.y||0),...d}})}h&&l.sort(((t,e)=>t.ySort-e.ySort)),this.renderYSortRow(this.rapid,l)}}this.rapid.matrixStack.applyTransformAfter(e)}localToMap(t,e){const s=e.tileSet;if(e.shape===exports.TilemapShape.ISOMETRIC){let e=0,i=0;const r=s.height/2,n=s.width/2;let a=Math.floor(t.y/r);const o=a%2==0;let h=Math.floor(t.x/n);const l=h%2==0,u=t.x%n/n,c=t.y%r/r,d=c<u,p=c<1-u;return o||(a-=1),d&&!l&&o?a-=1:d||!l||o?p&&l&&o?(h-=2,a-=1):p||l||o||(a+=1):(a+=1,h-=2),e=h,i=a,e=Math.floor(h/2),new f(e,i)}return new f(Math.floor(t.x/s.width),Math.floor(t.y/s.height))}mapToLocal(t,e){const s=e.tileSet;if(e.shape===exports.TilemapShape.ISOMETRIC){let e=new f(t.x*s.width,t.y*s.height/2);return t.y%2!=0&&(e.x+=s.width/2),e}return new f(t.x*s.width,t.y*s.height)}}function z(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var j,X={exports:{}};var W=(j||(j=1,function(t){var e=Object.prototype.hasOwnProperty,s="~";function i(){}function r(t,e,s){this.fn=t,this.context=e,this.once=s||!1}function n(t,e,i,n,a){if("function"!=typeof i)throw new TypeError("The listener must be a function");var o=new r(i,n||t,a),h=s?s+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],o]:t._events[h].push(o):(t._events[h]=o,t._eventsCount++),t}function a(t,e){0==--t._eventsCount?t._events=new i:delete t._events[e]}function o(){this._events=new i,this._eventsCount=0}Object.create&&(i.prototype=Object.create(null),(new i).__proto__||(s=!1)),o.prototype.eventNames=function(){var t,i,r=[];if(0===this._eventsCount)return r;for(i in t=this._events)e.call(t,i)&&r.push(s?i.slice(1):i);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},o.prototype.listeners=function(t){var e=s?s+t:t,i=this._events[e];if(!i)return[];if(i.fn)return[i.fn];for(var r=0,n=i.length,a=new Array(n);r<n;r++)a[r]=i[r].fn;return a},o.prototype.listenerCount=function(t){var e=s?s+t:t,i=this._events[e];return i?i.fn?1:i.length:0},o.prototype.emit=function(t,e,i,r,n,a){var o=s?s+t:t;if(!this._events[o])return!1;var h,l,u=this._events[o],c=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),c){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,e),!0;case 3:return u.fn.call(u.context,e,i),!0;case 4:return u.fn.call(u.context,e,i,r),!0;case 5:return u.fn.call(u.context,e,i,r,n),!0;case 6:return u.fn.call(u.context,e,i,r,n,a),!0}for(l=1,h=new Array(c-1);l<c;l++)h[l-1]=arguments[l];u.fn.apply(u.context,h)}else{var d,p=u.length;for(l=0;l<p;l++)switch(u[l].once&&this.removeListener(t,u[l].fn,void 0,!0),c){case 1:u[l].fn.call(u[l].context);break;case 2:u[l].fn.call(u[l].context,e);break;case 3:u[l].fn.call(u[l].context,e,i);break;case 4:u[l].fn.call(u[l].context,e,i,r);break;default:if(!h)for(d=1,h=new Array(c-1);d<c;d++)h[d-1]=arguments[d];u[l].fn.apply(u[l].context,h)}}return!0},o.prototype.on=function(t,e,s){return n(this,t,e,s,!1)},o.prototype.once=function(t,e,s){return n(this,t,e,s,!0)},o.prototype.removeListener=function(t,e,i,r){var n=s?s+t:t;if(!this._events[n])return this;if(!e)return a(this,n),this;var o=this._events[n];if(o.fn)o.fn!==e||r&&!o.once||i&&o.context!==i||a(this,n);else{for(var h=0,l=[],u=o.length;h<u;h++)(o[h].fn!==e||r&&!o[h].once||i&&o[h].context!==i)&&l.push(o[h]);l.length?this._events[n]=1===l.length?l[0]:l:a(this,n)}return this},o.prototype.removeAllListeners=function(t){var e;return t?(e=s?s+t:t,this._events[e]&&a(this,e)):(this._events=new i,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=s,o.EventEmitter=o,t.exports=o}(X)),X.exports),Y=z(W);class H extends Y{constructor(t,e,s,i,r){super(),this.elapsed=0,this.isRunning=!1,this.isFinished=!1,this.target=t,this.property=e,this.to=s,this.duration=i,this.easing=r}start(){const t=this.target[this.property];if("number"==typeof t)this.from=t;else{if("function"!=typeof t.clone)return console.error("Tween target property is not a 'number' or does not have a 'clone' method."),void(this.isFinished=!0);this.from=t.clone()}this.elapsed=0,this.isRunning=!0,this.isFinished=!1}update(t){if(!this.isRunning||this.isFinished)return;this.elapsed+=t;const e=Math.min(this.elapsed/this.duration,1),s=this.easing(e);let i;if("number"==typeof this.from&&"number"==typeof this.to)i=this.from+(this.to-this.from)*s;else{const t=this.from,e=this.to.subtract(t).multiply(s);i=t.add(e)}this.target[this.property]=i,e>=1&&(this.isFinished=!0,this.isRunning=!1,this.target[this.property]=this.to,this.emit("complete"))}}class K{}K.Linear=t=>t,K.EaseInQuad=t=>t*t,K.EaseOutQuad=t=>t*(2-t),K.EaseInOutQuad=t=>t<.5?2*t*t:(4-2*t)*t-1,K.EaseInCubic=t=>t*t*t,K.EaseOutCubic=t=>--t*t*t+1,K.EaseInOutCubic=t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,K.EaseInQuart=t=>t*t*t*t,K.EaseOutQuart=t=>1- --t*t*t*t,K.EaseInOutQuart=t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t;class $ extends Y{constructor(t,e=!1){super(),this.elapsedTime=0,this.isRunning=!1,this.isFinished=!1,this.duration=t,this.repeat=e}start(){this.isRunning=!0}stop(){this.isRunning=!1}update(t){this.isRunning&&!this.isFinished&&(this.elapsedTime+=t,this.elapsedTime>=this.duration&&(this.emit("timeout"),this.repeat?this.elapsedTime-=this.duration:(this.isFinished=!0,this.isRunning=!1)))}destroy(){this.isFinished=!0,this.isRunning=!1}}const q=!0;class Q{constructor(t,e){this.life=0,this.datas={},this.rapid=t,this.options=e,e.texture instanceof I?this.texture=e.texture:e.texture instanceof Array&&e.texture[0]instanceof Array?this.texture=m.pickWeight(e.texture):e.texture instanceof Array&&(this.texture=m.pick(e.texture)),this.maxLife=m.scalarOrRange(e.life,1),this.datas={speed:this.processAttribute(e.animation.speed,0),rotation:this.processAttribute(e.animation.rotation,0),scale:this.processAttribute(e.animation.scale,1),color:this.processAttribute(e.animation.color,p.White),velocity:this.processAttribute(e.animation.velocity,f.ZERO),acceleration:this.processAttribute(e.animation.acceleration,f.ZERO)},this.position=f.ZERO,this.initializePosition()}processAttribute(t,e){if(!t)return{value:e};if("object"==typeof(s=t)&&null!==s&&Object.getPrototypeOf(s)===Object.prototype){const s=m.scalarOrRange(t.start,e),i=m.scalarOrRange(t.end||s,e);return{delta:t.delta??this.getDelta(s,i,this.maxLife),value:s,damping:t.damping}}return this.processAttribute({start:t},e);var s}updateDamping(t){for(const e of Object.values(this.datas))if(e.damping){const s=e.value,i=Math.pow(e.damping,t);e.value="number"==typeof s?s*i:s.multiply(i)}}updateDelta(t){const e=this.datas;for(const e of Object.values(this.datas))if(e.delta){const s=e.value;"number"==typeof s?e.value+=t*e.delta:e.value=s.add(e.delta.multiply(t))}e.color.value.clamp();const s=f.fromAngle(e.rotation.value).multiply(e.speed.value*t);this.position=this.position.add(s).add(e.velocity.value.multiply(t)).add(e.acceleration.value.multiply(t))}getDelta(t,e,s){return"number"==typeof t&&"number"==typeof e?(e-t)/s:t instanceof f&&e instanceof f||t instanceof p&&e instanceof p?e.subtract(t).divide(s):t}update(t){return this.life+=t,!(this.life>=this.maxLife)&&(this.updateDamping(t),this.updateDelta(t),!0)}render(){this.rapid.renderSprite({...this.options,position:this.position,scale:this.datas.scale.value,rotation:this.datas.rotation.value,color:this.datas.color.value,texture:this.texture})}initializePosition(){switch(this.options.emitShape){case exports.ParticleShape.POINT:this.position=f.ZERO;break;case exports.ParticleShape.CIRCLE:const t=Math.random()*Math.PI*2,e=(this.options.emitRadius||0)*Math.sqrt(Math.random());this.position=new f(Math.cos(t)*e,Math.sin(t)*e);break;case exports.ParticleShape.RECT:this.position=new f((Math.random()-.5)*(this.options.emitRect?.width||0),(Math.random()-.5)*(this.options.emitRect?.height||0))}!this.options.localSpace&&this.options.position&&(this.position=this.position.add(this.options.position))}}class Z{constructor(t,e){this.particles=[],this.emitting=!1,this.emitTimer=0,this.emitRate=10,this.emitTime=0,this.emitTimeCounter=0,this.localSpace=q,this.position=f.ZERO,this.rapid=t,this.options=e,this.emitRate=void 0!==e.emitRate?e.emitRate:10,this.emitTime=void 0!==e.emitTime?e.emitTime:0,this.localSpace=void 0!==e.localSpace?e.localSpace:q,this.position=e.position||f.ZERO}getTransform(){return this.options}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){this.particles=[],this.emitTimeCounter=0}emit(t){const e=Math.min(t,(this.options.maxParticles||1/0)-this.particles.length);for(let t=0;t<e;t++){const t={...this.options},e=new Q(this.rapid,t);this.particles.unshift(e)}}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const t=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*t),this.emitTimeCounter-=t*this.emitTime}}else{this.emitTimer+=t;const e=this.emitRate*t,s=Math.floor(e);s>0&&(this.emit(s),this.emitTimer-=s/this.emitRate);this.emitTimer*this.emitRate>=1&&(this.emit(1),this.emitTimer-=1/this.emitRate)}for(let e=this.particles.length-1;e>=0;e--)this.particles[e].update(t)||this.particles.splice(e,1)}render(){for(const t of this.particles)t.render()}getParticleCount(){return this.particles.length}isActive(){return this.emitting||this.particles.length>0}oneShot(){this.emit(this.emitRate)}}class V{constructor(t){this.projectionDirty=!0,this.matrixStack=new c,this.tileMap=new G(this),this.light=new x(this),this.defaultColor=new p(255,255,255,255),this.regions=new Map,this.currentMaskType=[],this.currentTransform=[],this.currentFBO=[],this.lastTime=0;const e=(t=>{const e={stencil:!0},s=t.getContext("webgl2",e)||t.getContext("webgl",e);if(!s)throw new Error("Unable to initialize WebGL. Your browser may not support it.");return s})(t.canvas);this.gl=e,this.canvas=t.canvas,this.texture=new D(this,t.antialias??!1),this.maxTextureUnits=e.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.width=t.width||this.canvas.width,this.height=t.height||this.canvas.height,this.scaleEnable=t.scaleEnable??!1,this.scaleRadio=t.scaleRadio||exports.ScaleRadio.KEEP,this.devicePixelRatio=t.devicePixelRatio??window.devicePixelRatio??1,this.backgroundColor=t.backgroundColor||new p(255,255,255,255),this.registerBuildInRegion(),this.initWebgl(e),this.updateDisplaySize(this.width,this.height),this.projectionDirty=!1,this.canvas.style.display="block"}updateDisplaySize(t,e){const s=this.width,i=this.height;let r,n,a,o;if(this.scaleEnable){const h=s/i,l=t/e;switch(this.scaleRadio){case exports.ScaleRadio.IGNORE:r=s,n=i,a=t*this.devicePixelRatio,o=e*this.devicePixelRatio;break;case exports.ScaleRadio.KEEP:let u,c;r=s,n=i,l>h?(c=e,u=c*h):(u=t,c=u/h),a=u*this.devicePixelRatio,o=c*this.devicePixelRatio;break;case exports.ScaleRadio.EXPAND:l>h?(n=i,r=i*l):(r=s,n=s/l),a=t*this.devicePixelRatio,o=e*this.devicePixelRatio;break;case exports.ScaleRadio.KEEP_W:r=s,n=s/l,a=t*this.devicePixelRatio,o=e*this.devicePixelRatio;break;case exports.ScaleRadio.KEEP_H:n=i,r=i*l,a=t*this.devicePixelRatio,o=e*this.devicePixelRatio;break;default:r=s,n=i,a=t*this.devicePixelRatio,o=e*this.devicePixelRatio}}else r=s,n=i,a=s*this.devicePixelRatio,o=i*this.devicePixelRatio;this.logicWidth=r,this.logicHeight=n,this.physicsWidth=a,this.physicsHeight=o,this.resizeSize(r,n,a,o,!0)}resizeSize(t,e,s,i,r=!1){this.updateProjection(0,t,e,0),this.gl.viewport(0,0,s,i),this.gl.scissor(0,0,s,i),r&&(this.canvas.width=s,this.canvas.height=i,this.canvas.style.width=s/this.devicePixelRatio+"px",this.canvas.style.height=i/this.devicePixelRatio+"px")}updateProjection(t,e,s,i){this.projection=this.createOrthMatrix(t,e,s,i),this.projectionDirty=!0}initWebgl(t){t.enable(t.BLEND),t.disable(t.DEPTH_TEST),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.enable(t.STENCIL_TEST),t.enable(t.SCISSOR_TEST)}clearTextureUnit(){for(let t=0;t<this.maxTextureUnits;t++)this.gl.activeTexture(this.gl.TEXTURE0+t),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}registerBuildInRegion(){this.registerRegion("sprite",L),this.registerRegion("graphic",_)}registerRegion(t,e){this.regions.set(t,new e(this))}quitCurrentRegion(){this.currentRegion&&this.currentRegion.hasPendingContent()&&(this.currentRegion.render(),this.currentRegion.exitRegion())}setRegion(t,e){if(t!=this.currentRegionName||this.currentRegion&&this.currentRegion.isShaderChanged(e)){const s=this.regions.get(t);this.quitCurrentRegion(),this.currentRegion=s,this.currentRegionName=t,s.enterRegion(e)}}save(){this.matrixStack.pushMat()}restore(){this.matrixStack.popMat()}withTransform(t){this.save(),t(),this.restore()}startRender(t=!0){this.clear(),t&&this.matrixStack.clear(),this.matrixStack.pushIdentity(),this.currentRegion=void 0,this.currentRegionName=void 0;const e=performance.now(),s=this.lastTime?(e-this.lastTime)/1e3:0;return this.lastTime=e,s}endRender(){this.currentRegion?.render(),this.projectionDirty=!1}render(t){t(this.startRender()),this.endRender()}renderTileMapLayer(t,e){this.tileMap.renderLayer(t,e instanceof O?{tileSet:e}:e)}renderSprite(t){const e=t.texture;if(!e||!e.base)return;const{offsetX:s,offsetY:i}=this.startDraw(t,e.width,e.height);this.setRegion("sprite",t.shader),this.currentRegion.renderSprite(e.base.texture,e.width,e.height,e.clipX,e.clipY,e.clipW,e.clipH,s,i,(t.color||this.defaultColor).uint32,t.uniforms,t.flipX,t.flipY),this.afterDraw()}renderParticles(t){t.localSpace?(this.startDraw(t.getTransform()),t.render(),this.afterDraw()):t.render()}renderTexture(t){t.base&&this.renderSprite({texture:t})}renderLine(t){const e=t.closed?[...t.points,t.points[0]]:t.points,{vertices:s,uv:i}=y({...t,points:e});this.renderGraphic({...t,drawType:this.gl.TRIANGLES,points:s,uv:i})}renderGraphic(t){this.startGraphicDraw(t),t.points.forEach(((e,s)=>{const i=Array.isArray(t.color)?t.color[s]:t.color,r=t.uv?.[s];this.addGraphicVertex(e.x,e.y,r,i)})),this.endGraphicDraw()}startGraphicDraw(t){const{offsetX:e,offsetY:s}=this.startDraw(t);this.setRegion("graphic",t.shader);const i=this.currentRegion;i.startRender(e,s,t.texture,t.uniforms),t.drawType&&(i.drawType=t.drawType)}addGraphicVertex(t,e,s,i){this.currentRegion.addVertex(t,e,s?.x,s?.y,(i||this.defaultColor).uint32)}endGraphicDraw(){this.currentRegion.render(),this.afterDraw()}startDraw(t,e=0,s=0){return this.currentTransform.push(t),this.matrixStack.applyTransform(t,e,s)}afterDraw(){this.currentTransform.length>0&&this.matrixStack.applyTransformAfter(this.currentTransform.pop())}renderRect(t){const{width:e,height:s}=t,i=[new f(0,0),new f(e,0),new f(e,s),new f(0,s)];this.renderGraphic({...t,points:i,drawType:this.gl.TRIANGLE_FAN})}renderCircle(t){const e=t.segments||32,s=t.radius,i=t.color||this.defaultColor,r=[];for(let t=0;t<=e;t++){const i=t/e*Math.PI*2,n=Math.cos(i)*s,a=Math.sin(i)*s;r.push(new f(n,a))}this.renderGraphic({...t,points:r,color:i,drawType:this.gl.TRIANGLE_FAN})}clear(t){const e=this.gl,s=t||this.backgroundColor;e.clearColor(s.r/255,s.g/255,s.b/255,s.a/255),e.clear(e.COLOR_BUFFER_BIT),this.clearMask()}createOrthMatrix(t,e,s,i){return new Float32Array([2/(e-t),0,0,0,0,2/(i-s),0,0,0,0,-1,0,-(e+t)/(e-t),-(i+s)/(i-s),0,1])}drawMask(t=exports.MaskType.Include,e){this.startDrawMask(t),e(),this.endDrawMask()}startDrawMask(t=exports.MaskType.Include){const e=this.gl;this.currentMaskType.push(t),this.setMaskType(t,!0),e.stencilOp(e.KEEP,e.KEEP,e.REPLACE),e.colorMask(!1,!1,!1,!1)}endDrawMask(){const t=this.gl;this.quitCurrentRegion(),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.colorMask(!0,!0,!0,!0),this.setMaskType(this.currentMaskType.pop()??exports.MaskType.Include,!1)}setMaskType(t,e=!1){const s=this.gl;if(this.quitCurrentRegion(),e)this.clearMask(),s.stencilFunc(s.ALWAYS,1,255);else switch(t){case exports.MaskType.Include:s.stencilFunc(s.EQUAL,1,255);break;case exports.MaskType.Exclude:s.stencilFunc(s.NOTEQUAL,1,255)}}clearMask(){const t=this.gl;this.quitCurrentRegion(),t.clearStencil(0),t.clear(t.STENCIL_BUFFER_BIT),t.stencilFunc(t.ALWAYS,1,255)}createCostumShader(t,e,s,i=0){return C.createCostumShader(this,t,e,s,i)}startFBO(t){this.quitCurrentRegion(),t.bind(),this.clearTextureUnit(),this.resizeSize(t.width,t.height,t.width,t.height),this.updateProjection(0,t.width,0,t.height),this.save(),this.matrixStack.identity(),this.currentFBO.push(t)}endFBO(){if(this.currentFBO.length>0){const t=this.currentFBO.pop();this.quitCurrentRegion(),t.unbind(),this.clearTextureUnit(),this.resizeSize(this.logicWidth,this.logicHeight,this.physicsWidth,this.physicsHeight),this.restore()}}drawToFBO(t,e){this.startFBO(t),e(),this.endFBO()}setBlendMode(t){switch(t){case exports.BlendMode.Additive:this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE);break;case exports.BlendMode.Subtractive:this.gl.blendFunc(this.gl.ZERO,this.gl.ONE_MINUS_SRC_COLOR);break;case exports.BlendMode.Mix:this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)}}drawLightShadowMask(t){this.startDrawMask(t.type||exports.MaskType.Exclude);this.light.createLightShadowMaskPolygon(t.occlusion,t.lightSource,t.baseProjectionLength).forEach((t=>{this.renderGraphic({points:t,color:p.Black})})),this.endDrawMask()}createParticleEmitter(t){return new Z(this,t)}cssToGameCoords(t,e){const s=t instanceof f?t:new f(t,e),i=this.canvas.getBoundingClientRect(),r=s.x/i.width,n=s.y/i.height,a=r*this.logicWidth,o=n*this.logicHeight;return new f(a,o)}gameToCssCoords(t,e){const s=t instanceof f?t:new f(t,e??0),i=this.canvas.getBoundingClientRect(),r=s.x/this.logicWidth,n=s.y/this.logicHeight,a=r*i.width,o=n*i.height;return new f(a,o)}}class J extends Y{constructor(t,e){super(),this.element=t,this.audioContext=e,this.source=null,this.gainNode=this.audioContext.createGain(),this.element.addEventListener("ended",this.handleEnded.bind(this))}handleEnded(){this.emit("ended")}async play(t=!1){try{this.element.loop=t,this.source=this.audioContext.createMediaElementSource(this.element),this.source.connect(this.gainNode),this.gainNode.connect(this.audioContext.destination),await this.element.play()}catch(t){console.error("Error playing audio:",t)}}pause(){this.element.pause()}stop(){this.element.pause(),this.element.currentTime=0,this.source&&(this.source.disconnect(),this.source=null)}setVolume(t){this.gainNode.gain.value=Math.max(0,Math.min(1,t))}destroy(){this.stop(),this.gainNode.disconnect(),this.element.removeEventListener("ended",this.handleEnded.bind(this)),this.removeAllListeners()}}class tt{constructor(){this.audioContext=new(window.AudioContext||window.webkitAudioContext)}destroy(){this.audioContext.close()}}class et extends Y{constructor(t){super(),this.totalAsset=0,this.loadedAssets=0,this.game=t,this.assets={json:{},audio:{},images:{}}}loadJson(t,e){this.totalAsset++,fetch(e).then((t=>t.json())).then((e=>{this.assets.json[t]=e,this.assetLoaded()})).catch((s=>this.handleError(t,e,s)))}loadAudio(t,e){this.totalAsset++;const s=new Audio;s.src=e,s.oncanplaythrough=()=>{this.assets.audio[t]=new J(s,this.game.audio.audioContext),this.assetLoaded(),s.oncanplaythrough=null},s.onerror=()=>this.handleError(t,e,"Audio load error")}loadImage(t,e){this.totalAsset++;const s=new Image;s.src=e,s.onload=()=>{this.assets.images[t]=this.game.render.texture.textureFromSource(s),this.assetLoaded()},s.onerror=()=>this.handleError(t,e,"Image load error")}loadAssets(t){t.forEach((t=>{switch(t.type){case"json":this.loadJson(t.name,t.url);break;case"audio":this.loadAudio(t.name,t.url);break;case"image":this.loadImage(t.name,t.url);break;default:console.warn(`Unknown asset type: ${t.type}`)}}))}assetLoaded(){this.loadedAssets++;const t=this.loadedAssets/this.totalAsset;this.emit("progress",t,this.loadedAssets,this.totalAsset),this.loadedAssets===this.totalAsset&&this.emit("complete",this.assets)}handleError(t,e,s){this.emit("error",{name:t,url:e,error:s}),console.error(`Failed to load asset ${t} from ${e}:`,s)}get(t,e){return this.assets[t]?.[e]}getJSON(t){return this.assets.json[t]}getAudio(t){return this.assets.audio[t]}getTexture(t){return this.assets.images[t]}}class st{constructor(t){this.mousePosition=f.ZERO,this.keysDown=new Set,this.keysDownLastFrame=new Set,this.buttonsDown=new Set,this.buttonsDownLastFrame=new Set,this.rapid=t,this.canvas=t.canvas,this.attachEventListeners()}attachEventListeners(){const t=this.canvas.getBoundingClientRect();this.canvas.addEventListener("mousemove",this.handleMouseMove=e=>{this.mousePosition=this.rapid.cssToGameCoords(e.clientX-t.left,e.clientY-t.top)}),window.addEventListener("keydown",this.handleKeyDown=t=>{this.keysDown.add(t.code)}),window.addEventListener("keyup",this.handleKeyUp=t=>{this.keysDown.delete(t.code)}),this.canvas.addEventListener("mousedown",this.handleMouseDown=t=>{this.buttonsDown.add(t.button)}),this.canvas.addEventListener("mouseup",this.handleMouseUp=t=>{this.buttonsDown.delete(t.button)})}updateNextFrame(){this.keysDownLastFrame=new Set(this.keysDown),this.buttonsDownLastFrame=new Set(this.buttonsDown)}isKeyDown(t){return this.keysDown.has(t)}isKeyUp(t){return!this.keysDown.has(t)}wasKeyPressed(t){return this.keysDown.has(t)&&!this.keysDownLastFrame.has(t)}wasKeyReleased(t){return!this.keysDown.has(t)&&this.keysDownLastFrame.has(t)}isButtonDown(t){return this.buttonsDown.has(t)}isButtonUp(t){return!this.buttonsDown.has(t)}wasButtonPressed(t){return this.buttonsDown.has(t)&&!this.buttonsDownLastFrame.has(t)}wasButtonReleased(t){return!this.buttonsDown.has(t)&&this.buttonsDownLastFrame.has(t)}getMouseLocal(t){return t.transform.globalToLocal(this.mousePosition)}destroy(){this.canvas.removeEventListener("mousemove",this.handleMouseMove),window.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("keyup",this.handleKeyUp),this.canvas.removeEventListener("mousedown",this.handleMouseDown),this.canvas.removeEventListener("mouseup",this.handleMouseUp),this.keysDown.clear(),this.keysDownLastFrame.clear(),this.buttonsDown.clear(),this.buttonsDownLastFrame.clear()}}class it{get x(){return this.position.x}get y(){return this.position.x}set x(t){this.x=t}set y(t){this.y=t}constructor(t,e={}){this.parent=null,this.globalZindex=0,this.localZindex=0,this.transform=new c,this.children=[],this.transform.pushIdentity(),this.game=t,this.rapid=t.render,this.tags=e.tags??[],e.position?this.position=e.position:this.position=new f(e.x??0,e.y??0),"number"==typeof e.scale?this.scale=new f(e.scale,e.scale):e.scale?this.scale=e.scale:this.scale=new f(1,1),this.rotation=e.rotation??0}getParentTransform(){return this.parent?this.parent.transform:this.rapid.matrixStack}update(t){this.onUpdate(t);for(const e of this.children)e.update(t)}onUpdate(t){}collectRenderables(t){this.onRender!==it.prototype.onRender&&t.push(this);for(const e of this.children)e.collectRenderables(t)}beforOnRender(){const t=this.transform;this.rapid.matrixStack.setTransform(t.getTransform())}onRender(t){}updateTransform(t=!1){t&&this.parent&&this.parent.updateTransform(t);const e=this.transform,s=this.getParentTransform();e.setTransform(s.getTransform()),e.translate(this.position),e.rotate(this.rotation),e.scale(this.scale)}addChild(t){t.parent&&t.parent.removeChild(t),t.parent=this,this.children.push(t)}removeChild(t){const e=this.children.indexOf(t);e>-1&&(t.parent=null,this.children.splice(e,1))}findDescendant(t,e=!0){const s=[];for(const i of this.children){if(t(i)){if(e)return i;s.push(i)}const r=i.findDescendant(t,e);if(e){if(r)return r}else s.push(...r)}return e?null:s}findDescendantByTag(t,e=!1){return this.findDescendant((e=>0!==t.length&&t.every((t=>e.tags.includes(t)))),e)}dispose(){this.postDispose(),this.parent&&this.parent.removeChild(this)}postDispose(){this.children.forEach((t=>{t.dispose()}))}}class rt extends it{constructor(t,e){super(t,e),this.error=new f(rt.DEFAULT_ERROR),this.data=[[]],this.ySortCallback=[],e.error?"number"==typeof e.error?this.error=new f(e.error):this.error=e.error:this.error=new f(e.errorX??rt.DEFAULT_ERROR,e.errorY??rt.DEFAULT_ERROR),this.tileSet=e.tileSet,this.shape=e.shape??exports.TilemapShape.SQUARE,this.eachTile=e.eachTile}collectRenderables(t){this.onRender!==it.prototype.onRender&&t.push(this)}setTile(t,e,s){return e<0||e>=this.data.length||t<0||t>=this.data[e].length?(console.warn(`Tilemap.setTile: Coordinates (${t}, ${e}) are out of bounds.`),!1):(this.data[e][t]=s,!0)}getTile(t,e){if(!(e<0||e>=this.data.length||t<0||t>=this.data[e].length))return this.data[e][t]}removeTile(t,e){return this.setTile(t,e,rt.EMPTY_TILE)}fill(t,e,s,i,r){const n=e+i,a=s+r;for(let i=s;i<a;i++)for(let s=e;s<n;s++)this.setTile(s,i,t)}setData(t){this.data=t}localToMap(t){this.rapid.tileMap.localToMap(t,{tileSet:this.tileSet})}mapToLocal(t){this.rapid.tileMap.mapToLocal(t,{tileSet:this.tileSet})}onRender(t){const e=[...this.ySortCallback];this.children.forEach((t=>{e.push({ySort:t.localZindex,entity:t})})),t.renderTileMapLayer(this.data,{error:this.error,tileSet:this.tileSet,eachTile:this.eachTile,ySortCallback:e})}}rt.DEFAULT_ERROR=0,rt.EMPTY_TILE=-1;exports.BaseTexture=N,exports.Camera=class extends it{updateTransform(){const t=this.transform;t.identity();const e=new f(-this.rapid.logicWidth,-this.rapid.logicHeight).divide(2);t.translate(e),t.translate(this.position),t.rotate(this.rotation),t.scale(this.scale),t.setTransform(t.getInverse())}},exports.Color=p,exports.DynamicArrayBuffer=l,exports.Entity=it,exports.FrameBufferObject=B,exports.GLShader=C,exports.Game=class{constructor(t){this.mainScene=null,this.isRunning=!1,this.lastTime=0,this.tweens=[],this.timers=[],this.renderQueue=[],this.render=new V(t),this.input=new st(this.render),this.asset=new et(this),this.audio=new tt,this.texture=this.render.texture}switchScene(t){this.mainScene&&this.mainScene.dispose(),this.mainScene=t,t.create()}start(){this.isRunning||(this.isRunning=!0,this.lastTime=performance.now(),this.gameLoop())}stop(){this.isRunning=!1}addEntityRenderQueue(t){this.renderQueue.push(t)}gameLoop(){if(!this.isRunning)return;const t=performance.now(),e=(t-this.lastTime)/1e3;this.lastTime=t,this.render.startRender(),this.mainScene&&(this.mainScene.update(e),this.mainScene.collectRenderables(this.renderQueue),this.renderQueue.sort(((t,e)=>{const s=t.parent&&t.parent===e.parent,i=t.globalZindex-e.globalZindex;return 0===i||s?s?t.localZindex-e.localZindex:0:i})),this.renderQueue.forEach((t=>{t.beforOnRender(),t.onRender(this.render)})),this.renderQueue.length=0),this.render.endRender(),this.input.updateNextFrame(),this.updateTweens(e),this.updateTimers(e),requestAnimationFrame(this.gameLoop.bind(this))}destroy(){this.audio.destroy(),this.input.destroy()}createTimer(t,e=!1){const s=new $(t,e);return this.timers.push(s),s.start(),s}updateTimers(t){for(const e of this.timers)e.update(t);this.timers=this.timers.filter((t=>!t.isFinished))}createTween(t,e,s,i,r=K.Linear){const n=new H(t,e,s,i,r);return this.tweens.push(n),n.start(),n}updateTweens(t){for(const e of this.tweens)e.update(t);this.tweens=this.tweens.filter((t=>!t.isFinished))}},exports.InputManager=st,exports.MathUtils=class{static deg2rad(t){return t*(Math.PI/180)}static rad2deg(t){return t/(Math.PI/180)}static normalizeDegrees(t){return(t%360+360)%360}},exports.MatrixStack=c,exports.ParticleEmitter=Z,exports.Random=m,exports.Rapid=V,exports.SCALEFACTOR=2,exports.Scene=class extends it{create(){}},exports.Text=k,exports.Texture=I,exports.TextureCache=D,exports.TileMapRender=G,exports.TileSet=O,exports.Tilemap=rt,exports.Uniform=class{constructor(t){this.isDirty=!1,this.data=t}setUniform(t,e){this.data[t]!=e&&(this.isDirty=!0),this.data[t]=e}clearDirty(){this.isDirty=!1}getUnifromNames(){return Object.keys(this.data)}bind(t,e,s,i){if(!s)return;const r=this.data[e];if("number"==typeof r)t.uniform1f(s,r);else if(Array.isArray(r))switch(r.length){case 1:Number.isInteger(r[0])?t.uniform1i(s,r[0]):t.uniform1f(s,r[0]);break;case 2:Number.isInteger(r[0])?t.uniform2iv(s,r):t.uniform2fv(s,r);break;case 3:Number.isInteger(r[0])?t.uniform3iv(s,r):t.uniform3fv(s,r);break;case 4:Number.isInteger(r[0])?t.uniform4iv(s,r):t.uniform4fv(s,r);break;case 9:t.uniformMatrix3fv(s,!1,r);break;case 16:t.uniformMatrix4fv(s,!1,r);break;default:console.error(`Unsupported uniform array length for ${e}:`,r.length)}else if("boolean"==typeof r)t.uniform1i(s,r?1:0);else if(r.base?.texture){const e=i.useTexture(r.base.texture)[0];t.uniform1i(s,e)}else console.error(`Unsupported uniform type for ${e}:`,typeof r)}},exports.Vec2=f,exports.WebglBufferArray=u,exports.WebglElementBufferArray=d,exports.graphicAttributes=M,exports.spriteAttributes=A;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(t=>(t.KEEP="keep",t.KEEP_H="keep_h",t.KEEP_W="keep_w",t.IGNORE="ignore",t.EXPAND="expand",t))(t||{}),e=(t=>(t.STRETCH="stretch",t.REPEAT="repeat",t))(e||{}),i=(t=>(t.REPEAT="repeat",t.CLAMP="clamp",t.MIRROR="mirror",t))(i||{}),s=(t=>(t.Include="normal",t.Exclude="inverse",t))(s||{}),r=(t=>(t.SQUARE="square",t.ISOMETRIC="isometric",t))(r||{}),n=(t=>(t.SPRITE="sprite",t.GRAPHIC="graphic",t))(n||{}),a=(t=>(t.Additive="additive",t.Subtractive="subtractive",t.Mix="mix",t))(a||{}),o=(t=>(t.POINT="point",t.CIRCLE="circle",t.RECT="rect",t))(o||{});var h=(t=>(t[t.Float32=0]="Float32",t[t.Uint32=1]="Uint32",t[t.Uint16=2]="Uint16",t))(h||{});class u{constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case 0:return Float32Array;case 1:return Uint32Array;case 2:return Uint16Array}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case 0:this.typedArray=this.float32;break;case 1:this.typedArray=this.uint32;break;case 2:this.typedArray=this.uint16}}clear(){this.usedElemNum=0}resize(t=0){if((t+=this.usedElemNum)>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum<<=1;this.setMaxSize(this.maxElemNum)}}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.float32[this.usedElemNum++]=t}pushUint16(t){this.uint16[this.usedElemNum++]=t}pop(t){this.usedElemNum-=t}getArray(t=0,e){return null==e?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.usedElemNum}}class l extends u{constructor(t,e,i=t.ARRAY_BUFFER,s=t.STATIC_DRAW){super(e),this.dirty=!0,this.webglBufferSize=0,this.gl=t,this.buffer=t.createBuffer(),this.type=i,this.usage=s}pushFloat32(t){super.pushFloat32(t),this.dirty=!0}pushUint32(t){super.pushUint32(t),this.dirty=!0}pushUint16(t){super.pushUint16(t),this.dirty=!0}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize?(t.bufferData(this.type,this.getArray(),this.usage),this.webglBufferSize=this.maxElemNum):t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class c extends u{constructor(){super(0)}pushMat(){const t=this.usedElemNum-6,e=this.typedArray;this.resize(6),this.pushFloat32(e[t+0]),this.pushFloat32(e[t+1]),this.pushFloat32(e[t+2]),this.pushFloat32(e[t+3]),this.pushFloat32(e[t+4]),this.pushFloat32(e[t+5])}popMat(){this.pop(6)}pushIdentity(){this.resize(6),this.pushFloat32(1),this.pushFloat32(0),this.pushFloat32(0),this.pushFloat32(1),this.pushFloat32(0),this.pushFloat32(0)}translate(t,e){if("number"!=typeof t)return this.translate(t.x,t.y);const i=this.usedElemNum-6,s=this.typedArray;s[i+4]=s[i+0]*t+s[i+2]*e+s[i+4],s[i+5]=s[i+1]*t+s[i+3]*e+s[i+5]}rotate(t){const e=this.usedElemNum-6,i=this.typedArray,s=Math.cos(t),r=Math.sin(t),n=i[e+0],a=i[e+1],o=i[e+2],h=i[e+3];i[e+0]=n*s-a*r,i[e+1]=n*r+a*s,i[e+2]=o*s-h*r,i[e+3]=o*r+h*s}scale(t,e){if("number"!=typeof t)return this.scale(t.x,t.y);e||(e=t);const i=this.usedElemNum-6,s=this.typedArray;s[i+0]=s[i+0]*t,s[i+1]=s[i+1]*t,s[i+2]=s[i+2]*e,s[i+3]=s[i+3]*e}apply(t,e){if("number"!=typeof t)return new g(...this.apply(t.x,t.y));const i=this.usedElemNum-6,s=this.typedArray;return[s[i+0]*t+s[i+2]*e+s[i+4],s[i+1]*t+s[i+3]*e+s[i+5]]}getInverse(){const t=this.usedElemNum-6,e=this.typedArray,i=e[t+0],s=e[t+1],r=e[t+2],n=e[t+3],a=e[t+4],o=e[t+5],h=i*n-s*r;return new Float32Array([n/h,-s/h,-r/h,i/h,(r*o-n*a)/h,(s*a-i*o)/h])}getTransform(){const t=this.usedElemNum-6,e=this.typedArray;return new Float32Array([e[t+0],e[t+1],e[t+2],e[t+3],e[t+4],e[t+5]])}setTransform(t){const e=this.usedElemNum-6,i=this.typedArray;i[e+0]=t[0],i[e+1]=t[1],i[e+2]=t[2],i[e+3]=t[3],i[e+4]=t[4],i[e+5]=t[5]}getGlobalPosition(){const t=this.usedElemNum-6,e=this.typedArray;return new g(e[t+4],e[t+5])}setGlobalPosition(t,e){if("number"!=typeof t)return void this.setGlobalPosition(t.x,t.y);const i=this.usedElemNum-6,s=this.typedArray;s[i+4]=t,s[i+5]=e}getGlobalRotation(){const t=this.usedElemNum-6,e=this.typedArray;return Math.atan2(e[t+1],e[t+0])}setGlobalRotation(t){const e=this.usedElemNum-6,i=this.typedArray,s=this.getGlobalScale(),r=Math.cos(t),n=Math.sin(t);i[e+0]=r*s.x,i[e+1]=n*s.x,i[e+2]=-n*s.y,i[e+3]=r*s.y}getGlobalScale(){const t=this.usedElemNum-6,e=this.typedArray,i=Math.sqrt(e[t+0]*e[t+0]+e[t+1]*e[t+1]),s=Math.sqrt(e[t+2]*e[t+2]+e[t+3]*e[t+3]);return new g(i,s)}setGlobalScale(t,e){if("number"!=typeof t)return void this.setGlobalScale(t.x,t.y);const i=this.getGlobalRotation(),s=Math.cos(i),r=Math.sin(i),n=this.usedElemNum-6,a=this.typedArray;a[n+0]=s*t,a[n+1]=r*t,a[n+2]=-r*e,a[n+3]=s*e}globalToLocal(t){const e=this.getInverse();return new g(e[0]*t.x+e[2]*t.y+e[4],e[1]*t.x+e[3]*t.y+e[5])}localToGlobal(t){return this.apply(t)}toCSSTransform(){const t=this.usedElemNum-6,e=this.typedArray;return`matrix(${e[t+0]}, ${e[t+1]}, ${e[t+2]}, ${e[t+3]}, ${e[t+4]}, ${e[t+5]})`}identity(){const t=this.usedElemNum-6,e=this.typedArray;e[t+0]=1,e[t+1]=0,e[t+2]=0,e[t+3]=1,e[t+4]=0,e[t+5]=0}applyTransform(t,e=0,i=0){(t.saveTransform??1)&&this.pushMat(),t.afterSave&&t.afterSave();const s=t.x||0,r=t.y||0;(s||r)&&this.translate(s,r),t.position&&this.translate(t.position),t.rotation&&this.rotate(t.rotation),t.scale&&this.scale(t.scale);let n=t.offsetX||0,a=t.offsetY||0;t.offset&&(n+=t.offset.x,a+=t.offset.y);const o=t.origin;return o&&("number"==typeof o?(n-=o*e,a-=o*i):(n-=o.x*e,a-=o.y*i)),{offsetX:n,offsetY:a}}applyTransformAfter(t){t.beforRestore&&t.beforRestore(),(t.restoreTransform??1)&&this.popMat()}}class d extends l{constructor(t,e,i,s){super(t,2,t.ELEMENT_ARRAY_BUFFER,t.STATIC_DRAW),this.setMaxSize(e*s);for(let r=0;r<s;r++)this.addObject(r*i);this.bindBuffer(),this.bufferData()}addObject(t){}}const p=class t{constructor(t,e,i,s=255){this._r=t,this._g=e,this._b=i,this._a=s,this.updateUint()}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0}setRGBA(t,e,i,s){this.r=t,this.g=e,this.b=i,this.a=s,this.updateUint()}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new t(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),i=this.g.toString(16).padStart(2,"0"),s=this.b.toString(16).padStart(2,"0"),r=this.a.toString(16).padStart(2,"0");return`#${e}${i}${s}${t?r:""}`}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}static fromHex(e){e.startsWith("#")&&(e=e.slice(1));const i=parseInt(e.slice(0,2),16),s=parseInt(e.slice(2,4),16),r=parseInt(e.slice(4,6),16);let n=255;return e.length>=8&&(n=parseInt(e.slice(6,8),16)),new t(i,s,r,n)}add(e){return new t(Math.min(this.r+e.r,255),Math.min(this.g+e.g,255),Math.min(this.b+e.b,255),Math.min(this.a+e.a,255))}subtract(e){return new t(Math.max(0,this.r-e.r),Math.max(0,this.g-e.g),Math.max(0,this.b-e.b),Math.max(0,this.a-e.a))}divide(e){return e instanceof t?new t(this.r/e.r,this.g/e.g,this.b/e.b,this.a/e.a):new t(this.r/e,this.g/e,this.b/e,this.a/e)}multiply(e){return e instanceof t?new t(this.r*e.r,this.g*e.g,this.b*e.b,this.a*e.a):new t(this.r*e,this.g*e,this.b*e,this.a*e)}clamp(){this.r=Math.max(0,Math.min(255,this.r)),this.g=Math.max(0,Math.min(255,this.g)),this.b=Math.max(0,Math.min(255,this.b)),this.a=Math.max(0,Math.min(255,this.a))}};p.Red=new p(255,0,0,255),p.Green=new p(0,255,0,255),p.Blue=new p(0,0,255,255),p.Yellow=new p(255,255,0,255),p.Purple=new p(128,0,128,255),p.Orange=new p(255,165,0,255),p.Pink=new p(255,192,203,255),p.Gray=new p(128,128,128,255),p.Brown=new p(139,69,19,255),p.Cyan=new p(0,255,255,255),p.Magenta=new p(255,0,255,255),p.Lime=new p(192,255,0,255),p.White=new p(255,255,255,255),p.Black=new p(0,0,0,255),p.TRANSPARENT=new p(0,0,0,0);let f=p;const m=class t{constructor(t,e){this.x=void 0!==t?t:0,this.y=void 0!==e?e:0}set(t,e){return Array.isArray(t)?(this.x=t[0],this.y=t[1]):e?(this.x=t,this.y=e):(this.x=t,this.y=t),this}add(e){return new t(this.x+e.x,this.y+e.y)}subtract(e){return new t(this.x-e.x,this.y-e.y)}multiply(e){return e instanceof t?new t(this.x*e.x,this.y*e.y):new t(this.x*e,this.y*e)}divide(e){return e instanceof t?new t(this.x/e.x,this.y/e.y):new t(this.x/e,this.y/e)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}clone(){return new t(this.x,this.y)}copy(t){this.x=t.x,this.y=t.y}equal(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}angle(){return Math.atan2(this.y,this.x)}middle(e){return new t((this.x+e.x)/2,(this.y+e.y)/2)}abs(){return new t(Math.abs(this.x),Math.abs(this.y))}floor(){return new t(Math.floor(this.x),Math.floor(this.y))}ceil(){return new t(Math.ceil(this.x),Math.ceil(this.y))}snap(e){return new t(Math.round(this.x/e)*e,Math.round(this.y/e)*e)}stringify(){return`Vec2(${this.x}, ${this.y})`}static FromArray(e){return e.map((e=>new t(e[0],e[1])))}static fromAngle(e){return new t(Math.cos(e),Math.sin(e))}angleBetween(t){const e=this.dot(t),i=this.length()*t.length(),s=Math.max(-1,Math.min(1,e/i));return Math.acos(s)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}};m.ZERO=new m(0,0),m.ONE=new m(1,1),m.UP=new m(0,1),m.DOWN=new m(0,-1),m.LEFT=new m(-1,0),m.RIGHT=new m(1,0);let g=m;class x{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,i,s){return new g(x.float(t,e),x.float(i,s))}static direction(t){const e=x.angle();return new g(Math.cos(e)*t,Math.sin(e)*t)}static randomColor(t,e){return new f(x.float(t.r,e.r),x.float(t.g,e.g),x.float(t.b,e.b),x.float(t.a,e.a))}static pick(t){return t[x.int(0,t.length-1)]}static pickWeight(t){if(!t||0===t.length)return null;let e=0;for(const r of t)e+=r[1];const i=Math.random()*e;let s=0;for(const r of t)if(s+=r[1],i<=s)return r[0];return t[t.length-1][0]}static scalarOrRange(t,e){if(void 0===t)return e;if(Array.isArray(t)){if("number"==typeof t[0])return x.float(t[0],t[1]);if(t[0]instanceof g)return x.vector(t[0].x,t[1].x,t[0].y,t[1].y);if(t[0]instanceof f)return x.randomColor(t[0],t[1])}return"number"==typeof t?t:t.clone()}}class y{constructor(t){this.render=t}createLightShadowMaskPolygon(t,e,i){const s=[];t.forEach((t=>{for(let e=0;e<t.length;e++){const i=t[e],r=t[(e+1)%t.length];s.push([i,r])}})),i=i||Math.sqrt(Math.pow(this.render.width,2)+Math.pow(this.render.height,2));const r=[];return s.forEach((([t,s])=>{const n=new g(t.x-e.x,t.y-e.y),a=new g(s.x-e.x,s.y-e.y),o=s.subtract(t).perpendicular(),h=Math.abs(o.dot(n))/(o.length()*n.length())+.01,u=Math.abs(o.dot(a))/(o.length()*a.length())+.01,l=i/h,c=i/u,d=new g(n.x,n.y).normalize(),p=new g(a.x,a.y).normalize(),f=new g(t.x+d.x*l,t.y+d.y*l),m=new g(s.x+p.x*c,s.y+p.y*c);r.push([t,s,m,f])})),r}}const T=(t,e,i,s)=>{const r=[],n=s?Math.atan2(e.y,e.x):Math.atan2(-e.y,-e.x),a=Math.PI;for(let o=0;o<10;o++){const e=n+o/10*a,s=n+(o+1)/10*a,h=Math.cos(e)*i,u=Math.sin(e)*i,l=Math.cos(s)*i,c=Math.sin(s)*i;r.push(t),r.push(t.add(new g(h,u))),r.push(t.add(new g(l,c)))}return r},w=t=>{const i=t.points;if(i.length<2)return{vertices:[],uv:[]};const{normals:s,length:r}=((t,e=!1)=>{const i=[];if(t.length<2||e&&t.length<3)return{normals:i,length:0};const s=t.length;let r=0;if(e)for(let a=0;a<s;a++){const e=t[a],i=t[(a+1)%s];r+=e.distanceTo(i)}else for(let a=0;a<s-1;a++)r+=t[a].distanceTo(t[a+1]);const n=(t,e,i)=>{const s=e.subtract(t).normalize(),r=e.subtract(i).normalize(),n=r.dot(s);if(n<-.999)return{normal:s.perpendicular(),miters:1};{let t=r.add(s).normalize();s.cross(r)<0&&(t=t.multiply(-1));let e=1/Math.sqrt((1-n)/2);return{normal:t,miters:Math.min(e,4)}}};if(e){for(let e=0;e<s-1;e++){const r=0===e?t[s-2]:t[e-1],a=t[e],o=t[e+1];i.push(n(r,a,o))}i.push(i[0])}else for(let a=0;a<s;a++)if(0===a){const e=t[1].subtract(t[0]).normalize();i.push({normal:e.perpendicular(),miters:1})}else if(a===s-1){const e=t[a].subtract(t[a-1]).normalize();i.push({normal:e.perpendicular(),miters:1})}else i.push(n(t[a-1],t[a],t[a+1]));return{normals:i,length:r}})(i,t.closed),n=(t.width||1)/2,a=[],o=[],h=t.roundCap||!1,u=t.textureMode||e.STRETCH;let l=0;const c=t.texture?.width||1;for(let d=0;d<i.length-1;d++){const t=i[d],h=s[d].normal,p=s[d].miters,f=t.add(h.multiply(p*n)),m=t.subtract(h.multiply(p*n)),x=i[d+1],y=s[d+1].normal,T=s[d+1].miters,w=x.add(y.multiply(T*n)),b=x.subtract(y.multiply(T*n)),E=t.distanceTo(x);let R=0,v=0;u===e.STRETCH?(R=l/r,v=(l+E)/r):(R=l/c,v=R+E/c);const S=new g(R,0),A=new g(R,1),M=new g(v,0),C=new g(v,1);a.push(f),o.push(S),a.push(m),o.push(A),a.push(w),o.push(M),a.push(w),o.push(M),a.push(b),o.push(C),a.push(m),o.push(A),l+=E}if(h&&!t.closed){const t=i[0],e=s[0].normal,r=T(t,e,n,!0);a.push(...r);const o=i[i.length-1],h=s[i.length-1].normal,u=T(o,h,n,!1);a.push(...u)}return{vertices:a,uv:o}},b="precision mediump float;varying vec2 vRegion;varying vec4 vColor;uniform sampler2D uTexture;uniform int uUseTexture;void main(void){vec4 color;if(uUseTexture>0){color=texture2D(uTexture,vRegion)*vColor;}else{color=vColor;}gl_FragColor=color;}",E="precision mediump float;attribute vec2 aPosition;attribute vec4 aColor;attribute vec2 aRegion;varying vec4 vColor;uniform mat4 uProjectionMatrix;uniform vec4 uColor;varying vec2 vRegion;void main(void){gl_Position=uProjectionMatrix*vec4(aPosition,0.0,1.0);vColor=aColor;vRegion=aRegion;}",R=(t,e,i)=>{const s=t.createShader(i);if(!s)throw new Error("Unable to create webgl shader");t.shaderSource(s,e),t.compileShader(s);if(!t.getShaderParameter(s,t.COMPILE_STATUS)){const i=t.getShaderInfoLog(s);throw console.error("Shader compilation failed:",i),new Error("Unable to compile shader: "+i+e)}return s};function v(t,e,i,s=!1,r=!1,n="clamp"){const a=t.createTexture();if(!a)throw new Error("unable to create texture");let o;switch(t.bindTexture(t.TEXTURE_2D,a),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,i?t.LINEAR:t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i?t.LINEAR:t.NEAREST),n){case"repeat":o=t.REPEAT;break;case"mirror":o=t.MIRRORED_REPEAT;break;default:o=t.CLAMP_TO_EDGE}return t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,o),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,r),s?t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.width,e.height,0,t.RGBA,t.UNSIGNED_BYTE,null):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),a}const S=5126,A="precision mediump float;uniform sampler2D uTextures[%TEXTURE_NUM%];varying vec2 vRegion;varying float vTextureId;varying vec4 vColor;void main(void){vec4 color;%GET_COLOR%gl_FragColor=color*vColor;}",M="precision mediump float;attribute vec2 aPosition;attribute vec2 aRegion;attribute float aTextureId;attribute vec4 aColor;uniform mat4 uProjectionMatrix;varying vec2 vRegion;varying float vTextureId;varying vec4 vColor;void main(void){vRegion=aRegion;vTextureId=aTextureId;vColor=aColor;gl_Position=uProjectionMatrix*vec4(aPosition,0.0,1.0);}",C=[{name:"aPosition",size:2,type:S,stride:24},{name:"aRegion",size:2,type:S,stride:24,offset:2*Float32Array.BYTES_PER_ELEMENT},{name:"aTextureId",size:1,type:S,stride:24,offset:4*Float32Array.BYTES_PER_ELEMENT},{name:"aColor",size:4,type:5121,stride:24,offset:5*Float32Array.BYTES_PER_ELEMENT,normalized:!0}],_=[{name:"aPosition",size:2,type:S,stride:20},{name:"aColor",size:4,type:5121,stride:20,offset:2*Float32Array.BYTES_PER_ELEMENT,normalized:!0},{name:"aRegion",size:2,type:S,stride:20,offset:3*Float32Array.BYTES_PER_ELEMENT}];class P{constructor(t,e,i,s,r=0){this.attributeLoc={},this.uniformLoc={},this.textureUnitNum=0,this.attributes=[];const n=function(t,e){if(t.includes("%TEXTURE_NUM%")&&(t=t.replace("%TEXTURE_NUM%",e.toString())),t.includes("%GET_COLOR%")){let i="";for(let t=0;t<e;t++)i+=0==t?`if(vTextureId == ${t}.0)`:t==e-1?"else":`else if(vTextureId == ${t}.0)`,i+=`{color = texture2D(uTextures[${t}], vRegion);}`;t=t.replace("%GET_COLOR%",i)}return t}(i,t.maxTextureUnits-r);this.program=((t,e,i)=>{var s=t.createProgram(),r=R(t,e,35633),n=R(t,i,35632);if(!s)throw new Error("Unable to create program shader");if(t.attachShader(s,r),t.attachShader(s,n),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS)){const e=t.getProgramInfoLog(s);throw new Error("Unable to link shader program: "+e)}return s})(t.gl,e,n),this.gl=t.gl,this.textureUnitNum=r,this.parseShader(e),this.parseShader(n),s&&this.setAttributes(s)}setUniforms(t,e){const i=this.gl;for(const s of t.getUnifromNames()){const r=this.getUniform(s);t.bind(i,s,r,e)}}getUniform(t){return this.uniformLoc[t]}use(){this.gl.useProgram(this.program)}parseShader(t){const e=this.gl,i=t.match(/attribute\s+\w+\s+(\w+)/g);if(i)for(const r of i){const t=r.split(" ")[2],i=e.getAttribLocation(this.program,t);-1!=i&&(this.attributeLoc[t]=i)}const s=t.match(/uniform\s+\w+\s+(\w+)/g);if(s)for(const r of s){const t=r.split(" ")[2];this.uniformLoc[t]=e.getUniformLocation(this.program,t)}}setAttribute(t){const e=this.attributeLoc[t.name];if(void 0!==e){const i=this.gl;i.vertexAttribPointer(e,t.size,t.type,t.normalized||!1,t.stride,t.offset||0),i.enableVertexAttribArray(e)}}setAttributes(t){this.attributes=t;for(const e of t)this.setAttribute(e)}updateAttributes(){this.setAttributes(this.attributes)}static createCostumShader(t,e,i,s,r=0){let a={[n.SPRITE]:A,[n.GRAPHIC]:b}[s],o={[n.SPRITE]:M,[n.GRAPHIC]:E}[s];const h={[n.SPRITE]:C,[n.GRAPHIC]:_}[s];return a=a.replace("void main(void) {",i+"\nvoid main(void) {"),o=o.replace("void main(void) {",e+"\nvoid main(void) {"),a=a.replace("// fragment","fragment(color);"),o=o.replace(/\/\/ vertex s[\s\S]*?\/\/ vertex e/,"vec2 position = aPosition;\n vertex(position, vRegion);\n gl_Position = uProjectionMatrix * vec4(position, 0.0, 1.0);"),new P(t,o,a,h,r)}}class F{constructor(t){this.usedTextures=[],this.shaders=new Map,this.isCostumShader=!1,this.freeTextureUnitNum=0,this.rapid=t,this.gl=t.gl,this.webglArrayBuffer=new l(t.gl,h.Float32,t.gl.ARRAY_BUFFER,t.gl.STREAM_DRAW),this.maxTextureUnits=t.maxTextureUnits}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},((t,e)=>e))}addVertex(t,e,...i){const[s,r]=this.rapid.matrixStack.apply(t,e);this.webglArrayBuffer.pushFloat32(s),this.webglArrayBuffer.pushFloat32(r)}useTexture(t){const e=this.usedTextures.indexOf(t);return-1==e?(this.usedTextures.push(t),this.freeTextureUnitNum=this.maxTextureUnits-this.usedTextures.length,[this.usedTextures.length-1,!0]):[e,!1]}enterRegion(t){this.currentShader=t??this.getShader("default"),this.currentShader.use(),this.initializeForNextRender(),this.webglArrayBuffer.bindBuffer(),this.currentShader.updateAttributes(),this.updateProjection(),this.isCostumShader=Boolean(t)}updateProjection(){this.gl.uniformMatrix4fv(this.currentShader.uniformLoc.uProjectionMatrix,!1,this.rapid.projection)}isUnifromChanged(t){return!!t&&(this.costumUnifrom!=t||!!t?.isDirty)}setCurrentUniform(t){t.clearDirty(),this.costumUnifrom=t}exitRegion(){}initDefaultShader(t,e,i){this.setShader("default",t,e,i)}setShader(t,e,i,s){this.webglArrayBuffer.bindBuffer(),this.shaders.set(t,new P(this.rapid,e,i,s)),"default"===t&&(this.defaultShader=this.shaders.get(t))}getShader(t){return this.shaders.get(t)}render(){this.executeRender(),this.initializeForNextRender()}executeRender(){const t=this.gl;for(let e=0;e<this.usedTextures.length;e++)t.activeTexture(t.TEXTURE0+e),t.bindTexture(t.TEXTURE_2D,this.usedTextures[e]);this.webglArrayBuffer.bufferData()}initializeForNextRender(){this.webglArrayBuffer.clear(),this.usedTextures.length=0,this.isCostumShader=!1,this.freeTextureUnitNum=this.maxTextureUnits}hasPendingContent(){return!1}isShaderChanged(t){return(t||this.defaultShader)!=this.currentShader}}class U extends F{constructor(t){super(t),this.vertex=0,this.offset=g.ZERO,this.drawType=t.gl.TRIANGLE_FAN,this.setShader("default",E,b,_)}startRender(t,e,i,s){s&&this.currentShader?.setUniforms(s,this),this.offset=new g(t,e),this.vertex=0,this.webglArrayBuffer.clear(),i&&i.base&&(this.texture=this.useTexture(i.base.texture)[0])}addVertex(t,e,i,s,r){this.webglArrayBuffer.resize(3),super.addVertex(t+this.offset.x,e+this.offset.y),this.webglArrayBuffer.pushUint32(r),this.webglArrayBuffer.pushFloat32(i),this.webglArrayBuffer.pushFloat32(s),this.vertex+=1}executeRender(){super.executeRender();const t=this.gl;t.uniform1i(this.currentShader.uniformLoc.uUseTexture,void 0===this.texture?0:1),this.texture&&t.uniform1i(this.currentShader.uniformLoc.uTexture,this.texture),t.drawArrays(this.drawType,0,this.vertex),this.drawType=this.rapid.gl.TRIANGLE_FAN,this.vertex=0,this.texture=void 0}}const N=Math.floor(16384);class L extends d{constructor(t,e){super(t,6,4,e)}addObject(t){super.addObject(),this.pushUint16(t),this.pushUint16(t+1),this.pushUint16(t+2),this.pushUint16(t),this.pushUint16(t+3),this.pushUint16(t+2)}}class D extends F{constructor(t){const e=t.gl;super(t),this.batchSprite=0,this.spriteTextureUnits=[],this.spriteTextureUnitIndexOffset=0,this.setShader("default",M,A,C),this.indexBuffer=new L(e,N)}addVertex(t,e,i,s,r,n){super.addVertex(t,e),this.webglArrayBuffer.pushFloat32(i),this.webglArrayBuffer.pushFloat32(s),this.webglArrayBuffer.pushFloat32(r),this.webglArrayBuffer.pushUint32(n)}renderSprite(t,e,i,s,r,n,a,o,h,u,l,c,d,p=0){(1+p>this.freeTextureUnitNum||this.batchSprite>=N||this.isUnifromChanged(l)||this.rapid.projectionDirty)&&(this.render(),l&&this.isUnifromChanged(l)&&(this.currentShader.setUniforms(l,this),this.setCurrentUniform(l)),this.rapid.projectionDirty&&this.updateProjection()),this.batchSprite++,this.webglArrayBuffer.resize(20);const[f,m]=this.useTexture(t);m&&(this.spriteTextureUnits.push(f),this.spriteTextureUnitIndexOffset=this.spriteTextureUnits[0]);const g=f-this.spriteTextureUnitIndexOffset,x=c?n:s,y=c?s:n,T=d?a:r,w=d?r:a,b=o,E=o+e,R=h,v=h+i;this.addVertex(b,R,x,T,g,u),this.addVertex(E,R,y,T,g,u),this.addVertex(E,v,y,w,g,u),this.addVertex(b,v,x,w,g,u)}executeRender(){if(super.executeRender(),this.batchSprite<=0)return;const t=this.gl;this.spriteTextureUnits.length>0&&this.gl.uniform1iv(this.currentShader.uniformLoc.uTextures,this.spriteTextureUnits),t.drawElements(t.TRIANGLES,6*this.batchSprite,t.UNSIGNED_SHORT,0)}enterRegion(t){super.enterRegion(t),this.indexBuffer.bindBuffer()}initializeForNextRender(){super.initializeForNextRender(),this.batchSprite=0,this.spriteTextureUnits.length=0}hasPendingContent(){return this.batchSprite>0}}class I{constructor(t,e){this.cache=new Map,this.render=t,this.antialias=e}async textureFromUrl(t,e=this.antialias,s=i.CLAMP){let r=this.cache.get(t);if(!r){const i=await this.loadImage(t);r=B.fromImageSource(this.render,i,e,s),r.cacheKey=t,this.cache.set(t,r)}return new k(r)}textureFromFrameBufferObject(t){return new k(t)}textureFromSource(t,e=this.antialias,s=i.CLAMP){let r=this.cache.get(t);return r||(r=B.fromImageSource(this.render,t,e,s),r.cacheKey=t,this.cache.set(t,r)),new k(r)}async loadImage(t){return new Promise((e=>{const i=new Image;i.onload=()=>{e(i)},i.src=t}))}createText(t){return new G(this.render,t)}destroy(t){const e=t instanceof k?t.base:t;e&&(e.destroy(this.render.gl),this.removeCache(e))}createFrameBufferObject(t,e,i=this.antialias){return new z(this.render,t,e,i)}removeCache(t){t.cacheKey&&this.cache.delete(t.cacheKey)}}class B{constructor(t,e,s,r=i.CLAMP){this.cacheKey=null,this.texture=t,this.width=e,this.height=s,this.wrapMode=r}static fromImageSource(t,e,s=!1,r=i.CLAMP){return new B(v(t.gl,e,s,!1,!1,r),e.width,e.height)}destroy(t){t.deleteTexture(this.texture)}}class k{constructor(t){this.scale=1,this.setBaseTexture(t)}setBaseTexture(t){t&&(this.base=t,this.setClipRegion(0,0,t.width,t.height))}setClipRegion(t,e,i,s){if(this.base)return this.clipX=t/this.base.width,this.clipY=e/this.base.height,this.clipW=this.clipX+i/this.base.width,this.clipH=this.clipY+s/this.base.height,this.width=i*this.scale,this.height=s*this.scale,this}static fromImageSource(t,e,i=!1){return new k(B.fromImageSource(t,e,i))}static fromFrameBufferObject(t){return new k(t)}createSpritesheet(t,e){if(!this.base)return[];const i=[],s=Math.floor(this.base.width/t),r=Math.floor(this.base.height/e);for(let n=0;n<r;n++)for(let r=0;r<s;r++){const s=this.clone();s.setClipRegion(r*t,n*e,t,e),i.push(s)}return i}clone(){return new k(this.base)}}const O=2.5;class G extends k{constructor(t,e){super(),this.scale=.4,this.rapid=t,this.options=e,this.text=e.text||" ",this.updateTextImage()}updateTextImage(){this.base&&this.base.destroy(this.rapid.gl);const t=this.createTextCanvas();this.setBaseTexture(B.fromImageSource(this.rapid,t,!0))}createTextCanvas(){const t=document.createElement("canvas"),e=t.getContext("2d");if(!e)throw new Error("Failed to get 2D canvas context");const i=this.options.fontSize||16,s=`${i}px ${this.options.fontFamily||"Arial"}`,r=this.text.split("\n");e.font=s;let n=0;for(const h of r){const t=e.measureText(h);n=Math.max(n,t.width)}const a=i*r.length;t.width=Math.ceil(n)*O,t.height=Math.ceil(a)*O,e.scale(O,O),e.font=s,e.fillStyle=this.options.color?this.options.color.toHexString():"#000",e.textAlign=this.options.textAlign||"left",e.textBaseline=this.options.textBaseline||"top";let o=0;for(const h of r)e.fillText(h,0,o),o+=i;return t}setText(t){this.text!==t&&(this.text=t||" ",this.updateTextImage())}}class z extends B{constructor(t,e,i,s=!1){const r=t.gl,n=v(r,{width:e,height:i},s,!0,!1),a=r.createFramebuffer();if(!a)throw r.deleteTexture(n),new Error("Failed to create WebGL framebuffer");r.bindFramebuffer(r.FRAMEBUFFER,a),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,n,0);const o=r.createRenderbuffer();if(!o)throw r.deleteFramebuffer(a),r.deleteTexture(n),new Error("Failed to create depth-stencil renderbuffer");r.bindRenderbuffer(r.RENDERBUFFER,o),r.renderbufferStorage(r.RENDERBUFFER,r.STENCIL_INDEX8,e,i),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.STENCIL_ATTACHMENT,r.RENDERBUFFER,o),super(n,e,i),this.gl=r,this.framebuffer=a,this.stencilBuffer=o,r.bindTexture(r.TEXTURE_2D,null),r.bindFramebuffer(r.FRAMEBUFFER,null),r.bindRenderbuffer(r.RENDERBUFFER,null)}bind(t){const e=this.gl;e.bindTexture(e.TEXTURE_2D,null),e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.clearColor(t.r,t.g,t.b,t.a),e.clear(e.COLOR_BUFFER_BIT|e.STENCIL_BUFFER_BIT)}unbind(){this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}resize(t,e){if(this.width===t&&this.height===e)return;this.width=t,this.height=e;const i=this.gl;i.bindTexture(i.TEXTURE_2D,this.texture),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,this.stencilBuffer),i.renderbufferStorage(i.RENDERBUFFER,i.STENCIL_INDEX8,t,e),i.bindRenderbuffer(i.RENDERBUFFER,null)}destroy(t){t.deleteFramebuffer(this.framebuffer),t.deleteRenderbuffer(this.stencilBuffer),super.destroy(t)}}function j(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var X,Y={exports:{}};const W=j((X||(X=1,function(t){var e=Object.prototype.hasOwnProperty,i="~";function s(){}function r(t,e,i){this.fn=t,this.context=e,this.once=i||!1}function n(t,e,s,n,a){if("function"!=typeof s)throw new TypeError("The listener must be a function");var o=new r(s,n||t,a),h=i?i+e:e;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],o]:t._events[h].push(o):(t._events[h]=o,t._eventsCount++),t}function a(t,e){0==--t._eventsCount?t._events=new s:delete t._events[e]}function o(){this._events=new s,this._eventsCount=0}Object.create&&(s.prototype=Object.create(null),(new s).__proto__||(i=!1)),o.prototype.eventNames=function(){var t,s,r=[];if(0===this._eventsCount)return r;for(s in t=this._events)e.call(t,s)&&r.push(i?s.slice(1):s);return Object.getOwnPropertySymbols?r.concat(Object.getOwnPropertySymbols(t)):r},o.prototype.listeners=function(t){var e=i?i+t:t,s=this._events[e];if(!s)return[];if(s.fn)return[s.fn];for(var r=0,n=s.length,a=new Array(n);r<n;r++)a[r]=s[r].fn;return a},o.prototype.listenerCount=function(t){var e=i?i+t:t,s=this._events[e];return s?s.fn?1:s.length:0},o.prototype.emit=function(t,e,s,r,n,a){var o=i?i+t:t;if(!this._events[o])return!1;var h,u,l=this._events[o],c=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),c){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,s),!0;case 4:return l.fn.call(l.context,e,s,r),!0;case 5:return l.fn.call(l.context,e,s,r,n),!0;case 6:return l.fn.call(l.context,e,s,r,n,a),!0}for(u=1,h=new Array(c-1);u<c;u++)h[u-1]=arguments[u];l.fn.apply(l.context,h)}else{var d,p=l.length;for(u=0;u<p;u++)switch(l[u].once&&this.removeListener(t,l[u].fn,void 0,!0),c){case 1:l[u].fn.call(l[u].context);break;case 2:l[u].fn.call(l[u].context,e);break;case 3:l[u].fn.call(l[u].context,e,s);break;case 4:l[u].fn.call(l[u].context,e,s,r);break;default:if(!h)for(d=1,h=new Array(c-1);d<c;d++)h[d-1]=arguments[d];l[u].fn.apply(l[u].context,h)}}return!0},o.prototype.on=function(t,e,i){return n(this,t,e,i,!1)},o.prototype.once=function(t,e,i){return n(this,t,e,i,!0)},o.prototype.removeListener=function(t,e,s,r){var n=i?i+t:t;if(!this._events[n])return this;if(!e)return a(this,n),this;var o=this._events[n];if(o.fn)o.fn!==e||r&&!o.once||s&&o.context!==s||a(this,n);else{for(var h=0,u=[],l=o.length;h<l;h++)(o[h].fn!==e||r&&!o[h].once||s&&o[h].context!==s)&&u.push(o[h]);u.length?this._events[n]=1===u.length?u[0]:u:a(this,n)}return this},o.prototype.removeAllListeners=function(t){var e;return t?(e=i?i+t:t,this._events[e]&&a(this,e)):(this._events=new s,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=i,o.EventEmitter=o,t.exports=o}(Y)),Y.exports));class H extends W{constructor(t){super(),this.totalAsset=0,this.loadedAssets=0,this.game=t,this.assets={json:{},audio:{},images:{}}}loadJson(t,e){this.totalAsset++,fetch(e).then((t=>{if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return t.json()})).then((e=>{this.assets.json[t]=e,this.assetLoaded()})).catch((i=>this.handleError(t,e,i)))}async loadAudio(t,e){this.totalAsset++;try{const i=await this.game.audio.audioFromUrl(e);this.assets.audio[t]=i,this.assetLoaded()}catch(i){this.handleError(t,e,i),this.assetLoaded()}}async loadImage(t,e){this.totalAsset++;try{this.assets.images[t]=await this.game.render.texture.textureFromUrl(e),this.assetLoaded()}catch(i){this.handleError(t,e,i),this.assetLoaded()}}loadAssets(t){if(0===t.length)return this.emit("progress",1,0,0),void this.emit("complete",this.assets);t.forEach((t=>{switch(t.type){case"json":this.loadJson(t.name,t.url);break;case"audio":this.loadAudio(t.name,t.url);break;case"image":this.loadImage(t.name,t.url);break;default:console.warn(`Unknown asset type: ${t.type}`)}}))}assetLoaded(){this.loadedAssets++;const t=this.totalAsset>0?this.loadedAssets/this.totalAsset:1;this.emit("progress",t,this.loadedAssets,this.totalAsset),this.loadedAssets>=this.totalAsset&&this.emit("complete",this.assets)}handleError(t,e,i){this.emit("error",{name:t,url:e,error:i}),console.error(`Failed to load asset '${t}' from ${e}:`,i)}get(t,e){return this.assets[t]?.[e]}getJSON(t){return this.assets.json[t]}getAudio(t){return this.assets.audio[t]}getTexture(t){return this.assets.images[t]}}class $ extends W{constructor(t,e){super(),this.sourceNode=null,this._volume=1,this._loop=!1,this._isPlaying=!1,this.audioContext=t,this.audioBuffer=e,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}play(){this.audioContext&&this.audioBuffer&&this.gainNode?(this._isPlaying&&this.stop(),this.sourceNode=this.audioContext.createBufferSource(),this.sourceNode.buffer=this.audioBuffer,this.sourceNode.loop=this._loop,this.sourceNode.connect(this.gainNode),this.sourceNode.onended=()=>{this._isPlaying&&(this._isPlaying=!1,this.sourceNode=null,this.emit("ended"))},this.sourceNode.start(0),this._isPlaying=!0):console.warn("Cannot play audio on a destroyed AudioPlayer.")}stop(){this.sourceNode&&this.sourceNode.stop(),this._isPlaying=!1}get volume(){return this._volume}set volume(t){this._volume=Math.max(0,Math.min(1,t)),this.gainNode&&this.audioContext&&this.gainNode.gain.setTargetAtTime(this._volume,this.audioContext.currentTime,.01)}get loop(){return this._loop}set loop(t){this._loop=t,this.sourceNode&&(this.sourceNode.loop=t)}get isPlaying(){return this._isPlaying}destroy(){this.stop(),this.gainNode&&this.gainNode.disconnect(),this.removeAllListeners(),this.audioBuffer=null,this.audioContext=null,this.gainNode=null,this.sourceNode=null}}class K{constructor(){this.cache=new Map;try{this.audioContext=new(window.AudioContext||window.webkitAudioContext)}catch(t){console.error("Web Audio API is not supported in this browser."),this.audioContext=null}}async audioFromUrl(t){if(!this.audioContext)throw new Error("AudioContext is not available. Cannot process audio.");let e=this.cache.get(t);if(!e){const s=await fetch(t);if(!s.ok)throw new Error(`Failed to fetch audio from ${t}: ${s.statusText}`);const r=await s.arrayBuffer();try{e=await this.audioContext.decodeAudioData(r)}catch(i){throw new Error(`Failed to decode audio from ${t}: ${i}`)}this.cache.set(t,e)}return new $(this.audioContext,e)}destroy(){this.cache.clear(),this.audioContext&&"closed"!==this.audioContext.state&&this.audioContext.close().catch((t=>{console.error("Error closing AudioContext:",t)})),this.audioContext=null}}class q{constructor(t){this.mousePosition=g.ZERO,this.keysDown=new Set,this.keysDownLastFrame=new Set,this.buttonsDown=new Set,this.buttonsDownLastFrame=new Set,this.rapid=t,this.canvas=t.canvas,this.attachEventListeners()}attachEventListeners(){const t=this.canvas.getBoundingClientRect();this.canvas.addEventListener("mousemove",this.handleMouseMove=e=>{this.mousePosition=this.rapid.cssToGameCoords(e.clientX-t.left,e.clientY-t.top)}),window.addEventListener("keydown",this.handleKeyDown=t=>{this.keysDown.add(t.code)}),window.addEventListener("keyup",this.handleKeyUp=t=>{this.keysDown.delete(t.code)}),this.canvas.addEventListener("mousedown",this.handleMouseDown=t=>{this.buttonsDown.add(t.button)}),this.canvas.addEventListener("mouseup",this.handleMouseUp=t=>{this.buttonsDown.delete(t.button)})}updateNextFrame(){this.keysDownLastFrame=new Set(this.keysDown),this.buttonsDownLastFrame=new Set(this.buttonsDown)}isKeyDown(t){return this.keysDown.has(t)}isKeyUp(t){return!this.keysDown.has(t)}wasKeyPressed(t){return this.keysDown.has(t)&&!this.keysDownLastFrame.has(t)}wasKeyReleased(t){return!this.keysDown.has(t)&&this.keysDownLastFrame.has(t)}isButtonDown(t){return this.buttonsDown.has(t)}isButtonUp(t){return!this.buttonsDown.has(t)}wasButtonPressed(t){return this.buttonsDown.has(t)&&!this.buttonsDownLastFrame.has(t)}wasButtonReleased(t){return!this.buttonsDown.has(t)&&this.buttonsDownLastFrame.has(t)}getMouseLocal(t){return t.transform.globalToLocal(this.mousePosition)}getAxis(t,e){let i=0;return this.isKeyDown(e)&&(i+=1),this.isKeyDown(t)&&(i-=1),i}getVector(t,e,i,s){const r=this.getAxis(t,e),n=this.getAxis(i,s);return new g(r,n).normalize()}destroy(){this.canvas.removeEventListener("mousemove",this.handleMouseMove),window.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("keyup",this.handleKeyUp),this.canvas.removeEventListener("mousedown",this.handleMouseDown),this.canvas.removeEventListener("mouseup",this.handleMouseUp),this.keysDown.clear(),this.keysDownLastFrame.clear(),this.buttonsDown.clear(),this.buttonsDownLastFrame.clear()}}class Q extends W{constructor(t,e,i,s,r){super(),this.elapsed=0,this.isRunning=!1,this.isFinished=!1,this.target=t,this.property=e,this.to=i,this.duration=s,this.easing=r}start(){const t=this.target[this.property];if("number"==typeof t)this.from=t;else{if("function"!=typeof t.clone)return console.error("Tween target property is not a 'number' or does not have a 'clone' method."),void(this.isFinished=!0);this.from=t.clone()}this.elapsed=0,this.isRunning=!0,this.isFinished=!1}update(t){if(!this.isRunning||this.isFinished)return;this.elapsed+=t;const e=Math.min(this.elapsed/this.duration,1),i=this.easing(e);let s;if("number"==typeof this.from&&"number"==typeof this.to)s=this.from+(this.to-this.from)*i;else{const t=this.from,e=this.to.subtract(t).multiply(i);s=t.add(e)}this.target[this.property]=s,e>=1&&(this.isFinished=!0,this.isRunning=!1,this.target[this.property]=this.to,this.emit("complete"))}}const V=class{};V.Linear=t=>t,V.EaseInQuad=t=>t*t,V.EaseOutQuad=t=>t*(2-t),V.EaseInOutQuad=t=>t<.5?2*t*t:(4-2*t)*t-1,V.EaseInCubic=t=>t*t*t,V.EaseOutCubic=t=>--t*t*t+1,V.EaseInOutCubic=t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,V.EaseInQuart=t=>t*t*t*t,V.EaseOutQuart=t=>1- --t*t*t*t,V.EaseInOutQuart=t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t;let Z=V;class J extends W{constructor(t,e=!1){super(),this.elapsedTime=0,this.isRunning=!1,this.isFinished=!1,this.duration=t,this.repeat=e}start(){this.isRunning=!0}stop(){this.isRunning=!1}update(t){this.isRunning&&!this.isFinished&&(this.elapsedTime+=t,this.elapsedTime>=this.duration&&(this.emit("timeout"),this.repeat?this.elapsedTime-=this.duration:(this.isFinished=!0,this.isRunning=!1)))}destroy(){this.isFinished=!0,this.isRunning=!1}}class tt{constructor(t,e={}){this.parent=null,this.globalZindex=0,this.localZindex=0,this.transform=new c,this.children=[],this.transform.pushIdentity(),this.game=t,this.rapid=t.render,this.tags=e.tags??[],e.position?this.position=e.position:this.position=new g(e.x??0,e.y??0),"number"==typeof e.scale?this.scale=new g(e.scale,e.scale):e.scale?this.scale=e.scale:this.scale=new g(1,1),this.rotation=e.rotation??0}get x(){return this.position.x}get y(){return this.position.y}set x(t){this.position.x=t}set y(t){this.position.y=t}getScene(){return this.game.getMainScene()}getParentTransform(){return this.parent?this.parent.transform:this.rapid.matrixStack}update(t){this.onUpdate(t);for(const e of this.children)e.update(t)}onUpdate(t){}collectRenderables(t){this.updateTransform(),this.onRender!==tt.prototype.onRender&&t.push(this);for(const e of this.children)e.collectRenderables(t)}beforeOnRender(){const t=this.transform;this.rapid.matrixStack.setTransform(t.getTransform())}onRender(t){}updateTransform(t=!1){t&&this.parent&&this.parent.updateTransform(t);const e=this.transform,i=this.getParentTransform();e.setTransform(i.getTransform()),e.translate(this.position),e.rotate(this.rotation),e.scale(this.scale)}addChild(t){t.parent&&t.parent.removeChild(t),t.parent=this,this.children.push(t)}removeChild(t){const e=this.children.indexOf(t);e>-1&&(t.parent=null,this.children.splice(e,1))}findDescendant(t,e=!0){const i=[];for(const s of this.children){if(t(s)){if(e)return s;i.push(s)}const r=s.findDescendant(t,e);if(e){if(r)return r}else i.push(...r)}return e?null:i}findDescendantByTag(t,e=!1){return this.findDescendant((e=>0!==t.length&&t.every((t=>e.tags.includes(t)))),e)}dispose(){this.postDispose(),this.parent&&this.parent.removeChild(this)}postDispose(){this.children.forEach((t=>{t.dispose()}))}getMouseLocalPosition(){return this.game.input.getMouseLocal(this)}getMouseGlobalPosition(){return this.game.input.mousePosition}}class et{constructor(t,e){this.textures=new Map,this.width=t,this.height=e}setTile(t,e){e instanceof k&&(e={texture:e}),this.textures.set(t,e)}getTile(t){return this.textures.get(t)}}class it{constructor(t){this.rapid=t}getOffset(t){let e=(t.errorX??2)+1,i=(t.errorY??2)+1;if("number"==typeof t.error){const s=(t.error??2)+1;e=s,i=s}else t.error&&(e=t.error.x+1,i=t.error.y+1);return{errorX:e,errorY:i}}getTileData(t,e){const i=e.shape??r.SQUARE,s=t.width,n=i===r.ISOMETRIC?t.height/2:t.height,a=this.rapid.matrixStack,{errorX:o,errorY:h}=this.getOffset(e),u=new g(0,0),l=new g(this.rapid.width,0),c=new g(0,this.rapid.height),d=new g(this.rapid.width,this.rapid.height),p=a.globalToLocal(u),f=a.globalToLocal(l),m=a.globalToLocal(c),x=a.globalToLocal(d),y=Math.min(p.x,f.x,m.x,x.x),T=Math.max(p.x,f.x,m.x,x.x),w=Math.min(p.y,f.y,m.y,x.y),b=Math.max(p.y,f.y,m.y,x.y),E=new g(Math.floor(y/s)-o,Math.floor(w/n)-h),R=new g(Math.ceil(T/s)+o,Math.ceil(b/n)+h);return{startTile:E,viewportWidth:R.x-E.x,viewportHeight:R.y-E.y}}renderLayer(t,e){this.rapid.matrixStack.applyTransform(e);const i=e.tileSet,{startTile:s,viewportWidth:r,viewportHeight:n}=this.getTileData(i,e),a=[];e.ySortCallback&&a.push(...e.ySortCallback);for(let o=0;o<n;o++){const n=o+s.y;if(!(n<0||n>=t.length))for(let o=0;o<r;o++){const r=o+s.x;if(r<0||r>=t[n].length)continue;const h=t[n][r],u=i.getTile(h);if(!u)continue;const l=this.mapToLocal(new g(r,n),e),c=l.y+(u.ySortOffset??0),d=e.eachTile&&e.eachTile(h,r,n)||{};a.push({ySort:c,renderSprite:{...u,x:l.x+(u.x||0),y:l.y+(u.y||0),...d}})}}e.ySortCallback&&e.ySortCallback.length>0&&a.sort(((t,e)=>t.ySort-e.ySort));for(const o of a)o.render?o.render():o.entity?o.entity.onRender(this.rapid):o.renderSprite&&this.rapid.renderSprite(o.renderSprite);this.rapid.matrixStack.applyTransformAfter(e)}localToMap(t,e){const i=e.tileSet;if(e.shape===r.ISOMETRIC){let e=0,s=0;const r=i.height/2,n=i.width/2;let a=Math.floor(t.y/r);const o=a%2==0;let h=Math.floor(t.x/n);const u=h%2==0,l=t.x%n/n,c=t.y%r/r,d=c<l,p=c<1-l;return o||(a-=1),d&&!u&&o?a-=1:d||!u||o?p&&u&&o?(h-=2,a-=1):p||u||o||(a+=1):(a+=1,h-=2),e=h,s=a,e=Math.floor(h/2),new g(e,s)}return new g(Math.floor(t.x/i.width),Math.floor(t.y/i.height))}mapToLocal(t,e){const i=e.tileSet;if(e.shape===r.ISOMETRIC){let e=new g(t.x*i.width,t.y*i.height/2);return t.y%2!=0&&(e.x+=i.width/2),e}return new g(t.x*i.width,t.y*i.height)}}const st=class t extends tt{constructor(e,i){super(e,i),this.error=new g(t.DEFAULT_ERROR),this.data=[[]],this.ySortCallback=[],i.error?"number"==typeof i.error?this.error=new g(i.error):this.error=i.error:this.error=new g(i.errorX??t.DEFAULT_ERROR,i.errorY??t.DEFAULT_ERROR),this.tileSet=i.tileSet,this.shape=i.shape??r.SQUARE,this.eachTile=i.eachTile,this.enableYsort=i.enableYsort??!1}collectRenderables(t){this.enableYsort?this.onRender!==tt.prototype.onRender&&t.push(this):super.collectRenderables(t)}setTile(t,e,i){return e<0||e>=this.data.length||t<0||t>=this.data[e].length?(console.warn(`Tilemap.setTile: Coordinates (${t}, ${e}) are out of bounds.`),!1):(this.data[e][t]=i,!0)}getTile(t,e){if(!(e<0||e>=this.data.length||t<0||t>=this.data[e].length))return this.data[e][t]}removeTile(e,i){return this.setTile(e,i,t.EMPTY_TILE)}fill(t,e,i,s,r){const n=e+s,a=i+r;for(let o=i;o<a;o++)for(let i=e;i<n;i++)this.setTile(i,o,t)}setData(t){this.data=t}localToMap(t){this.rapid.tileMap.localToMap(t,{tileSet:this.tileSet})}mapToLocal(t){this.rapid.tileMap.mapToLocal(t,{tileSet:this.tileSet})}onRender(t){const e=[...this.ySortCallback];this.enableYsort&&this.children.forEach((t=>{e.push({ySort:t.localZindex,entity:t})})),t.renderTileMapLayer(this.data,{error:this.error,tileSet:this.tileSet,eachTile:this.eachTile,ySortCallback:e})}};st.DEFAULT_ERROR=0,st.EMPTY_TILE=-1;class rt{constructor(e){this.projectionDirty=!0,this.matrixStack=new c,this.tileMap=new it(this),this.light=new y(this),this.defaultColor=new f(255,255,255,255),this.regions=new Map,this.currentMaskType=[],this.currentTransform=[],this.currentFBO=[],this.lastTime=0;const i=(t=>{const e={stencil:!0},i=t.getContext("webgl2",e)||t.getContext("webgl",e);if(!i)throw new Error("Unable to initialize WebGL. Your browser may not support it.");return i})(e.canvas);this.gl=i,this.canvas=e.canvas,this.texture=new I(this,e.antialias??!1),this.maxTextureUnits=i.getParameter(this.gl.MAX_TEXTURE_IMAGE_UNITS),this.width=e.width||this.canvas.width,this.height=e.height||this.canvas.height,this.scaleEnable=e.scaleEnable??!1,this.scaleRadio=e.scaleRadio||t.KEEP,this.devicePixelRatio=e.devicePixelRatio??window.devicePixelRatio??1,this.backgroundColor=e.backgroundColor||new f(255,255,255,255),this.registerBuildInRegion(),this.initWebgl(i),this.updateDisplaySize(this.width,this.height),this.projectionDirty=!1,this.canvas.style.display="block"}updateDisplaySize(e,i){const s=this.width,r=this.height;let n,a,o,h;if(this.scaleEnable){const u=s/r,l=e/i;switch(this.scaleRadio){case t.IGNORE:n=s,a=r,o=e*this.devicePixelRatio,h=i*this.devicePixelRatio;break;case t.KEEP:let c,d;n=s,a=r,l>u?(d=i,c=d*u):(c=e,d=c/u),o=c*this.devicePixelRatio,h=d*this.devicePixelRatio;break;case t.EXPAND:l>u?(a=r,n=r*l):(n=s,a=s/l),o=e*this.devicePixelRatio,h=i*this.devicePixelRatio;break;case t.KEEP_W:n=s,a=s/l,o=e*this.devicePixelRatio,h=i*this.devicePixelRatio;break;case t.KEEP_H:a=r,n=r*l,o=e*this.devicePixelRatio,h=i*this.devicePixelRatio;break;default:n=s,a=r,o=e*this.devicePixelRatio,h=i*this.devicePixelRatio}}else n=s,a=r,o=s*this.devicePixelRatio,h=r*this.devicePixelRatio;this.logicWidth=n,this.logicHeight=a,this.physicsWidth=o,this.physicsHeight=h,this.resizeSize(n,a,o,h,!0)}resizeSize(t,e,i,s,r=!1){this.updateProjection(0,t,e,0),this.gl.viewport(0,0,i,s),this.gl.scissor(0,0,i,s),r&&(this.canvas.width=i,this.canvas.height=s,this.canvas.style.width=i/this.devicePixelRatio+"px",this.canvas.style.height=s/this.devicePixelRatio+"px")}updateProjection(t,e,i,s){this.projection=this.createOrthMatrix(t,e,i,s),this.projectionDirty=!0}initWebgl(t){t.enable(t.BLEND),t.disable(t.DEPTH_TEST),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.enable(t.STENCIL_TEST),t.enable(t.SCISSOR_TEST)}clearTextureUnit(){for(let t=0;t<this.maxTextureUnits;t++)this.gl.activeTexture(this.gl.TEXTURE0+t),this.gl.bindTexture(this.gl.TEXTURE_2D,null)}registerBuildInRegion(){this.registerRegion("sprite",D),this.registerRegion("graphic",U)}registerRegion(t,e){this.regions.set(t,new e(this))}quitCurrentRegion(){this.currentRegion&&this.currentRegion.hasPendingContent()&&(this.currentRegion.render(),this.currentRegion.exitRegion())}setRegion(t,e){if(t!=this.currentRegionName||this.currentRegion&&this.currentRegion.isShaderChanged(e)){const i=this.regions.get(t);this.quitCurrentRegion(),this.currentRegion=i,this.currentRegionName=t,i.enterRegion(e)}}save(){this.matrixStack.pushMat()}restore(){this.matrixStack.popMat()}withTransform(t){this.save(),t(),this.restore()}startRender(t=!0){this.clear(),t&&this.matrixStack.clear(),this.matrixStack.pushIdentity(),this.currentRegion=void 0,this.currentRegionName=void 0;const e=performance.now(),i=this.lastTime?(e-this.lastTime)/1e3:0;return this.lastTime=e,i}endRender(){this.currentRegion?.render(),this.projectionDirty=!1}render(t){t(this.startRender()),this.endRender()}renderTileMapLayer(t,e){this.tileMap.renderLayer(t,e instanceof et?{tileSet:e}:e)}renderSprite(t){const e=t.texture;if(!e||!e.base)return;const{offsetX:i,offsetY:s}=this.startDraw(t,e.width,e.height);this.setRegion("sprite",t.shader),this.currentRegion.renderSprite(e.base.texture,e.width,e.height,e.clipX,e.clipY,e.clipW,e.clipH,i,s,(t.color||this.defaultColor).uint32,t.uniforms,t.flipX,t.flipY),this.afterDraw()}renderTexture(t){t.base&&this.renderSprite({texture:t})}renderLine(t){const e=t.closed?[...t.points,t.points[0]]:t.points,{vertices:i,uv:s}=w({...t,points:e});this.renderGraphic({...t,drawType:this.gl.TRIANGLES,points:i,uv:s})}renderGraphic(t){this.startGraphicDraw(t),t.points.forEach(((e,i)=>{const s=Array.isArray(t.color)?t.color[i]:t.color,r=t.uv?.[i];this.addGraphicVertex(e.x,e.y,r,s)})),this.endGraphicDraw()}startGraphicDraw(t){const{offsetX:e,offsetY:i}=this.startDraw(t);this.setRegion("graphic",t.shader);const s=this.currentRegion;s.startRender(e,i,t.texture,t.uniforms),t.drawType&&(s.drawType=t.drawType)}addGraphicVertex(t,e,i,s){this.currentRegion.addVertex(t,e,i?.x,i?.y,(s||this.defaultColor).uint32)}endGraphicDraw(){this.currentRegion.render(),this.afterDraw()}startDraw(t,e=0,i=0){return this.currentTransform.push(t),this.matrixStack.applyTransform(t,e,i)}afterDraw(){this.currentTransform.length>0&&this.matrixStack.applyTransformAfter(this.currentTransform.pop())}renderRect(t){const{width:e,height:i}=t,s=[new g(0,0),new g(e,0),new g(e,i),new g(0,i)];this.renderGraphic({...t,points:s,drawType:this.gl.TRIANGLE_FAN})}renderCircle(t){const e=t.segments||32,i=t.radius,s=t.color||this.defaultColor,r=[];for(let n=0;n<=e;n++){const t=n/e*Math.PI*2,s=Math.cos(t)*i,a=Math.sin(t)*i;r.push(new g(s,a))}this.renderGraphic({...t,points:r,color:s,drawType:this.gl.TRIANGLE_FAN})}clear(t){const e=this.gl,i=t||this.backgroundColor;e.clearColor(i.r/255,i.g/255,i.b/255,i.a/255),e.clear(e.COLOR_BUFFER_BIT),this.clearMask()}createOrthMatrix(t,e,i,s){return new Float32Array([2/(e-t),0,0,0,0,2/(s-i),0,0,0,0,-1,0,-(e+t)/(e-t),-(s+i)/(s-i),0,1])}drawMask(t=s.Include,e){this.startDrawMask(t),e(),this.endDrawMask()}startDrawMask(t=s.Include){const e=this.gl;this.currentMaskType.push(t),this.setMaskType(t,!0),e.stencilOp(e.KEEP,e.KEEP,e.REPLACE),e.colorMask(!1,!1,!1,!1)}endDrawMask(){const t=this.gl;this.quitCurrentRegion(),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),t.colorMask(!0,!0,!0,!0),this.setMaskType(this.currentMaskType.pop()??s.Include,!1)}setMaskType(t,e=!1){const i=this.gl;if(this.quitCurrentRegion(),e)this.clearMask(),i.stencilFunc(i.ALWAYS,1,255);else switch(t){case s.Include:i.stencilFunc(i.EQUAL,1,255);break;case s.Exclude:i.stencilFunc(i.NOTEQUAL,1,255)}}clearMask(){const t=this.gl;this.quitCurrentRegion(),t.clearStencil(0),t.clear(t.STENCIL_BUFFER_BIT),t.stencilFunc(t.ALWAYS,1,255)}createCostumShader(t,e,i,s=0){return P.createCostumShader(this,t,e,i,s)}startFBO(t,e=this.defaultColor){this.quitCurrentRegion(),t.bind(e),this.clearTextureUnit(),this.resizeSize(t.width,t.height,t.width,t.height),this.updateProjection(0,t.width,0,t.height),this.save(),this.matrixStack.identity(),this.currentFBO.push(t)}endFBO(){if(this.currentFBO.length>0){const t=this.currentFBO.pop();this.quitCurrentRegion(),t.unbind(),this.clearTextureUnit(),this.resizeSize(this.logicWidth,this.logicHeight,this.physicsWidth,this.physicsHeight),this.restore()}}drawToFBO(t,e){this.startFBO(t),e(),this.endFBO()}setBlendMode(t){switch(t){case a.Additive:this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE);break;case a.Subtractive:this.gl.blendFunc(this.gl.ZERO,this.gl.ONE_MINUS_SRC_COLOR);break;case a.Mix:this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA)}}drawLightShadowMask(t){this.startDrawMask(t.type||s.Exclude);this.light.createLightShadowMaskPolygon(t.occlusion,t.lightSource,t.baseProjectionLength).forEach((t=>{this.renderGraphic({points:t,color:f.Black})})),this.endDrawMask()}cssToGameCoords(t,e){const i=t instanceof g?t:new g(t,e),s=this.canvas.getBoundingClientRect(),r=i.x/s.width,n=i.y/s.height,a=r*this.logicWidth,o=n*this.logicHeight;return new g(a,o)}gameToCssCoords(t,e){const i=t instanceof g?t:new g(t,e??0),s=this.canvas.getBoundingClientRect(),r=i.x/this.logicWidth,n=i.y/this.logicHeight,a=r*s.width,o=n*s.height;return new g(a,o)}}const nt=!0;class at{constructor(t,e){this.life=0,this.datas={},this.rapid=t,this.options=e,e.texture instanceof k?this.texture=e.texture:e.texture instanceof Array&&e.texture[0]instanceof Array?this.texture=x.pickWeight(e.texture):e.texture instanceof Array&&(this.texture=x.pick(e.texture)),this.maxLife=x.scalarOrRange(e.life,1),this.datas={speed:this.processAttribute(e.animation.speed,0),rotation:this.processAttribute(e.animation.rotation,0),scale:this.processAttribute(e.animation.scale,1),color:this.processAttribute(e.animation.color,f.White),velocity:this.processAttribute(e.animation.velocity,g.ZERO),acceleration:this.processAttribute(e.animation.acceleration,g.ZERO)},this.position=g.ZERO,this.initializePosition()}processAttribute(t,e){if(!t)return{value:e};if("object"==typeof(i=t)&&null!==i&&Object.getPrototypeOf(i)===Object.prototype){const i=t,s=x.scalarOrRange(i.start,e),r=x.scalarOrRange(i.end||s,e);return{delta:i.delta??this.getDelta(s,r,this.maxLife),value:s,damping:i.damping}}return this.processAttribute({start:t},e);var i}updateDamping(t){for(const e of Object.values(this.datas))if(e.damping){const i=e.value,s=Math.pow(e.damping,t);"number"==typeof i?e.value*=s:i.multiply&&(e.value=i.multiply(s))}}updateDelta(t){const e=this.datas;for(const s of Object.values(e))if(s.delta){const e=s.value;"number"==typeof e?s.value+=t*s.delta:e.add&&(s.value=e.add(s.delta.multiply(t)))}e.color.value.clamp(),e.velocity.value=e.velocity.value.add(e.acceleration.value.multiply(t));const i=g.fromAngle(e.rotation.value).multiply(e.speed.value*t);this.position=this.position.add(i).add(e.velocity.value.multiply(t))}getDelta(t,e,i){return 0===i?t:"number"==typeof t&&"number"==typeof e?(e-t)/i:t instanceof g&&e instanceof g||t instanceof f&&e instanceof f?e.subtract(t).divide(i):t}update(t){return this.life+=t,!(this.life>=this.maxLife)&&(this.updateDamping(t),this.updateDelta(t),!0)}render(){const t=this.getPosition();this.rapid.renderSprite({...this.options,position:t,scale:this.datas.scale.value,rotation:this.datas.rotation.value,color:this.datas.color.value,texture:this.texture})}getPosition(){return this.position}initializePosition(){switch(this.options.emitShape){case o.POINT:this.position=g.ZERO;break;case o.CIRCLE:const t=Math.random()*Math.PI*2,e=(this.options.emitRadius||0)*Math.sqrt(Math.random());this.position=new g(Math.cos(t)*e,Math.sin(t)*e);break;case o.RECT:this.position=new g((Math.random()-.5)*(this.options.emitRect?.width||0),(Math.random()-.5)*(this.options.emitRect?.height||0))}!this.options.localSpace&&this.options.position&&(this.position=this.position.add(this.options.position))}}exports.ArrayType=h,exports.BaseTexture=B,exports.BlendMode=a,exports.Camera=class extends tt{constructor(t,e={}){super(t,e),this.enable=!1,this.center=!1,this.positionSmoothingSpeed=0,this.rotationSmoothingSpeed=0,this.center=e.center??!0,this.positionSmoothingSpeed=e.positionSmoothingSpeed??0,this.rotationSmoothingSpeed=e.rotationSmoothingSpeed??0,this._currentRenderPosition=this.position.clone(),this._currentRenderRotation=this.rotation,this.setEnable(e.enable??!1)}setEnable(t){this.enable=t,t?this.game.setMainCamera(this):this.game.mainCamera===this&&this.game.setMainCamera(null)}onUpdate(t){if(this.positionSmoothingSpeed>0){const e=1-Math.exp(-this.positionSmoothingSpeed*t);this._currentRenderPosition.lerp(this.position,e)}else this._currentRenderPosition.copy(this.position);if(this.rotationSmoothingSpeed>0){const e=1-Math.exp(-this.rotationSmoothingSpeed*t);let i=this.rotation-this._currentRenderRotation;for(;i<-Math.PI;)i+=2*Math.PI;for(;i>Math.PI;)i-=2*Math.PI;this._currentRenderRotation+=i*e}else this._currentRenderRotation=this.rotation}updateTransform(){const t=this.getParentTransform(),e=this.transform;e.setTransform(t.getTransform()),e.translate(this._currentRenderPosition),e.rotate(this._currentRenderRotation),e.scale(this.scale);const i=e.getInverse();if(this.center){const t=this.rapid.logicWidth/2,e=this.rapid.logicHeight/2;i[4]=i[0]*t+i[2]*e+i[4],i[5]=i[1]*t+i[3]*e+i[5]}this.transform.setTransform(i)}},exports.CanvasLayer=class extends tt{constructor(t,e){super(t,e)}updateTransform(){this.transform.identity()}},exports.Color=f,exports.DynamicArrayBuffer=u,exports.Entity=tt,exports.FrameBufferObject=z,exports.GLShader=P,exports.Game=class{constructor(t){this.mainScene=null,this.isRunning=!1,this.lastTime=0,this.tweens=[],this.timers=[],this.mainCamera=null,this.renderQueue=[],this.worldTransform=new c,this.render=new rt(t),this.input=new q(this.render),this.asset=new H(this),this.audio=new K,this.texture=this.render.texture}getMainScene(){return this.mainScene}setMainCamera(t){this.mainCamera=t}switchScene(t){this.mainScene&&this.mainScene.dispose(),this.mainScene=t,t.create()}start(){this.isRunning||(this.isRunning=!0,this.lastTime=performance.now(),this.gameLoop())}stop(){this.isRunning=!1}addEntityRenderQueue(t){this.renderQueue.push(t)}gameLoop(){if(!this.isRunning)return;const t=performance.now(),e=(t-this.lastTime)/1e3;this.lastTime=t,this.render.startRender(),this.mainScene&&(this.mainCamera&&this.mainCamera.enable&&this.render.matrixStack.setTransform(this.mainCamera.transform.getTransform()),this.worldTransform.setTransform(this.render.matrixStack.getTransform()),this.mainScene.update(e),this.mainScene.collectRenderables(this.renderQueue),this.renderQueue.sort(((t,e)=>{const i=t.parent&&t.parent===e.parent,s=t.globalZindex-e.globalZindex;return 0!==s?s:i?t.localZindex-e.localZindex:0})),this.renderQueue.forEach((t=>{t.beforeOnRender(),t.onRender(this.render)})),this.renderQueue.length=0),this.render.endRender(),this.input.updateNextFrame(),this.updateTweens(e),this.updateTimers(e),requestAnimationFrame(this.gameLoop.bind(this))}destroy(){this.audio.destroy(),this.input.destroy()}createTimer(t,e=!1){const i=new J(t,e);return this.timers.push(i),i.start(),i}updateTimers(t){for(const e of this.timers)e.update(t);this.timers=this.timers.filter((t=>!t.isFinished))}createTween(t,e,i,s,r=Z.Linear){const n=new Q(t,e,i,s,r);return this.tweens.push(n),n.start(),n}updateTweens(t){for(const e of this.tweens)e.update(t);this.tweens=this.tweens.filter((t=>!t.isFinished))}},exports.InputManager=q,exports.Label=class extends tt{constructor(t,e){super(t,e),this.text=new G(t.render,e)}onRender(t){t.renderSprite({texture:this.text})}setText(t){this.text.setText(t)}},exports.LineTextureMode=e,exports.MaskType=s,exports.MathUtils=class{static deg2rad(t){return t*(Math.PI/180)}static rad2deg(t){return t/(Math.PI/180)}static normalizeDegrees(t){return(t%360+360)%360}},exports.MatrixStack=c,exports.ParticleEmitter=class extends tt{constructor(t,e){super(t,e),this.particles=[],this.emitting=!1,this.emitTimer=0,this.emitRate=10,this.emitTime=0,this.emitTimeCounter=0,this.localSpace=nt,this.options=e,this.emitRate=e.emitRate??10,this.emitTime=e.emitTime??0,this.localSpace=e.localSpace??nt}getTransform(){return this.options}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimer=0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){this.particles=[],this.emitTimer=0,this.emitTimeCounter=0}emit(t){const e=Math.floor(Math.min(t,(this.options.maxParticles||1/0)-this.particles.length));for(let i=0;i<e;i++){const t=this.localSpace?this.position:this.transform.getGlobalPosition(),e=new at(this.rapid,{...this.options,position:t,localSpace:this.localSpace});this.particles.unshift(e)}}onUpdate(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0)for(this.emitTimeCounter+=t;this.emitTimeCounter>=this.emitTime;)this.emit(this.emitRate),this.emitTimeCounter-=this.emitTime;else{this.emitTimer+=t;const e=1/this.emitRate;for(;this.emitTimer>=e;)this.emit(1),this.emitTimer-=e}for(let e=this.particles.length-1;e>=0;e--)this.particles[e].update(t)||this.particles.splice(e,1)}onRender(){if(this.rapid.save(),!this.localSpace){const t=this.game.worldTransform;this.rapid.matrixStack.setTransform(t.getTransform())}for(const t of this.particles)t.render();this.rapid.restore()}getParticleCount(){return this.particles.length}isActive(){return this.emitting||this.particles.length>0}oneShot(){this.emit(this.emitRate)}},exports.ParticleShape=o,exports.Random=x,exports.Rapid=rt,exports.SCALEFACTOR=O,exports.ScaleRadio=t,exports.Scene=class extends tt{create(){}},exports.ShaderType=n,exports.Sprite=class extends tt{constructor(t,e={}){super(t,e),this.animations=new Map,this.currentAnimation=null,this.currentFrame=0,this.frameTimer=0,this.isPlaying=!1,this.texture=e.texture??null,this.flipX=e.flipX??!1,this.flipY=e.flipY??!1,this.color=e.color??f.White,this.offset=e.offset??g.ZERO,e.animations&&this.setAnimations(e.animations)}setAnimations(t){this.animations=new Map(Object.entries(t))}addAnimation(t,e,i=10,s=!0){this.animations.set(t,{name:t,frames:e,fps:i,loop:s})}play(t,e=!1){const i=this.animations.get(t);i?this.currentAnimation!==i||e?(this.currentAnimation=i,this.currentFrame=0,this.frameTimer=0,this.isPlaying=!0,this.texture=this.currentAnimation.frames[this.currentFrame]):this.isPlaying||(this.isPlaying=!0):console.warn(`Animation "${t}" not found.`)}stop(){this.isPlaying=!1}onUpdate(t){if(!this.isPlaying||!this.currentAnimation)return;const e=1/this.currentAnimation.fps;for(this.frameTimer+=t;this.frameTimer>=e;)if(this.frameTimer-=e,this.currentFrame++,this.currentFrame>=this.currentAnimation.frames.length){if(!this.currentAnimation.loop){this.currentFrame=this.currentAnimation.frames.length-1,this.isPlaying=!1;break}this.currentFrame=0}this.texture=this.currentAnimation.frames[this.currentFrame]}onRender(t){this.texture&&t.renderSprite({texture:this.texture,flipX:this.flipX,flipY:this.flipY,offset:this.offset,color:this.color})}},exports.Text=G,exports.Texture=k,exports.TextureCache=I,exports.TextureWrapMode=i,exports.TileMapRender=it,exports.TileSet=et,exports.TilemapShape=r,exports.Uniform=class{constructor(t){this.isDirty=!1,this.data=t}setUniform(t,e){this.data[t]!=e&&(this.isDirty=!0),this.data[t]=e}clearDirty(){this.isDirty=!1}getUnifromNames(){return Object.keys(this.data)}bind(t,e,i,s){if(!i)return;const r=this.data[e];if("number"==typeof r)t.uniform1f(i,r);else if(Array.isArray(r))switch(r.length){case 1:Number.isInteger(r[0])?t.uniform1i(i,r[0]):t.uniform1f(i,r[0]);break;case 2:Number.isInteger(r[0])?t.uniform2iv(i,r):t.uniform2fv(i,r);break;case 3:Number.isInteger(r[0])?t.uniform3iv(i,r):t.uniform3fv(i,r);break;case 4:Number.isInteger(r[0])?t.uniform4iv(i,r):t.uniform4fv(i,r);break;case 9:t.uniformMatrix3fv(i,!1,r);break;case 16:t.uniformMatrix4fv(i,!1,r);break;default:console.error(`Unsupported uniform array length for ${e}:`,r.length)}else if("boolean"==typeof r)t.uniform1i(i,r?1:0);else if(r.base?.texture){const e=s.useTexture(r.base.texture)[0];t.uniform1i(i,e)}else console.error(`Unsupported uniform type for ${e}:`,typeof r)}},exports.Vec2=g,exports.WebglBufferArray=l,exports.WebglElementBufferArray=d,exports.graphicAttributes=_,exports.spriteAttributes=C;
|
package/dist/render.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { ICircleRenderOptions, IGraphicRenderOptions, ILayerRenderOptions, IRapidOptions, IRectRenderOptions, IRenderLineOptions, ISpriteRenderOptions, ShaderType as ShaderType, MaskType, WebGLContext, BlendMode, ILightRenderOptions,
|
|
2
|
-
import { LightManager } from
|
|
3
|
-
import { Color, MatrixStack, Vec2 } from
|
|
4
|
-
import RenderRegion from
|
|
5
|
-
import { FrameBufferObject, Texture, TextureCache } from
|
|
6
|
-
import { TileMapRender, TileSet } from
|
|
7
|
-
import GLShader from
|
|
8
|
-
import { ParticleEmitter } from "./particle";
|
|
1
|
+
import { ICircleRenderOptions, IGraphicRenderOptions, ILayerRenderOptions, IRapidOptions, IRectRenderOptions, IRenderLineOptions, ISpriteRenderOptions, ShaderType as ShaderType, MaskType, WebGLContext, BlendMode, ILightRenderOptions, IPolygonGraphicRenderOptions } from './interface';
|
|
2
|
+
import { LightManager } from './light';
|
|
3
|
+
import { Color, MatrixStack, Vec2 } from './math';
|
|
4
|
+
import { default as RenderRegion } from './regions/region';
|
|
5
|
+
import { FrameBufferObject, Texture, TextureCache } from './texture';
|
|
6
|
+
import { TileMapRender, TileSet } from './tilemap';
|
|
7
|
+
import { default as GLShader } from './webgl/glshader';
|
|
9
8
|
/**
|
|
10
9
|
* The `Rapid` class provides a WebGL-based rendering engine.
|
|
11
10
|
*/
|
|
@@ -115,7 +114,6 @@ declare class Rapid {
|
|
|
115
114
|
* @param options - The rendering options for the sprite, including texture, position, color, and shader.
|
|
116
115
|
*/
|
|
117
116
|
renderSprite(options: ISpriteRenderOptions): void;
|
|
118
|
-
renderParticles(particleEmitter: ParticleEmitter): void;
|
|
119
117
|
/**
|
|
120
118
|
* Renders a texture directly without additional options.
|
|
121
119
|
* This is a convenience method that calls renderSprite with just the texture.
|
|
@@ -222,7 +220,7 @@ declare class Rapid {
|
|
|
222
220
|
* Sets up the FBO for rendering by binding it, adjusting viewport size and projection
|
|
223
221
|
* @param fbo - The Frame Buffer Object to render to
|
|
224
222
|
*/
|
|
225
|
-
startFBO(fbo: FrameBufferObject): void;
|
|
223
|
+
startFBO(fbo: FrameBufferObject, color?: Color): void;
|
|
226
224
|
/**
|
|
227
225
|
* Ends rendering to a Frame Buffer Object
|
|
228
226
|
* Restores the default framebuffer and original viewport settings
|
|
@@ -247,7 +245,6 @@ declare class Rapid {
|
|
|
247
245
|
* @param lightSource - The light source position
|
|
248
246
|
*/
|
|
249
247
|
drawLightShadowMask(options: ILightRenderOptions): void;
|
|
250
|
-
createParticleEmitter(options: IParticleOptions): ParticleEmitter;
|
|
251
248
|
cssToGameCoords(x: number | Vec2, y?: number): Vec2;
|
|
252
249
|
gameToCssCoords(x: number | Vec2, y?: number): Vec2;
|
|
253
250
|
}
|
package/dist/texture.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import Rapid from
|
|
2
|
-
import { Images, ITextTextureOptions, TextureWrapMode, WebGLContext } from
|
|
1
|
+
import { default as Rapid } from './render';
|
|
2
|
+
import { Images, ITextTextureOptions, TextureWrapMode, WebGLContext } from './interface';
|
|
3
|
+
import { Color } from './math';
|
|
3
4
|
/**
|
|
4
5
|
* texture manager
|
|
5
6
|
* @ignore
|
|
@@ -65,6 +66,7 @@ declare class BaseTexture {
|
|
|
65
66
|
width: number;
|
|
66
67
|
height: number;
|
|
67
68
|
wrapMode: TextureWrapMode;
|
|
69
|
+
cacheKey: string | Images | null;
|
|
68
70
|
constructor(texture: WebGLTexture, width: number, height: number, wrapMode?: TextureWrapMode);
|
|
69
71
|
static fromImageSource(r: Rapid, image: Images, antialias?: boolean, wrapMode?: TextureWrapMode): BaseTexture;
|
|
70
72
|
/**
|
|
@@ -117,7 +119,7 @@ declare class Texture {
|
|
|
117
119
|
* @param base
|
|
118
120
|
* @param scale
|
|
119
121
|
*/
|
|
120
|
-
|
|
122
|
+
setBaseTexture(base?: BaseTexture): void;
|
|
121
123
|
/**
|
|
122
124
|
* Sets the region of the texture to be used for rendering.
|
|
123
125
|
* @param x - The x-coordinate of the top-left corner of the region.
|
|
@@ -134,6 +136,7 @@ declare class Texture {
|
|
|
134
136
|
* @returns A new `Texture` instance created from the image source.
|
|
135
137
|
*/
|
|
136
138
|
static fromImageSource(rapid: Rapid, image: Images, antialias?: boolean): Texture;
|
|
139
|
+
static fromFrameBufferObject(fbo: FrameBufferObject): Texture;
|
|
137
140
|
/**
|
|
138
141
|
* Converts the current texture into a spritesheet.
|
|
139
142
|
* @param rapid - The Rapid instance to use.
|
|
@@ -141,7 +144,7 @@ declare class Texture {
|
|
|
141
144
|
* @param spriteHeight - The height of each sprite in the spritesheet.
|
|
142
145
|
* @returns An array of `Texture` instances representing the sprites in the spritesheet.
|
|
143
146
|
*/
|
|
144
|
-
|
|
147
|
+
createSpritesheet(spriteWidth: number, spriteHeight: number): Texture[];
|
|
145
148
|
/**
|
|
146
149
|
* Clone the current texture
|
|
147
150
|
* @returns A new `Texture` instance with the same base texture reference.
|
|
@@ -151,32 +154,25 @@ declare class Texture {
|
|
|
151
154
|
/**
|
|
152
155
|
* @ignore
|
|
153
156
|
*/
|
|
154
|
-
export declare const SCALEFACTOR = 2;
|
|
157
|
+
export declare const SCALEFACTOR = 2.5;
|
|
155
158
|
declare class Text extends Texture {
|
|
156
|
-
private options;
|
|
157
|
-
private rapid;
|
|
159
|
+
private readonly options;
|
|
160
|
+
private readonly rapid;
|
|
158
161
|
protected scale: number;
|
|
159
162
|
text: string;
|
|
160
|
-
/**
|
|
161
|
-
* Creates a new `Text` instance.
|
|
162
|
-
* @param options - The options for rendering the text, such as font, size, color, etc.
|
|
163
|
-
*/
|
|
164
163
|
constructor(rapid: Rapid, options: ITextTextureOptions);
|
|
165
164
|
private updateTextImage;
|
|
166
|
-
/**
|
|
167
|
-
* Creates a canvas element for rendering text.
|
|
168
|
-
* @returns HTMLCanvasElement - The created canvas element.
|
|
169
|
-
*/
|
|
170
165
|
private createTextCanvas;
|
|
171
166
|
/**
|
|
172
|
-
*
|
|
173
|
-
* @param text
|
|
167
|
+
* Updates the displayed text. Re-renders the texture if the text has changed.
|
|
168
|
+
* @param text - The new text to display.
|
|
174
169
|
*/
|
|
175
170
|
setText(text: string): void;
|
|
176
171
|
}
|
|
177
172
|
declare class FrameBufferObject extends BaseTexture {
|
|
178
173
|
private framebuffer;
|
|
179
174
|
private gl;
|
|
175
|
+
private readonly stencilBuffer;
|
|
180
176
|
/**
|
|
181
177
|
* Creates a new FrameBufferObject instance
|
|
182
178
|
* @param render - The Rapid instance to use
|
|
@@ -189,7 +185,7 @@ declare class FrameBufferObject extends BaseTexture {
|
|
|
189
185
|
* Bind the framebuffer for rendering
|
|
190
186
|
* @ignore
|
|
191
187
|
*/
|
|
192
|
-
bind(): void;
|
|
188
|
+
bind(bgColor: Color): void;
|
|
193
189
|
/**
|
|
194
190
|
* Unbind the framebuffer and restore default framebuffer
|
|
195
191
|
* @ignore
|
package/dist/tilemap.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import Rapid from
|
|
2
|
-
import { IRegisterTileOptions, ILayerRenderOptions } from
|
|
3
|
-
import { Texture } from
|
|
4
|
-
import { Vec2 } from
|
|
1
|
+
import { default as Rapid } from './render';
|
|
2
|
+
import { IRegisterTileOptions, ILayerRenderOptions, YSortCallback, TilemapShape, ISpriteRenderOptions, IEntityTilemapLayerOptions } from './interface';
|
|
3
|
+
import { Texture } from './texture';
|
|
4
|
+
import { Vec2 } from './math';
|
|
5
|
+
import { Entity, Game } from './game';
|
|
5
6
|
/**
|
|
6
7
|
* Represents a tileset that manages tile textures and their properties.
|
|
7
8
|
*/
|
|
@@ -41,16 +42,6 @@ export declare class TileMapRender {
|
|
|
41
42
|
* @param rapid - The Rapid rendering instance to use.
|
|
42
43
|
*/
|
|
43
44
|
constructor(rapid: Rapid);
|
|
44
|
-
/**
|
|
45
|
-
* 将需要 y-sort 的回调根据它们的 y 坐标分组到一个 Map 中。
|
|
46
|
-
* 使用 Map 是为了避免因地图坐标过大而创建稀疏数组,从而优化内存使用。
|
|
47
|
-
*
|
|
48
|
-
* @param ySortCallbacks - Array of y-sort callbacks to process.
|
|
49
|
-
* @param height - The effective height of a tile row, used for grouping.
|
|
50
|
-
* @returns A Map where keys are row indices (y) and values are arrays of y-sort callbacks for that row.
|
|
51
|
-
* @private
|
|
52
|
-
*/
|
|
53
|
-
private getYSortRow;
|
|
54
45
|
/**
|
|
55
46
|
* Calculates the error offset values for tile rendering.
|
|
56
47
|
* @param options - Layer rendering options containing error values.
|
|
@@ -58,13 +49,6 @@ export declare class TileMapRender {
|
|
|
58
49
|
* @private
|
|
59
50
|
*/
|
|
60
51
|
private getOffset;
|
|
61
|
-
/**
|
|
62
|
-
* Renders a row of y-sorted entities.
|
|
63
|
-
* @param rapid - The Rapid rendering instance.
|
|
64
|
-
* @param ySortRow - Array of y-sort callbacks to render.
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
private renderYSortRow;
|
|
68
52
|
/**
|
|
69
53
|
* Calculates tile rendering data based on the viewport and tileset.
|
|
70
54
|
* @param tileSet - The tileset to use for rendering.
|
|
@@ -75,10 +59,11 @@ export declare class TileMapRender {
|
|
|
75
59
|
private getTileData;
|
|
76
60
|
/**
|
|
77
61
|
* Renders the tilemap layer based on the provided data and options.
|
|
62
|
+
* This method collects all visible tiles and y-sortable objects into a single queue,
|
|
63
|
+
* sorts them once by their y-coordinate, and then renders them in the correct order.
|
|
78
64
|
*
|
|
79
65
|
* @param data - A 2D array representing the tilemap data.
|
|
80
66
|
* @param options - The rendering options for the tilemap layer.
|
|
81
|
-
* @returns
|
|
82
67
|
*/
|
|
83
68
|
renderLayer(data: (number | string)[][], options: ILayerRenderOptions): void;
|
|
84
69
|
/**
|
|
@@ -96,3 +81,79 @@ export declare class TileMapRender {
|
|
|
96
81
|
*/
|
|
97
82
|
mapToLocal(map: Vec2, options: ILayerRenderOptions): Vec2;
|
|
98
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Tilemap entity for rendering tiled maps.
|
|
86
|
+
*/
|
|
87
|
+
export declare class Tilemap extends Entity {
|
|
88
|
+
static readonly DEFAULT_ERROR = 0;
|
|
89
|
+
static readonly EMPTY_TILE = -1;
|
|
90
|
+
error: Vec2;
|
|
91
|
+
shape: TilemapShape;
|
|
92
|
+
tileSet: TileSet;
|
|
93
|
+
data: (number | string)[][];
|
|
94
|
+
eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
|
|
95
|
+
ySortCallback: YSortCallback[];
|
|
96
|
+
enableYsort: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Creates a tilemap entity.
|
|
99
|
+
* @param game - The game instance this tilemap belongs to.
|
|
100
|
+
* @param options - Configuration options for the tilemap.
|
|
101
|
+
*/
|
|
102
|
+
constructor(game: Game, options: IEntityTilemapLayerOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Collects renderable entities, excluding children unless they override onRender.
|
|
105
|
+
* @param queue - The array to collect renderable entities.
|
|
106
|
+
*/
|
|
107
|
+
collectRenderables(queue: Entity[]): void;
|
|
108
|
+
/**
|
|
109
|
+
* Sets a tile at the specified map coordinates.
|
|
110
|
+
* @param x - The X coordinate (column) on the map.
|
|
111
|
+
* @param y - The Y coordinate (row) on the map.
|
|
112
|
+
* @param tileId - The tile ID to set (number or string).
|
|
113
|
+
* @returns True if the tile was set successfully, false if coordinates are out of bounds.
|
|
114
|
+
*/
|
|
115
|
+
setTile(x: number, y: number, tileId: number | string): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the tile ID at the specified map coordinates.
|
|
118
|
+
* @param x - The X coordinate (column) on the map.
|
|
119
|
+
* @param y - The Y coordinate (row) on the map.
|
|
120
|
+
* @returns The tile ID (number or string) or undefined if coordinates are out of bounds.
|
|
121
|
+
*/
|
|
122
|
+
getTile(x: number, y: number): number | string | undefined;
|
|
123
|
+
/**
|
|
124
|
+
* Removes a tile at the specified map coordinates (sets it to EMPTY_TILE).
|
|
125
|
+
* @param x - The X coordinate (column) on the map.
|
|
126
|
+
* @param y - The Y coordinate (row) on the map.
|
|
127
|
+
* @returns True if the tile was removed successfully, false if coordinates are out of bounds.
|
|
128
|
+
*/
|
|
129
|
+
removeTile(x: number, y: number): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Fills a rectangular area with a specified tile ID.
|
|
132
|
+
* @param tileId - The tile ID to use for filling.
|
|
133
|
+
* @param startX - The starting X coordinate.
|
|
134
|
+
* @param startY - The starting Y coordinate.
|
|
135
|
+
* @param width - The width of the fill area.
|
|
136
|
+
* @param height - The height of the fill area.
|
|
137
|
+
*/
|
|
138
|
+
fill(tileId: number | string, startX: number, startY: number, width: number, height: number): void;
|
|
139
|
+
/**
|
|
140
|
+
* Replaces the entire tilemap data and updates dimensions.
|
|
141
|
+
* @param newData - The new 2D array of tile data.
|
|
142
|
+
*/
|
|
143
|
+
setData(newData: (number | string)[][]): void;
|
|
144
|
+
/**
|
|
145
|
+
* Converts local coordinates to map coordinates.
|
|
146
|
+
* @param local - The local coordinates to convert.
|
|
147
|
+
*/
|
|
148
|
+
localToMap(local: Vec2): void;
|
|
149
|
+
/**
|
|
150
|
+
* Converts map coordinates to local coordinates.
|
|
151
|
+
* @param local - The map coordinates to convert.
|
|
152
|
+
*/
|
|
153
|
+
mapToLocal(local: Vec2): void;
|
|
154
|
+
/**
|
|
155
|
+
* Renders the tilemap layer.
|
|
156
|
+
* @param render - The rendering engine instance.
|
|
157
|
+
*/
|
|
158
|
+
onRender(render: Rapid): void;
|
|
159
|
+
}
|
package/dist/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rapid-render",
|
|
3
|
-
"version": "0.1.21.
|
|
3
|
+
"version": "0.1.21.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
"require": "./dist/rapid.umd.cjs"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
-
"dev
|
|
18
|
-
"
|
|
19
|
-
"dev": "concurrently \"npm run dev:build\" \"npm run dev:serve\"",
|
|
20
|
-
"build": "rollup -c rollup.config.prod.js && tsc",
|
|
17
|
+
"dev": "vite",
|
|
18
|
+
"build": "vite build",
|
|
21
19
|
"docs": "typedoc"
|
|
22
20
|
},
|
|
23
21
|
"devDependencies": {
|
|
@@ -29,13 +27,17 @@
|
|
|
29
27
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
30
28
|
"tslib": "^2.6.2",
|
|
31
29
|
"typedoc-theme-category-nav": "^0.0.3",
|
|
32
|
-
"typescript": "^5.3.3"
|
|
30
|
+
"typescript": "^5.3.3",
|
|
31
|
+
"unplugin-dts": "^1.0.0-beta.0",
|
|
32
|
+
"vite-plugin-dts": "^4.5.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@rollup/plugin-commonjs": "^28.0.6",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
37
37
|
"concurrently": "^9.1.2",
|
|
38
38
|
"eventemitter3": "^5.0.1",
|
|
39
|
-
"typedoc": "^0.28.3"
|
|
39
|
+
"typedoc": "^0.28.3",
|
|
40
|
+
"vite": "^7.1.2",
|
|
41
|
+
"vite-plugin-string": "^1.2.3"
|
|
40
42
|
}
|
|
41
43
|
}
|