UNPKG

jsge

Version:

Javascript Game Engine

1 lines 87.9 kB
var e={d:(t,i)=>{for(var s in i)e.o(i,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:i[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{oX:()=>r,QD:()=>w,T_:()=>qe,uw:()=>ne,xl:()=>i,xP:()=>et,bq:()=>te,P6:()=>s});var i={};e.r(i),e.d(i,{Rectangle:()=>D,Vector:()=>N,Vertex:()=>L});var s={};e.r(s),e.d(s,{angle_2points:()=>ue,angle_3points:()=>de,calculateEllipseVertices:()=>Le,calculateLinesVertices:()=>Me,countClosestTraversal:()=>ce,countClosestTraversal2:()=>he,countDistance:()=>fe,crossProduct:()=>Ee,dotProduct:()=>me,dotProductWithAngle:()=>ge,generateUniqId:()=>Pe,isCircleLineIntersect:()=>ve,isEllipseCircleIntersect:()=>we,isEllipseLineIntersect:()=>ye,isEllipsePolygonIntersect:()=>Ie,isLineShorter:()=>pe,isMobile:()=>ae,isPointCircleIntersect:()=>Se,isPointInsidePolygon:()=>Re,isPointLineIntersect:()=>Te,isPointOnTheLine:()=>_e,isPointPolygonIntersect:()=>xe,isPointRectIntersect:()=>Ae,isPolygonLineIntersect:()=>be,isSafari:()=>oe,mat3Multiply:()=>De,mat3MultiplyPosCoords:()=>Be,mat3MultiplyVector:()=>Ne,pointToCircleDistance:()=>le,randomFromArray:()=>Oe,verticesArrayToArrayNumbers:()=>Ce});const r={MODE:{DEBUG:"DEBUG",PRODUCTION:"PRODUCTION"},AUDIO:{},CONNECTION_STATUS:{DISCONNECTED:"disconnected",CONNECTED:"connected",CONNECTION_LOST:"connection lost"},EVENTS:{SYSTEM:{START_PAGE:"START_PAGE",STOP_PAGE:"STOP_PAGE",RENDER:{START:"start",END:"end"}},WEBSOCKET:{SERVER_CLIENT:{CONNECTION_STATUS_CHANGED:"CONNECTION_STATUS_CHANGED",ROOMS_INFO:"roomsInfo",CREATED:"created",JOINED:"joined",FULL:"full",DISCONNECTED:"disconnected",SERVER_MESSAGE:"message",RESTARTED:"restarted"},CLIENT_SERVER:{ROOMS_INFO_REQUEST:"gatherRoomsInfo",CREATE_OR_JOIN:"create or join",RESTART_REQUEST:"restart",CLIENT_MESSAGE:"message"}}},WEBGL:{DRAW_PROGRAMS:{PRIMITIVES:"drawPrimitives",PRIMITIVES_M:"drawPrimitivesMerge",IMAGES_M:"drawImagesMerge"}},GAME_OPTIONS:{},LIBRARY:{WEBGL:"webgl"},OPTIMIZATION:{CYCLE_TIME_CALC:{AVERAGES:"AVERAGES",CURRENT:"CURRENT"},NATIVE_JS:{NOT_OPTIMIZED:"NOT_OPTIMIZED",OPTIMIZED:"OPTIMIZED"},WEB_ASSEMBLY:{ASSEMBLY_SCRIPT:"ASSEMBLY_SCRIPT",NATIVE_WAT:"WASM"}}},n="rect",a="conus",o="circle",l="polygon",c="line",h="text",u="image",d={STAGE_NOT_EXIST:"STAGE_NOT_EXIST",ELEMENT_NOT_EXIST:"ELEMENT_NOT_EXIST",FILE_NOT_EXIST:"FILE_NOT_EXIST",CANT_GET_THE_IMAGE:"CANT_GET_THE_IMAGE",UNEXPECTED_INPUT_PARAMS:"UNEXPECTED_INPUT_PARAMS",UNHANDLED_EXCEPTION:"UNHANDLED_EXCEPTION",CANVAS_KEY_NOT_SPECIFIED:"CANVAS_KEY_NOT_SPECIFIED",CANVAS_WITH_KEY_NOT_EXIST:"CANVAS_WITH_KEY_NOT_EXIST",WRONG_TYPE_ERROR:"WRONG_TYPE_ERROR",UNEXPECTED_WS_MESSAGE:"UNEXPECTED_WS_MESSAGE",UNEXPECTED_PLAYER_ID:"UNEXPECTED_PLAYER_ID",UNEXPECTED_BULLET_ID:"UNEXPECTED_BULLET_ID",UNEXPECTED_EVENT_NAME:"UNEXPECTED_EVENT_NAME",WEBGL_ERROR:"WEBGL_ERROR",DRAW_PREPARE_ERROR:"DRAW_PREPARE_ERROR",ANOTHER_STAGE_ACTIVE:"ANOTHER_STAGE_ACTIVE",UNEXPECTED_TILE_ID:"UNEXPECTED_TILE_ID",UNEXPECTED_TOUCH_AREA:"UNEXPECTED TOUCH AREA",UNEXPECTED_METHOD_TYPE:"UNEXPECTED METHOD TYPE"},g="NOT_FOUND",m="WORLD_DIMENSIONS_NOT_SET",E="UNHANDLED_DRAW_ISSUE",_="AUDIO_NOT_REGISTERED",f="AUDIO_NOT_LOADED",p="UNKNOWN_DRAW_OBJECT",T="METHOD_NOT_IMPLEMENTED",b="POLYGON_VERTICES_NOT_CORRECT";function x(e,t){throw new Error(e+": "+t)}function R(e,t){console.warn(e,t)}class A{#e;#t=100;#i;#s;#r;#n;#a;constructor(e,t,i=!1,s,r=!1){this.#e=e,this.#i=this.#o(t),this.#s=s||0,this.#r=r,this.#n=i}get name(){return this.#e}get isActive(){return this.#r}get currentSprite(){return this.#i[this.#s][0]}get _isLastSprite(){return this.#i.length-1===this.#s}iterateAnimationIndex(){const e=this.#s;this.#i[e][1]<Date.now()-this.#a&&(this._isLastSprite?this.#n?this.#s=0:this.deactivateAnimation():this.#s++,this.#a=Date.now())}activateAnimation=()=>{this.#r=!0,this.#s=0,this.#a=Date.now()};deactivateAnimation=()=>{this.#r=!1};#o(e){let t=[];return e.forEach(e=>{"number"==typeof e.id&&"number"==typeof e.duration?t.push([e.id,e.duration]):t.push([e,this.#t])}),t}}class S{#l;#c;#h;#u;#d;#g=0;#m=0;#E=[1,1];#_=Pe();#f=!1;#p;#T;#b=!1;constructor(e,t,i,s){this.#l=t,this.#c=i,this.#h=s,this.#u=e}get bgColor(){return this.#h}set bgColor(e){this.#h=e}get type(){return this.#u}get x(){return this.#l}get y(){return this.#c}set x(e){this.#l=e}set y(e){this.#c=e}get sortIndex(){return this.#g}set sortIndex(e){this.#g=e}get blendFunc(){return this.#d}set blendFunc(e){this.#d=e}get rotation(){return this.#m}set rotation(e){this.#m=e}get scale(){return this.#E}set scale(e){"number"==typeof e?this.#E=[e,e]:Array.isArray(e)&&(this.#E=e)}get id(){return this.#_}get isRemoved(){return this.#f}destroy(){this.#f=!0}get isMaskAttached(){return!!this.#p}get _maskId(){return this.#p}setMask(e){e._isMask=!0,this.#p=e.id}removeMask(){this.#p=null}set _isMask(e){this.#T=e}get _isMask(){return this.#T}get isOffsetTurnedOff(){return this.#b}turnOffOffset(){this.#b=!0}_calculateRectVertices=(e,t)=>{const i=e/2,s=t/2;return[[-i,-s],[i,-s],[i,s],[-i,s]]};_interpolateConus(e,t=2*Math.PI,i=Math.PI/14){let s=[0,0];for(let r=0;r<=t;r+=i){let t=Math.cos(r)*e,i=Math.sin(r)*e;s.push(t,i)}return s}_calculateConusBoundaries(e,t=2*Math.PI,i=Math.PI/14){let s=[];for(let r=0;r<=t;r+=i){let t=Math.cos(r)*e,i=Math.sin(r)*e;s.push([t,i])}return s}_convertVerticesArray(e){return void 0!==e[0].x&&void 0!==e[0].y?Ce(e):e}}class v{#x;#R;#A;#S=0;#v=0;#y=0;constructor(e,t){this._initiateStorageData(e,t)}get cells(){return this.#v}get vectors(){return this.#x}get textures(){return this.#R}get _bTempIndexes(){return this.#A}get bufferSize(){return this.#S}_initiateStorageData(e,t){this.#v=e,this.#y=t||e,this.#y>e&&(this.#y=e),this.#S=12*this.#y,this.#x=new Array(this.#S),this.#R=new Array(this.#S),this.#A=new Int32Array(4*this.#v)}}class y{#w;#I;#P;#O;#C="-#-";#M;#L;#D;#N;#B;#p;#g=0;#W=new Map;#b;#f=!1;constructor(e,t,i,s,r,n,a=!1,o){this.#w=e,this.#I=t,this.#P=i,this.#O=s,this.#L=[],this.#M=r,this.#D=n,this.#N=a,this.#B=a||!1,o&&this.setMask(o),this.#F(s,n)}get layerKey(){return this.#w}get tileMapKey(){return this.#I}get tilemap(){return this.#P}get tilesets(){return this.#O}get tilesetImages(){return this.#M}get layerData(){return this.#D}get setBoundaries(){return this.#N}get drawBoundaries(){return this.#B}set drawBoundaries(e){this.#B=e}get isRemoved(){return this.#f}set isRemoved(e){this.#f=e}get _maskId(){return this.#p}setMask(e){e._isMask=!0,this.#p=e.id}removeMask(){this.#p=null}get sortIndex(){return this.#g}set sortIndex(e){this.#g=e}get isOffsetTurnedOff(){return this.#b}turnOffOffset(){this.#b=!0}get hasAnimations(){return this.#W.size>0}get _textureStorages(){return this.#L}_setTextureStorage(e,t){this.#L[e]=t}#F(e,t){let i=0,s=0,r=0;e.forEach((e,n)=>{const a=e.tiles,o=e.name,l=e.firstgid,c=this.tilesets[n+1],h=c?c.firstgid:1e9;if(a)for(let n of a){const a=n.animation,c=n.objectgroup,h=n.id;if(a){const t=o+this.#C+h,i=this.#j(a),s=new A(t,i,!0);this.#W.set(t,s),e._hasAnimations||(e._hasAnimations=!0,e._animations=new Map,e._animations.set(h,i[0][0])),this.#G(s)}c&&this.#N&&(e._hasBoundaries||(e._hasBoundaries=!0,e._boundaries=new Map),e._boundaries.set(h,c),c.objects.forEach(e=>{if(e.ellipse){const e=t.data.filter(e=>e===h+l).length;i+=4*e}else if(e.point){const e=t.data.filter(e=>e===h+l).length;s+=2*e}else if(e.polygon){const i=t.data.filter(e=>e===h+l).length;r+=2*e.polygon.length*i}else{const e=t.data.filter(e=>e===h+l).length;r+=16*e}}))}const u=t.data.filter(e=>e>=l&&e<h).length,d=t.data.length;this.#N&&(r+=16*u),e._temp=new v(d,u)}),t.ellipseBoundariesLen=i,t.pointBoundariesLen=s,t.polygonBoundariesLen=r}#j(e){return e.map(e=>({duration:e.duration,id:e.tileid}))}_processActiveAnimations(){for(let e of this.#W.values())e.isActive&&(e.iterateAnimationIndex(),this.#U(e))}#G=e=>{e.activateAnimation(),this.#U(e)};#U=e=>{const[t,i]=e.name.split(this.#C),s=this.#O.findIndex(e=>e.name===t);this.#O[s]._animations.set(parseInt(i),e.currentSprite)};stopRepeatedAnimation(e){this.#W.get(e).deactivateAnimation()}removeAllAnimations(){for(let[e,t]of this.#W.entries())this.removeEventListener(e,t.activateAnimation),t.deactivateAnimation();this.#W.clear(),this.#W=void 0}destroy(){this.removeAllAnimations(),super.destroy()}}class w extends S{#V;#k;#X;#Y;#z;#W;#H;#K;#Q=0;#Z=0;#q;#J;#$;constructor(e,t,i,s,r,n=0,a,o,l=0,c=0){super(u,e,t),this.#X=r,this.#z=new EventTarget,this.#W=new Map,this.image=o,this.#K=n,this.#Q=l,this.#Z=c,this.#V=i,this.#k=s,this.#q=a&&!a.r?this._convertVerticesArray(a):a&&a.r?this._calculateConusBoundaries(a.r):this._calculateRectVertices(i,s),this.#J=a&&void 0!==a.r?a:null}get width(){return this.#V}get height(){return this.#k}set width(e){this.#V=e}set height(e){this.#k=e}get key(){return this.#X}get image(){return this.#Y}set image(e){this.#$&&(this.#$._isTextureRecalculated=!0),this.#Y=e}get scale(){return super.scale}set scale(e){this.#J?this.#J.r=this.#J.r*e:this.#q=this._calculateRectVertices(this.width*e,this.height*e),super.scale=e}get imageIndex(){return this.#K}set imageIndex(e){this.#K=e}get spacing(){return this.#Q}get margin(){return this.#Z}get hasAnimations(){return this.#W.size>0}get activeAnimation(){return this.#H}get boundaries(){return this.#q}get vertices(){return this.#q}get circleBoundaries(){return this.#J}_processActiveAnimations(){const e=this.#H;if(e){const t=this.#W.get(e);!1===t.isActive?this.#H=null:(t.iterateAnimationIndex(),this.#K=t.currentSprite)}}get _textureStorage(){return this.#$}set _textureStorage(e){this.#$=e}emit(e,...t){const i=new Event(e);i.data=[...t],this.#z.dispatchEvent(i)}addEventListener(e,t,i){this.#z.addEventListener(e,t,i)}removeEventListener(e,t,i){this.#z.removeEventListener(e,t,i)}addAnimation(e,t,i){this.#ee(t)||x(d.UNEXPECTED_INPUT_PARAMS," animationSpriteIndexes should be Array of indexes, or Array of objects {duration:number, id:number}");const s=new A(e,t,i);this.#W.set(e,s),this.addEventListener(e,this.#G)}#ee(e){let t=!0;return e.forEach(e=>{"number"!=typeof e&&("number"==typeof e.duration&&"number"==typeof e.id||(t=!1))}),t}#G=e=>{const t=e.type,i=this.#W.get(t);this.#H&&this.#H!==t&&this.stopRepeatedAnimation(this.#H),i.activateAnimation(),this.#H=t,this.#K=i.currentSprite};stopRepeatedAnimation(e){this.#W.get(e).deactivateAnimation(),this.#H=null}removeAllAnimations(){for(let[e,t]of this.#W.entries())this.removeEventListener(e,t.activateAnimation),t.deactivateAnimation();this.#W.clear(),this.#W=void 0}destroy(){this.removeAllAnimations(),super.destroy()}}class I extends S{#te;#q;constructor(e,t,i,s){super(o,e,t,s),this.#te=i,this.#q=this._interpolateConus(i)}get scale(){return super.scale}set scale(e){this.#q=this._interpolateConus(this.#te*e),super.scale=e}get vertices(){return this.#q}set vertices(e){this.#q=e}get radius(){return this.#te}}class P extends S{#te;#ie;#q;#se;constructor(e,t,i,s,r,n=0){super(a,e,t,s),this.#te=i,this.#ie=r,this.#se=n,this.#q=this._interpolateConus(i,r)}get scale(){return super.scale}set scale(e){this.#q=this._interpolateConus(this.#te*e,this.#ie),super.scale=e}get vertices(){return this.#q}set vertices(e){this.#q=e}get radius(){return this.#te}get angle(){return this.#ie}get fade_min(){return this.#se}set fade_min(e){this.#se=e}}class O extends S{#q;#re=1;constructor(e,t){super(c,e[0][0],e[0][1],t),this.#q=e}get scale(){return super.scale}set scale(e){super.scale=e}get vertices(){return this.#q}set vertices(e){this.#q=e}get lineWidth(){return this.#re}set lineWidth(e){this.#re=e}}class C extends S{#q;constructor(e,t){super(l,e[0].x,e[0].y,t),this.#q=this._convertVerticesArray(e)}get scale(){return super.scale}set scale(e){super.scale=e}get vertices(){return this.#q}set vertices(e){this.#q=e}}class M extends S{#V;#k;#q;constructor(e,t,i,s,r){super(n,e,t,r),this.#V=i,this.#k=s,this.#q=this._calculateRectVertices(i,s)}get scale(){return super.scale}set scale(e){super.scale=e}get vertices(){return this.#q}get width(){return this.#V}get height(){return this.#k}set width(e){this.#V=e}set height(e){this.#k=e}}class L{#l;#c;constructor(e,t){this.#l=e,this.#c=t}get x(){return this.#l}get y(){return this.#c}}class D{#l;#c;#V;#k;constructor(e,t,i,s){this.#l=e,this.#c=t,this.#V=i,this.#k=s}get x(){return this.#l}get y(){return this.#c}get width(){return this.#V}get height(){return this.#k}}class N{#l;#c;constructor(e,t,i,s){this.#l=i-e,this.#c=s-t}get x(){return this.#l}get y(){return this.#c}get length(){return Math.sqrt(Math.pow(this.#l,2)+Math.pow(this.#c,2))}get tetaAngle(){return Math.atan2(this.#c,this.#l)}}class B{#ne;#l;#c;#V;#k;#ae=!1;constructor(e,t){this.#V=e,this.#k=t}get x(){return this.#l}get y(){return this.#c}get width(){return this.#V}get height(){return this.#k}get atlasIndex(){return this.#ne}get isMeasurementsSet(){return this.#ae}_setMeasurements(e,t,i){this.#l=t,this.#c=i,this.#ne=e,this.#ae=!0}}class W extends S{#oe;#le;#ce;#he;#ue;#de;#ge;#me=document.createElement("canvas");#Ee=!1;#_e;constructor(e,t,i,s,r,n,a){super(h,e,t),this.#de=i,this.#oe=s,this.#he=r,this.#ge,this.#fe(n,a)}get boundariesBox(){const e=this._atlasPos.width,t=this._atlasPos.height;return new D(this.x,this.y-t,e,t)}get vertices(){const e=this.boundariesBox;return this._calculateRectVertices(e.width,e.height)}get text(){return this.#de}set text(e){e!==this.#de&&(this.#de=e,this.#fe())}get font(){return this.#oe}set font(e){e!==this.#oe&&(this.#oe=e,this.#fe())}get textAlign(){return this.#le}set textAlign(e){e!==this.#le&&(this.#le=e,this.#fe())}get textBaseline(){return this.#ce}set textBaseline(e){e!==this.#ce&&(this.#ce=e,this.#fe())}get fillStyle(){return this.#he}set fillStyle(e){e!==this.#he&&(this.#he=e,this.#fe())}get strokeStyle(){return this.#ue}set strokeStyle(e){e!==this.#ue&&(this.#ue=e,this.#fe())}get scale(){return super.scale}set scale(e){e!==this.scale&&(super.scale=e,this.#fe())}get textMetrics(){return this.#ge}set _textMetrics(e){this.#ge=e}get _textureCanvas(){return this.#me}get _atlasPos(){return this.#_e}get _isTextureUpdated(){return this.#Ee}_setTextureUpdated(){this.#Ee=!1}#fe(e,t){const i=this._textureCanvas.getContext("2d",{willReadFrequently:!0});if(i){i.font=this.font;const s=i.measureText(this.text);this._atlasPos&&this.#pe(s)?(e=this._atlasPos.width,t=this._atlasPos.height):(e||(e=Math.floor(s.width)),t||(t=Math.floor(s.fontBoundingBoxAscent+s.fontBoundingBoxDescent)),this.#_e=new B(e,t),this._textMetrics=s),i.canvas.width=e,i.canvas.height=t,i.clearRect(0,0,e,t),i.font=this.font,i.textBaseline="bottom",this.fillStyle&&(i.fillStyle=this.fillStyle,i.fillText(this.text,0,t)),this.strokeStyle&&(i.strokeStyle=this.strokeStyle,i.strokeText(this.text,0,t)),this.#Ee=!0}else x(d.UNHANDLED_EXCEPTION,"can't getContext('2d')")}#pe(e){return e.fontBoundingBoxAscent===this.textMetrics.fontBoundingBoxAscent}}class F{#Te;#be;#xe;#Re;#Ae=0;#Se=0;#ve=0;#ye=0;#we=0;#Ie=0;#Pe=0;#Oe=0;#Ce=0;#Me=0;#Le=0;#De;#Ne;#Be;#We;#Fe=[];#je=[];#b;#Ge=!1;#Ue=[];#Ve=!1;constructor(e){}isOffsetTurnedOff(){return this.#b}set mapRotate(e){this.#we=e}#ke(e){this._addBoundaryLine(e.x1,e.y1,e.x2,e.y2)}_addImageDebugBoundaries(e){const t=e.length;for(let i=0;i<t;i++)this.#Ue.push(...e[i])}_enableDebugObjectBoundaries(){this.#Ve=!0}_addBoundariesArray(e){const t=e.length;for(let i=0;i<t;i++){const t=e[i];this._addBoundaryLine(t[0],t[1],t[2],t[3])}}_addBoundaryLine(e,t,i,s){this.#De[this.#Ce]=e,this.#Ce++,this.#De[this.#Ce]=t,this.#Ce++,this.#De[this.#Ce]=i,this.#Ce++,this.#De[this.#Ce]=s,this.#Ce++}_addEllipseBoundary(e,t,i,s){this.#Ne[this.#Le]=e,this.#Le++,this.#Ne[this.#Le]=t,this.#Le++,this.#Ne[this.#Le]=i,this.#Le++,this.#Ne[this.#Le]=s,this.#Le++}_addPointBoundary(e,t){this.#Be[this.#Me]=e,this.#Me++,this.#Be[this.#Me]=t,this.#Me++}_removeBoundaryLine(e){this.#De[e]=0,this.#De[e+1]=0,this.#De[e+2]=0,this.#De[e+3]=0}_clearBoundaries(){this.#De.fill(0),this.#Ne.fill(0),this.#Be.fill(0),this.#Ce=0,this.#Le=0,this.#Me=0,this.#Ve&&(this.#Ue=[])}_initiateBoundariesData(){this.#De=new Float32Array(this.#Ie),this.#Ne=new Float32Array(this.#Pe),this.#Be=new Float32Array(this.#Oe)}_setMaxBoundariesSize(e,t=0,i=0){this.#Ie=e,this.#Pe=t,this.#Oe=i}_setWorldDimensions(e,t){this.#Te=e,this.#be=t}_setCanvasDimensions(e,t){this.#xe=e,this.#Re=t}_setMapBoundaries(){const[e,t]=[this.#Te,this.#be],[i,s]=[this.#Ae,this.#Se],r=e-i,n=t-s;e&&t||R(m,"Can't set map boundaries."),this.#ke({x1:0,y1:0,x2:r,y2:0}),this.#ke({x1:r,y1:0,x2:r,y2:n}),this.#ke({x1:r,y1:n,x2:0,y2:n}),this.#ke({x1:0,y1:n,x2:0,y2:0})}_setWholeWorldMapBoundaries(){const[e,t]=[this.#Te,this.#be];e&&t||R(m,"Can't set map boundaries."),this.#We.push([0,0,e,0]),this.#We.push([e,0,e,t]),this.#We.push([e,t,0,t]),this.#We.push([0,t,0,0])}_mergeBoundaries(e=!1){const t=e?this.getWholeWorldBoundaries():this.getBoundaries(),i=new Set(t);for(const e of i.values()){const t=e[0],s=e[1],r=e[2],n=e[3];for(const a of i.values()){const o=a[0],l=a[1],c=a[2],h=a[3];t===c&&s===h&&r===o&&n===l&&(i.delete(e),i.delete(a)),r!==o||n!==l||t!==c&&s!==h||(a[0]=t,a[1]=s,i.delete(e))}}e?this.#De=Array.from(i):this.#We=Array.from(i),i.clear()}_setWholeMapBoundaries(e){this.#We.push(...e)}_enableMapBoundaries(){this.#Ge=!0}_sortRenderObjectsBySortIndex(){this.#Fe.sort((e,t)=>e.sortIndex-t.sortIndex)}_processPendingRenderObjects(){this.#je.length>0&&(this.#Fe.push(...this.#je),this._sortRenderObjectsBySortIndex(),this.#je=[])}set _renderObject(e){this.#je.push(e)}set _renderObjects(e){e.forEach(e=>{this._renderObject=e})}getBoundaries(){const e=this.#De,t=this.#Ce;let i=[],s=[];for(let r=0;r<t;r++){const t=e[r];i.push(t),(r+1)%4==0&&(s.push(i),i=[])}return s}getRawBoundaries(){return this.#De}getEllipseBoundaries(){return this.#Ne}getPointBoundaries(){return this.#Be}getWholeWorldBoundaries(){return this.#We}getDebugObjectBoundaries(){return this.#Ue}get isWorldBoundariesEnabled(){return this.#Ge}get canvasDimensions(){return[this.#xe,this.#Re]}get worldDimensions(){return[this.#Te,this.#be]}get worldOffset(){return[this.#Ae,this.#Se]}get mapCenter(){return[this.#ve,this.#ye]}get mapRotate(){return this.#we}get boundariesLen(){return this.#Ce}get ellipseBLen(){return this.#Le}get pointBLen(){return this.#Me}centerCameraPosition=(e,t)=>{let[i,s]=this.worldOffset;const[r,n]=this.canvasDimensions,[a,o]=this.worldDimensions,l=r/2,c=n/2,h=c-s;if(l-i<e)if(e<a-l){const t=e-l;t>=0&&(this.#Ae=Math.round(t))}else if(a>r){const e=a-r;this.#Ae=Math.round(e)}if(h<t)if(t<o-c){const e=t-c;e>=0&&(this.#Se=Math.round(e))}else if(o>n){const e=o-n;this.#Se=Math.round(e)}this.#ve=e,this.#ye=t};personRotatedCenterCamera=(e,t,i)=>{console.log("new centering algorithm")};get renderObjects(){return this.#Fe}getObjectsByInstance(e){return this.#Fe.filter(t=>t instanceof e)}cleanUp(){this.#Fe=[],this.#je=[],this._clearBoundaries()}}const j={loadstart:"loadstart",progress:"progress",abort:"abort",error:"error",load:"load",timeout:"timeout"},G=" loader is not registered.",U="Too much recursion. Stop iteration.",V="uploadMethod should be instance of Promise and return upload result value",k=" AtlasXML file extension is incorrect, only .xml file supported",X=" tilemap file extension is not correct, only .tmj, .json, .tmx, .xml files are supported",Y=" fileKey and url should be provided",z="Error loading related tileset ",H="JSON",K="XML",Q="UNKNOWN";class Z{#Xe;#Ye;#ze=new Map;#He=new Map;constructor(e,t){this.#Xe=e,this.#Ye=(e,i,...s)=>{const r=t(e,i,...s);if(r instanceof Promise)return r.then(t=>this.#Ke(t,e));throw new TypeError(V)}}#Ke=(e,t)=>new Promise((i,s)=>{e||null===e||$("AssetsManager: uploadMethod for "+this.#Xe+" returns incorrect value"),this.#Qe(t,e),this.#Ze(t),i()});#Qe(e,t){this.#He.set(e,t)}#Ze(e){this.#ze.delete(e)}get filesWaitingForUpload(){return this.#ze.size}get loadingQueue(){return this.#ze}get uploadMethod(){return this.#Ye}_addFile=(e,t)=>{this.#ze.has(e)&&$("AssetsManager: File "+this.#Xe+" with key "+e+" is already added"),this.#ze.set(e,t)};_isFileInQueue=e=>this.#ze.has(e);_getFile=e=>this.#He.get(e)}class q{#qe=5;#z=new EventTarget;#Je=new Map;#$e=0;constructor(){this.registerLoader("Audio",this._loadAudio),this.registerLoader("Image",this._loadImage),this.registerLoader("TileMap",this._loadTileMap),this.registerLoader("TileSet",this._loadTileSet),this.registerLoader("AtlasImageMap",this._loadAtlasImage),this.registerLoader("AtlasXML",this._loadAtlasXml)}get filesWaitingForUpload(){let e=0;return Array.from(this.#Je.values()).map(t=>e+=t.filesWaitingForUpload),e}registerLoader=(e,t=this._defaultUploadMethod)=>{this["add"+e]=(t,i,...s)=>{this.addFile(e,t,i,...s)},this["get"+e]=t=>this.getFile(e,t),this["is"+e+["InQueue"]]=t=>this.isFileInQueue(e,t);const i=this.#Je.get(e)||new Z(e,t);this.#Je.set(e,i)};preload(){return this.#et(),new Promise(async(e,t)=>{this.#tt().then(()=>{this.#it(),e()}).catch(e=>{t(e)})})}#tt(e=0){return this.#st().then(()=>{if(0===this.filesWaitingForUpload)return Promise.resolve();if(++e>this.#qe){const e=new Error(U);return this.#rt(e),Promise.reject(new Error(U))}return this.#tt(e)})}#st(){return new Promise((e,t)=>{let i=[];Array.from(this.#Je.values()).forEach(e=>{Array.from(e.loadingQueue.entries()).forEach(t=>{const s=new Promise((i,s)=>e.uploadMethod(t[0],...t[1]).then(()=>i()));i.push(s)})}),Promise.allSettled(i).then(i=>{for(const e of i)if("rejected"===e.status){const i=e.reason;this.#nt(i)?t(i):($("AssetsManager: "+i.message),this.#rt(i))}e()})})}addEventListener(e,t,...i){j[e]?this.#z.addEventListener(e,t,...i):$("AssetsManager: Event type should be one of the ProgressEvent.type")}removeEventListener(e,t,...i){this.#z.removeEventListener(e,t,...i)}_loadAtlasXml=(e,t)=>(this.#at(t),fetch(t).then(e=>e.text()).then(e=>(new window.DOMParser).parseFromString(e,"text/xml")).then(i=>{const s=i.documentElement||i.activeElement,r=s.attributes.getNamedItem("imagePath"),n=s.children;if(r){const i=this.#ot(t);return this.addAtlasImageMap(e,i+r.value,n,i),s}{const t=new Error(e+" XML format is not correct.");return this.#rt(t),t}}));_loadAtlasImage=(e,t,i,s="anonymous")=>new Promise((e,r)=>{const n=new Image,a=new Map,o=document.createElement("canvas"),l=o.getContext("2d");n.crossOrigin=s,n.onload=()=>{const t=[];let s=[];o.width=n.width,o.height=n.height,l.drawImage(n,0,0);for(let e of i){const i=e.attributes,r=i.getNamedItem("name").value,n=r.includes(".")?r.split(".")[0]:r,a=i.getNamedItem("x").value,o=i.getNamedItem("y").value,c=i.getNamedItem("width").value,h=i.getNamedItem("height").value;t.push(createImageBitmap(l.getImageData(a,o,c,h),{premultiplyAlpha:"premultiply"})),s.push(n)}this.#lt(),Promise.all(t).then(t=>{t.forEach((e,t)=>{const i=s[t];a.set(i,e),this.addImage(i,"empty url",e)}),o.remove(),e(a)})},n.onerror=()=>{const i=new Error("Error loading atlas image "+t);this.#rt(i),e(null)},n.src=t});_loadTileSet=(e,t,i=1,s)=>{const r=this.#ct(t),n=s?s+t:t;return r===H?fetch(n).then(e=>e.json()).then(e=>this._processTilesetData(e,s,i,t)).catch(()=>{const e=new Error(z+t);return this.#rt(e),Promise.resolve(null)}):r===K?fetch(n).then(e=>e.text()).then(e=>(new window.DOMParser).parseFromString(e,"text/xml")).then(e=>this._processTilesetXmlData(e.documentElement)).then(e=>this._processTilesetData(e,s,i,t)).catch(()=>{const e=new Error(z+t);return this.#rt(e),Promise.resolve(null)}):Promise.reject(n+X)};_processTilesetXmlData=e=>{const t={columns:Number(e.attributes?.columns?.value),name:e.attributes?.name?.value,tilecount:Number(e.attributes?.tilecount?.value),tiledversion:e.attributes?.tiledversion?.value,tileheight:Number(e.attributes?.tileheight?.value),tilewidth:Number(e.attributes?.tilewidth?.value),version:e.attributes?.version?.value,margin:e.attributes?.margin?Number(e.attributes.margin.value):0,spacing:e.attributes?.spacing?Number(e.attributes.margin.value):0,type:e.tagName};return this._processTilesetXmlChildData(t,e.childNodes),t};_processTilesetXmlChildData(e,t){for(let i=0;i<t.length;i++){const s=t[i],r=s.nodeName;if("image"===r)e.image=s?.attributes?.source?.value,e.imagewidth=s?.attributes?.width?Number(s.attributes.width.value):0,e.imageheight=s?.attributes?.height?Number(s.attributes.height.value):0;else if("tileoffset"===r)e.tileoffset={x:Number(s.attributes.x.value),y:Number(s.attributes.y.value)};else if("tile"===r){e.tiles||(e.tiles=[]);const t={id:Number(s.attributes?.id?.value)},i=s.childNodes;for(let e=0;e<i.length;e++){const s=i[e],r=s.nodeName;if("objectgroup"===r){t.objectgroup={type:r},s.attributes?.id&&(t.objectgroup.id=Number(s.attributes?.id?.value)),s.attributes?.draworder&&(t.objectgroup.draworder=s.attributes.draworder.value),s.attributes?.opacity&&(t.objectgroup.opacity=s.attributes.opacity.value),s.attributes?.x&&s.attributes?.y&&(t.objectgroup.x=s.attributes.x.value,t.objectgroup.y=s.attributes.y.value),t.objectgroup.objects=[];const e=s.childNodes;for(let i=0;i<e.length;i++){const s=e[i];if("object"===s.nodeName){const e={id:Number(s.attributes?.id?.value),visible:!s.attributes.visible||"0"!==s.attributes.visible.value,x:Number(s.attributes?.x?.value),y:Number(s.attributes?.y?.value),rotation:s.attributes?.rotation?Number(s.attributes.rotation.value):0};s.attributes?.width&&(e.width=Number(s.attributes.width.value)),s.attributes?.height&&(e.height=Number(s.attributes.height.value));const i=s.childNodes;if(i&&i.length>0)for(let t=0;t<i.length;t++){const s=i[t];if("ellipse"===s.nodeName)e.ellipse=!0;else if("point"===s.nodeName)e.point=!0;else if("polygon"===s.nodeName){const t=s.attributes?.points?.value;if(t&&t.length>0){const i=t.split(" ").map(e=>{const[t,i]=e.split(",");return{x:Number(t),y:Number(i)}});e.polygon=i}}}t.objectgroup.objects.push(e)}}}else if("animation"===r){t.animation=[];const e=s.childNodes;for(let i=0;i<e.length;i++){const s=e[i];if("frame"===s.nodeName){const e={tileid:Number(s.attributes?.tileid?.value),duration:Number(s.attributes?.duration?.value)};t.animation.push(e)}}}}e.tiles.push(t)}}}_processTilesetData=(e,t,i,s)=>{const{name:r,image:n}=e;return r&&n&&!this.isFileInQueue("Image",r)&&this.addImage(r,t?t+n:n),i&&(e.firstgid=i),s&&(e.source=s),Promise.resolve(e)};_defaultUploadMethod=(e,t)=>fetch(t);_loadTileMap=(e,t,i=!0)=>{let s;return s=this.#ht(t)===H?fetch(t).then(e=>e.json()).then(e=>this._processTileMapData(e,t,i)).catch(e=>(e.message.includes("JSON.parse:")&&(e=new Error("Error loading tilemap "+t)),this.#rt(e),Promise.resolve(null))):fetch(t).then(e=>e.text()).then(e=>this._processTileMapXML(e)).then(e=>this._processTileMapData(e,t,i)).catch(e=>(this.#rt(e),Promise.resolve(null))),s};_processTileMapXML=e=>{const t=(new DOMParser).parseFromString(e,"text/xml"),i=t.documentElement,s={type:i.tagName,width:Number(i.attributes?.width?.value),height:Number(i.attributes?.height?.value),infinite:!(!i.attributes.infinite||"1"!==i.attributes.infinite.value),nextlayerid:Number(i.attributes?.nextlayerid?.value),nextobjectid:Number(i.attributes?.nextobjectid?.value),orientation:i.attributes?.orientation?.value,renderorder:i.attributes?.renderorder?.value,tiledversion:i.attributes?.tiledversion?.value,tileheight:Number(i.attributes?.tileheight?.value),tilewidth:Number(i.attributes?.tilewidth?.value),version:i.attributes?.version?.value,tilesets:[],layers:[]},r=t.documentElement.childNodes;for(let e=0;e<r.length;e++){const t=r[e],i=t.nodeName;if("tileset"===i){const e={firstgid:Number(t.attributes?.firstgid?.value)};t.attributes?.source?e.source=t.attributes?.source?.value:(e.columns=Number(t.attributes?.columns?.value),t.attributes?.margin&&(e.margin=Number(t.attributes?.margin?.value)),t.attributes?.spacing&&(e.spacing=t.attributes?.spacing?.value),e.name=t.attributes?.name?.value,e.tilecount=Number(t.attributes?.tilecount?.value),e.tilewidth=Number(t.attributes?.tilewidth?.value),e.tileheight=Number(t.attributes?.tileheight?.value),this._processTilesetXmlChildData(e,t.childNodes)),s.tilesets.push(e)}else if("layer"===i){const e={height:Number(t.attributes?.height?.value),id:Number(t.attributes?.id?.value),name:t.attributes?.name?.value,width:Number(t.attributes?.width?.value),data:t.textContent?t.textContent.trim().split(",").map(e=>Number(e)):null};s.layers.push(e)}}return s};_processTileMapData=(e,t,i)=>{const s=this.#ot(t);if(!0===i&&e.tilesets&&e.tilesets.length>0){const t=[];return e.tilesets.forEach((e,i)=>{const{firstgid:r,source:n}=e;if(n){const e=this._loadTileSet("default-"+r,n,r,s).then(e=>(this.#lt(),Promise.resolve(e)));t.push(e)}else{const i=this._processTilesetData(e,s).then(e=>(this.#lt(),Promise.resolve(e)));t.push(i)}}),Promise.all(t).then(t=>{for(let i=0;i<t.length;i++){const s=t[i];e.tilesets[i]=s,e.tilesets[i].data=Object.assign({},s)}return Promise.resolve(e)})}return Promise.resolve(e)};_loadAudio=(e,t)=>new Promise(e=>{const i=new Audio(t);i.addEventListener("loadeddata",()=>{this.#lt(),e(i)}),i.addEventListener("error",()=>{const i=new Error("Error loading audio "+t);this.#rt(i),e(null)})});_loadImage=(e,t,i,s="anonymous")=>new Promise((e,r)=>{if(i)e(i);else{const i=new Image;i.crossOrigin=s,i.onload=()=>{createImageBitmap(i,{premultiplyAlpha:"premultiply"}).then(t=>{this.#lt(),e(t)})},i.onerror=()=>{const i=new Error("Error loading image "+t);this.#rt(i),e(null)},i.src=t}});#at(e){e.includes(".xml")||J(e+k)}#ct(e){return e.includes(".tsj")||e.includes(".json")?H:e.includes(".tsx")||e.includes(".xml")?K:Q}#ht(e){return e.includes(".tmj")||e.includes(".json")?H:e.includes(".tmx")||e.includes(".xml")?K:Q}#nt(e){return e.message.includes(V)||e.message.includes(k)||e.message.includes(" tileset file extension is not correct, only .tsj, .json, .tsx, .xml files are supported")||e.message.includes(X)||e.message.includes(Y)||e.message.includes(G)}#ot(e){let t=e.split("/"),i=t[t.length-1],s="/";return(i.includes(".tmj")||i.includes(".tmx")||i.includes(".xml")||i.includes(".json"))&&(t.pop(),s=t.join("/")+"/"),s}addFile(e,t,i,...s){const r=this.#Je.get(e);r?(this.#ut(t,i,e),r._addFile(t,[i,...s])):J(e+G)}isFileInQueue(e,t){const i=this.#Je.get(e);if(i)return i._isFileInQueue(t);J("Loader for "+e+" is not registered!")}getFile(e,t){const i=this.#Je.get(e);if(i)return i._getFile(t);J("Loader for "+e+" is not registered!")}#ut(e,t,i){const s=Y;e&&0!==e.trim().length||J("add"+i+"()"+s),t&&0!==t.trim().length||J("add"+i+"()"+s)}#et(){let e=this.filesWaitingForUpload;this.#z.dispatchEvent(new ProgressEvent(j.loadstart,{total:e}))}#it(){this.#z.dispatchEvent(new ProgressEvent(j.load))}#lt(){const e=this.filesWaitingForUpload;this.#$e+=1,this.#z.dispatchEvent(new ProgressEvent(j.progress,{lengthComputable:!0,loaded:this.#$e,total:e}))}#rt(e){$("AssetsManger: "+e.message),this.#z.dispatchEvent(new ErrorEvent(j.error,{error:e}))}}function J(e){throw new Error(e)}function $(e){console.warn(e)}class ee{#dt;#gt;constructor(e){this.#dt=e}get stageData(){return this.#gt}#mt(e){this.#gt._renderObject=e}rect(e,t,i,s,r){const n=new M(e,t,i,s,r);return this.#mt(n),n}text(e,t,i,s,r,n,a){const o=new W(e,t,i,s,r,n,a);return this.#mt(o),o}conus(e,t,i,s,r,n=0){const a=new P(e,t,i,s,r,n);return this.#mt(a),a}circle(e,t,i,s){const r=new I(e,t,i,s);return this.#mt(r),r}image(e,t,i,s,r,n=0,a,o=0,l=0){const c=this.#dt.getImage(r);c||x(d.CANT_GET_THE_IMAGE,"iLoader can't get the image with key: "+r);const h=new w(e,t,i,s,r,n,a,c,o,l);return this.#mt(h),h}line(e,t){void 0===e[0][0]&&console.warn("LINE_VERTICES_NOT_CORRECT","vertices should be a 2 dimensional array");const i=new O(e,t);return this.#mt(i),i}polygon(e,t){const i=new C(e,t);return this.#mt(i),i}tiledLayer(e,t,i,s){const r=this.#dt.getTileMap(t),n=Object.assign({},r.layers.find(t=>t.name===e)),a=Array.from(new Set(n.data.filter(e=>0!==e))).sort((e,t)=>e-t),o=r.tilesets.map(e=>Object.assign({},e)).filter(e=>{const t=e.firstgid,i=t+e.tilecount;return!!a.find(e=>e>=t&&e<i)}),l=o.map(e=>this.#dt.getImage(e.name)),c=new y(e,t,r,o,l,n,i,s);return l.length>1&&R("MULTIPLE_IMAGE_TILESET"," tileset "+e+" includes multiple images, it can case performance issues!"),this.#mt(c),c}_registerNewObjectMethod=(e,t)=>{this[e]=(...e)=>this.#Et(t,...e)};#Et=(e,...t)=>{const i=e(...t);return this.#mt(i),i};_attachPageData=e=>{this.#gt=e};_detachPageData=()=>{this.#gt=null}}const te={mode:r.MODE.DEBUG,gameOptions:{library:r.LIBRARY.WEBGL,optimization:r.OPTIMIZATION.NATIVE_JS.OPTIMIZED,optimizationWASMUrl:"./src/wa/calculateBufferDataWat.wasm",optimizationAssemblyUrl:"/src/wa/calculateBufferDataAssembly.wasm",loadingScreen:{backgroundColor:"rgba(128, 128, 128, 0.6)",loadingBarBg:"rgba(128, 128, 128, 1)",loadingBarProgress:"rgba(128, 128, 128, 0.2)"},render:{cyclesTimeCalc:{check:r.OPTIMIZATION.CYCLE_TIME_CALC.AVERAGES,averageFPStime:1e4},boundaries:{mapBoundariesEnabled:!0,realtimeCalculations:!0,wholeWorldPrecalculations:!1},textAtlasMaxSize:500},debug:{preserveDrawingBuffer:!1,checkWebGlErrors:!1,debugMobileTouch:!1,boundaries:{drawLayerBoundaries:!1,drawObjectBoundaries:!1,boundariesColor:"rgba(224, 12, 21, 0.6)",boundariesWidth:2},delayBetweenObjectRender:!1}},network:{enabled:!1,address:"https://gameserver.reslc.ru:9009",gatherRoomsInfoInterval:5e3},canvasMaxSize:{width:1800,height:1800},worldSize:{width:960,height:960},defaultCanvasKey:"default",customSettings:{}};class ie{static debug(...e){te.mode===r.MODE.DEBUG&&e.forEach(e=>console.log(e))}}class se extends Event{#_t;constructor(e,t){super(e),this.#ft(e)||x(d.UNEXPECTED_EVENT_NAME,", Please check if event is exist"),this.#_t=t}#ft(e){return Object.values(r.EVENTS.WEBSOCKET.SERVER_CLIENT).find(t=>t===e)}get data(){return this.#_t}}class re extends EventTarget{#pt;#Tt;constructor(e){super(),e||x(d.CREATE_INSTANCE_ERROR,"systemSettings should be passed to class instance"),this.#pt=e}init(){const e=this.#pt.network.address;this.#Tt=new WebSocket(e),this.#bt()}get isServerConnected(){return!(!this.#Tt||!this.#Tt.connected)}get playerId(){return this.#Tt.id}sendGatherRoomsInfo(){this.#Tt.emit(r.EVENTS.WEBSOCKET.CLIENT_SERVER.ROOMS_INFO_REQUEST)}sendCreateOrJoinRoom(e,t){this.#Tt.emit(r.EVENTS.WEBSOCKET.CLIENT_SERVER.CREATE_OR_JOIN,e,t)}sendMessage(e){this.#Tt.emit(r.EVENTS.WEBSOCKET.CLIENT_SERVER.CLIENT_MESSAGE,e)}#xt=()=>{ie.debug("connected, socket id: "+this.#Tt.id),this.dispatchEvent(new Event(r.EVENTS.WEBSOCKET.SERVER_CLIENT.CONNECTION_STATUS_CHANGED))};#Rt=e=>{ie.debug("server disconnected, reason: "+e),this.dispatchEvent(new Event(r.EVENTS.WEBSOCKET.SERVER_CLIENT.CONNECTION_STATUS_CHANGED))};#At=e=>{console.warn("server data: ",e)};#St=e=>{ie.debug("received new message from server: "+e),this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.SERVER_MESSAGE,e))};#vt=e=>{ie.debug("received roomsInfo "+e),this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.ROOMS_INFO,e))};#yt=(e,t)=>{ie.debug("CLIENT SOCKET: Created room "+e),this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.CREATED,{room:e,map:t}))};#wt=e=>{ie.debug("CLIENT SOCKET: Room is full, can't join: "+e),this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.FULL,{room:e}))};#It=(e,t)=>{ie.debug("CLIENT SOCKET: Joined to room: "+e,", map: ",t),this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.JOINED,{room:e,map:t}))};#Pt=e=>{this.dispatchEvent(new se(r.EVENTS.WEBSOCKET.SERVER_CLIENT.DISCONNECTED,{playerId:e}))};#bt(){this.#Tt.on("connect",this.#xt),this.#Tt.on("disconnect",this.#Rt),this.#Tt.on("data",this.#At),this.#Tt.on("roomsInfo",this.#vt),this.#Tt.on("created",this.#yt),this.#Tt.on("full",this.#wt),this.#Tt.on("joined",this.#It),this.#Tt.on("log",function(e){console.log.apply(console,e)}),this.#Tt.on("message",this.#St),this.#Tt.on("removed",function(e){console.log("removed message"),console.log(e)}),this.#Tt.on("disconnected",this.#Pt),addEventListener("beforeunload",this.#Ot)}#Ot=()=>{this.#Tt.disconnect()}}class ne{#Ct=.5;#Mt=new Map;#Lt;constructor(e){this.#Lt=e}getAudio=e=>{const t=this.#Mt.get(e);return null===t?(R(f,"Audio with key "+e+" exists, but not actually loaded"),t):t||(R(_,""),null)};getAudioCloned=e=>{const t=this.#Mt.get(e);if(null===t)return R(f,"Audio with key "+e+" exists, but not actually loaded"),t;if(t){const e=t.cloneNode();return e.volume=this.#Ct,e}return R(_),null};set volume(e){this.#Ct=e,this.#Dt(e)}get volume(){return this.#Ct}#Dt(e){for(const t of this.#Mt.values())t&&(t.volume=e)}registerAudio(e){let t=this.#Lt.getAudio(e);this.#Mt.set(e,t)}}function ae(){return/Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent)}function oe(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function le(e,t,i){return new N(e,t,i.x,i.y).length-i.r}function ce(e,t){const i=t.x1,s=t.y1,r=t.x2,n=t.y2,a=e.x1,o=e.y1,l=i,c=s,h=r-i,u=n-s,d=a,g=o,m=e.x2-a,E=e.y2-o,_=Math.sqrt(h*h+u*u),f=Math.sqrt(m*m+E*E);if(h/_==m/f&&u/_==E/f)return null;const p=(h*(g-c)+u*(l-d))/(m*u-E*h),T=(d+m*p-l)/h;return T<0||isNaN(T)||p<0||p>1?null:{x:l+h*T,y:c+u*T,p:T}}function he(e,t){const i=t.x1,s=t.y1,r=t.x2,n=t.y2,a=e.x1,o=e.y1,l=e.x2,c=e.y2,h=(i-r)*(o-c)-(s-n)*(a-l);if(0===h)return;let u=((i*n-s*r)*(a-l)-(i-r)*(a*c-o*l))/h,d=((i*n-s*r)*(o-c)-(s-n)*(a*c-o*l))/h;const g={x:u,y:d};return _e(g,e,1e-13)&&_e(g,t,1e-13)?{x:u,y:d,p:Math.sqrt(Math.pow(u-i,2)+Math.pow(d-s,2))}:void 0}function ue(e,t,i,s){return Math.atan2(s-t,i-e)}function de(e,t,i){const s=e.x-t.x,r=i.x-t.x,n=e.y-t.y,a=i.y-t.y,o=Math.sqrt(s*s+n*n),l=Math.sqrt(r*r+a*a);return Math.acos((s*r+n*a)/(o*l))}function ge(e,t,i){return e*t*Math.cos(i)}function me(e,t){return e.x*t.x+e.y*t.y}function Ee(e,t){return e.x*t.y-t.x*e.y}function _e(e,t,i=0){return(e.x>=t.x1-i&&e.x<=t.x2+i||e.x<=t.x1+i&&e.x>=t.x2-i)&&(e.y>=t.y1-i&&e.y<=t.y2+i||e.y<=t.y1+i&&e.y>=t.y2-i)}function fe(e,t){return new N(e.x,e.y,t.x,t.y).length}function pe(e,t){return new N(e.x1,e.y1,e.x2,e.y2).length<new N(t.x1,t.y1,t.x2,t.y2).length}function Te(e,t){const i=new N(t.x1,t.y1,t.x2,t.y2).length;return new N(t.x1,t.y1,e.x,e.y).length+new N(t.x2,t.y2,e.x,e.y).length<=i+.2}function be(e,t){const i=e.length;for(let s=0;s<i;s+=1){let i=e[s],r=e[s+1];if(!r){if(i[0]===e[0][0]&&i[1]===e[0][1])continue;r=e[0]}const n=he({x1:i[0],y1:i[1],x2:r[0],y2:r[1]},t);if(n)return n}if(e[i-1][0]!==e[0][0]&&e[i-1][1]!==e[0][1]){const s=e[i-1],r=e[0],n=he({x1:s[0],y1:s[1],x2:r[0],y2:r[1]},t);if(n)return n}return null}function xe(e,t,i){const s=i.length;for(let r=0;r<s;r+=1){let s=i[r],n=i[r+1];if(n||(n=i[0]),Te({x:e,y:t},{x1:s[0],y1:s[1],x2:n[0],y2:n[1]}))return!0}return!1}function Re(e,t,i){const s=i.length;let r=0;for(let n=0;n<s;n++){let s=i[n],a=i[n+1]?i[n+1]:i[0],o=s[0],l=s[1],c=a[0],h=a[1];t<l!=t<h&&e<(c-o)*(t-l)/(h-l)+o&&r++}return r>0&&r%2!=0}function Ae(e,t,i){return e>=i.x&&e<=i.width+i.x&&t>=i.y&&t<=i.y+i.height}function Se(e,t,i){const s=i.r;return new N(e,t,i.x,i.y).length<s}function ve(e,t,i,s){const r=s.x1,n=s.y1,a=s.x2,o=s.y2,l={x:r-e,y:n-t},c={x:a-e,y:o-t},h={x:a-r,y:o-n},u={x:r-a,y:n-o},d=Math.sqrt(Math.pow(h.x,2)+Math.pow(h.y,2)),g=me(l,u),m=me(c,h);let E;return g>0&&m>0?(E=Ee(l,c)/d,E<0&&(E*=-1)):E=Math.min(l.length,c.length),E<=i}function ye(e,t){const i=e[0],s=e[1],r=e[2],n=e[3],a={x:i-t[0][0],y:s-t[0][1]},o={x:i-t[1][0],y:s-t[1][1]},l=Math.sqrt(Math.pow(a.x,2)+Math.pow(a.y,2)),c=Math.sqrt(Math.pow(o.x,2)+Math.pow(o.y,2)),h=Math.min(l,c);if(h>Math.max(r,n))return!1;const u=h===l?a:o,d=Math.atan2(u.y,u.x),g={x:0-Math.cos(d)*r,y:0-Math.sin(d)*n};return!(h>Math.sqrt(Math.pow(g.x,2)+Math.pow(g.y,2)))}function we(e,t){const i=e[0],s=e[1],r={x:i-t.x,y:s-t.y},n=Math.sqrt(Math.pow(r.x,2)+Math.pow(r.y,2));if(n>Math.max(e[2],e[3])+t.r)return!1;{const r=ue(i,s,t.x,t.y),a=i-(i+e[2]*Math.cos(r)),o=s-(s+e[3]*Math.sin(r));return n<=Math.sqrt(Math.pow(a,2)+Math.pow(o,2))+t.r&&{x:a,y:o,p:1}}}function Ie(e,t){const i=t.length;for(let s=0;s<i;s+=1){let i=t[s],r=t[s+1];if(r||(r=t[0]),ye(e,[i,r]))return!0}return!1}function Pe(){return Math.round(1e6*Math.random())}function Oe(e){return e[Math.floor(Math.random()*e.length)]}function Ce(e){const t=e.length,i=[];for(let s=0;s<t;s++){const t=e[s];i.push([t.x,t.y])}return i}function Me(e=0,t=0,i,s){const r=s.length;let n=Array(r),a=0;for(let o=0;o<r;o++){const r=s[o];let l=s[o+1];l||(l=s[0]);const c=r[0],h=r[1],u=l[0],d=l[1],g=[c*Math.cos(i)-h*Math.sin(i)+e,c*Math.sin(i)+h*Math.cos(i)+t,u*Math.cos(i)-d*Math.sin(i)+e,u*Math.sin(i)+d*Math.cos(i)+t];n[a]=g,a++}return n}function Le(e=0,t=0,i,s,r=2*Math.PI,n=Math.PI/8){let a=[];for(let o=0;o<=r;o+=n){let r=Math.cos(o)*i+e,n=Math.sin(o)*s+t;a.push([r,n])}return a}function De(e,t){let i=[];for(let s=0;s<9;s+=3){let r=s;for(let n=0;n<3;n++){let a=0,o=n;for(let i=0;i<3;i++)a+=e[s+i]*t[o],o+=3;i[r]=a,r++}}return i}function Ne(e,t){let i=[],s=0;for(let r=0;r<6;r+=3){let n=0;const a=r+3;let o=0;for(let i=r;i<a;i++)n+=e[i]*(t[o]||1),o++;i[s]=n,s++}return i}function Be(e,t){const i=t.length;let s=[],r=0;for(let n=0;n<i;n+=2)for(let i=0;i<6;i+=3){let a=0;const o=i+3;let l=n,c=1;for(let s=i;s<o;s++)a+=e[s]*(3===c?1:t[l]),l++,c++;s[r]=a,r++}return s}class We{#Nt;#Bt;#Wt=!0;constructor(e,t=0){this.#Bt=e,this.#Nt=t}get _isTextureRecalculated(){return this.#Wt}set _isTextureRecalculated(e){this.#Wt=e}get _texture(){return this.#Bt}set _texture(e){this.#Bt=e}get _textureIndex(){return this.#Nt}}class Fe{#Ft;#Y=document.createElement("canvas");#jt=[0,0];#Gt=0;#Ut=0;#Bt;#Nt;#Vt=!1;constructor(e,t,i){this.#Ft=e,this.#Y.width=0,this.#Y.height=0,this.#Bt=t,this.#Nt=i}_isAddPossible(e,t){return this.#Y.width+e<this.#Ft||this.#Y.height+t<this.#Ft}_addNewTextImage(e,t,i){let s,r,[n,a]=this.#jt;const o=document.createElement("canvas");if(o.width=this.#Y.width,o.height=this.#Y.height,n+t<this.#Ft){s=n+t,s>o.width&&(o.width=s),r=a,this.#Gt<i&&(this.#Gt=i),o.height<a+this.#Gt&&(o.height=a+this.#Gt);const l=o.getContext("2d");0===n&&0===a||l.drawImage(this.#Y,0,0),l.drawImage(e,n,a)}else{if(!(a+i<this.#Ft))throw new Error("Overflow error, _isAddingPossible() should be called first");{n=0,this.#Ut+=1,a+=this.#Gt,r=a,this.#Gt=i,o.width<this.#Y.width&&(o.width=this.#Y.width),r+i>o.height&&(o.height=r+i),s=t;const l=o.getContext("2d");l.drawImage(this.#Y,0,0),l.drawImage(e,n,a)}}return this.#Y=o,this._isRecalculated=!0,this.#jt=[s,r],[n,a]}_updateTextImage(e,t){const i=t.x,s=t.y,r=t.width,n=t.height,a=this.#Y.getContext("2d");return a.clearRect(i,s,r,n),a.drawImage(e,i,s),this._isRecalculated=!0,[i,s]}get _atlasImage(){return this.#Y}get _texture(){return this.#Bt}set _texture(e){this.#Bt=e}get _textureIndex(){return this.#Nt}incrementIndex(){this.#Nt++}get _isRecalculated(){return this.#Vt}set _isRecalculated(e){this.#Vt=e}}class je{#kt;#Xt;#Yt;#zt;#Ht;#Lt;#Kt;#Qt;#Zt=null;#qt=null;#Jt=[];#$t=0;#ei=new Map;#ti=new Map;#ii=new Map;#si;constructor(e,t,i){e&&e instanceof WebGLRenderingContext||x(d.UNEXPECTED_INPUT_PARAMS," context parameter should be specified and equal to WebGLRenderingContext"),this.#kt=e,this.#Ht=t,this.#Lt=i,this.#zt=t.debug.checkWebGlErrors,this.#Xt=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.#Yt=e.getParameter(e.MAX_TEXTURE_SIZE),this.#Kt=e.createBuffer(),this.#Qt=e.createBuffer(),this.#Jt[0]=new Fe(t.render.textAtlasMaxSize,this.#kt.createTexture(),0),this._registerObjectRender(W.name,this._bindText,r.WEBGL.DRAW_PROGRAMS.IMAGES_M),this._registerObjectRender(M.name,this._bindPrimitives,r.WEBGL.DRAW_PROGRAMS.PRIMITIVES_M),this._registerObjectRender(C.name,this._bindPrimitives,r.WEBGL.DRAW_PROGRAMS.PRIMITIVES_M),this._registerObjectRender(I.name,this._bindConus,r.WEBGL.DRAW_PROGRAMS.PRIMITIVES),this._registerObjectRender(P.name,this._bindConus,r.WEBGL.DRAW_PROGRAMS.PRIMITIVES),this._registerObjectRender(O.name,this._bindPrimitives,r.WEBGL.DRAW_PROGRAMS.PRIMITIVES_M),this._registerObjectRender(y.name,this._bindTileImages,r.WEBGL.DRAW_PROGRAMS.IMAGES_M),this._registerObjectRender(u,this._bindImage,r.WEBGL.DRAW_PROGRAMS.IMAGES_M)}getProgram(e){return this.#ei.get(e)}getProgramVarLocations(e){return this.#ti.get(e)}_fixCanvasSize(e,t){this.#kt.viewport(0,0,e,t)}_initiateJsRender=e=>new Promise((t,i)=>{const s=e.getObjectsByInstance(y),[r,n]=e.worldDimensions;let a=0,o=0,l=0,c=0,h=0;s.forEach(e=>{const t=e.setBoundaries,i=e.layerData,s=e.tilemap,r=e.tilesets,{tileheight:n,tilewidth:u}=s,d=u,g=n;for(let e=0;e<r.length;e++){const e=d*i.width,s=g*i.height,r=i.polygonBoundariesLen,n=i.ellipseBoundariesLen,u=i.pointBoundariesLen;c<e&&(c=e),h<s&&(h=s),t&&(a+=r,o+=n,l+=u)}}),0===c||0===h||c===r&&h===n||(R("UNEXPECTED_WORLD_SIZE"," World size from tilemap is different than settings one, fixing..."),e._setWorldDimensions(c,h)),this.#Ht.render.boundaries.mapBoundariesEnabled&&(a+=16),e._setMaxBoundariesSize(a,o,l),e._initiateBoundariesData(),t(!0)});_initWebGlAttributes=()=>{const e=this.#kt;return e.enable(e.BLEND),e.enable(e.STENCIL_TEST),e.stencilFunc(e.ALWAYS,1,255),e.stencilOp(e.KEEP,e.KEEP,e.REPLACE),Promise.resolve()};_initiateWasm=e=>{const t=this.#Ht.optimization===r.OPTIMIZATION.WEB_ASSEMBLY.NATIVE_WAT?this.#Ht.optimizationWASMUrl:this.#Ht.optimizationAssemblyUrl;return new Promise((e,i)=>{this.layerData=new WebAssembly.Memory({initial:1e3}),this.layerDataFloat32=new Float32Array(this.layerData.buffer);const s={env:{memory:this.layerData,logi:console.log,logf:console.log}};fetch(t).then(e=>e.arrayBuffer()).then(e=>WebAssembly.instantiate(e,s)).then(t=>{this.calculateBufferData=t.instance.exports.calculateBufferData,e()})})};_initDrawCallsDebug(e){this.#si=e}_clearView(){const e=this.#kt;this.#si.cleanupDebugInfo(),e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT)}_render(e,t,i=0){return this.#kt.drawArrays(t,i,e),Promise.resolve(e)}_preRender(){return new Promise((e,t)=>{const i=this.#kt;if(this.#zt){const e=this.#zt?i.getError():0;if(0!==e)throw console.error(e),new Error("Error num: "+e)}else e()})}_postRender(e){let t=e;if(Array.isArray(t)){const[i,s]=e;this.#kt.drawArrays(s,0,i),t=i}return new Promise((e,i)=>{const s=this.#kt;0!==t&&(this.#si.incrementDrawCallsCounter(),this.#si.verticesDraw=t),s.stencilFunc(s.ALWAYS,1,255),this.#Ht.debug.delayBetweenObjectRender?setTimeout(()=>{e()},1e3):e()})}_registerAndCompileWebGlProgram(e,t,i,s,r){const n=this.#ri(t,i),a=this.#ni(n,s,r);return this.#ei.set(e,n),this.#ti.set(e,a),Promise.resolve()}#ri(e,t){const i=this.#kt,s=i.createProgram();if(s){const r=this.#ai(i,e,i.VERTEX_SHADER);r?i.attachShader(s,r):x(d.WEBGL_ERROR,"#compileShader(vertexShaderSource) is null");const n=this.#ai(i,t,i.FRAGMENT_SHADER);if(n?i.attachShader(s,n):x(d.WEBGL_ERROR,"#compileShader(fragmentShaderSource) is null"),i.linkProgram(s),!i.getProgramParameter(s,i.LINK_STATUS)){const e=i.getProgramInfoLog(s);x(d.WEBGL_ERROR,`Could not compile WebGL program. \n\n${e}`)}}else x(d.WEBGL_ERROR,"gl.createProgram() is null");return s}#ni(e,t,i){const s=this.#kt;let r={};return t.forEach(t=>{r[t]=s.getUniformLocation(e,t)}),i.forEach(t=>{r[t]=s.getAttribLocation(e,t)}),r}#ai(e,t,i){const s=e.createShader(i);if(s){if(e.shaderSource(s,t),e.compileShader(s),!e.getShaderParameter(s,e.COMPILE_STATUS)){const t=e.getShaderInfoLog(s);x(d.WEBGL_ERROR,"Couldn't compile webGl program. \n\n"+t)}}else x(d.WEBGL_ERROR,`gl.createShader(${i}) is null`);return s}_bindPrimitives=(e,t,i,s,r)=>{const[a,h]=!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset,u=e.x-a,d=e.y-h,g=e.scale,m=e.blendFunc?e.blendFunc:[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA],{u_resolution:E,u_color:_,a_position:f,u_fade_min:p}=r;let T=[];switch(e.type){case n:const t=0,i=0+e.width,s=0,r=0+e.height;T=[t,s,i,s,t,r,t,r,i,s,i,r];break;case o:T=e.vertices;break;case l:const a=this.#oi(e.vertices);if(T=a,a.length%3!=0)return R(b,`polygons ${e.id}, vertices are not correct, skip drawing`),Promise.reject();break;case c:const h=e.vertices,u=e.lineWidth/2;for(let e=0;e<h.length-1;e+=1){const t=h[e][0],i=h[e][1],s=h[e+1][0],r=h[e+1][1],n=s-t,a=r-i,o=Math.sqrt(n*n+a*a);if(0===o)continue;const l=-a/o*u,c=n/o*u,d=t+l,g=i+c,m=t-l,E=i-c,_=s+l,f=r+c,p=s-l,b=r-c;T.push(d,g,m,E,_,f,_,f,m,E,p,b)}}const x=this.calculateTranslatedCoords(u,d,e.rotation,g,T),A=this.getNextRenderObject(e,i);if(A&&this._canPrimitivesObjectsMerge(e,A))return null===this.#Zt?(this.#Zt=x,Promise.resolve(0)):(this.#Zt.push(...x),Promise.resolve(0));{t.useProgram(s),t.uniform2f(E,t.canvas.width,t.canvas.height),t.uniform1f(p,0),null===this.#Zt?this.#Zt=x:this.#Zt.push(...x),t.bindBuffer(t.ARRAY_BUFFER,this.#Kt),t.bufferData(t.ARRAY_BUFFER,new Float32Array(this.#Zt),t.STATIC_DRAW);const i=2,r=t.FLOAT,n=!1,a=0,o=0;t.vertexAttribPointer(f,i,r,n,a,o);const l=this.#li(e.bgColor);t.uniform4f(_,l[0]/255,l[1]/255,l[2]/255,l[3]),m&&t.blendFunc(m[0],m[1]),e.isMaskAttached?t.stencilFunc(t.EQUAL,e._maskId,255):e._isMask&&t.stencilFunc(t.ALWAYS,e.id,255);const c=this.#Zt.length/2;return this.#Zt=null,this._render(c,t.TRIANGLES)}};_bindConus=(e,t,i,s,r)=>{const[n,a]=!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset,o=e.x-n,l=e.y-a,c=e.scale,h=e.rotation,{u_translation:u,u_rotation:d,u_scale:g,u_resolution:m,u_color:E,a_position:_,u_fade_max:f,u_fade_min:p}=r,T=e.vertices,b=e.bgColor,x=e.fade_min,R=e.radius,A=e.blendFunc?e.blendFunc:[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA];let S=0;t.useProgram(s),t.uniform2f(m,t.canvas.width,t.canvas.height),t.uniform2f(u,o,l),t.uniform2f(g,c[0],c[1]),t.uniform1f(d,h),t.uniform1f(p,x),t.uniform1f(f,R),t.bindBuffer(t.ARRAY_BUFFER,this.#Kt),t.bufferData(t.ARRAY_BUFFER,new Float32Array(T),t.STATIC_DRAW),t.enableVertexAttribArray(_);const v=t.FLOAT;t.vertexAttribPointer(_,2,v,!1,0,0),S+=T.length/2,A&&t.blendFunc(A[0],A[1]);const y=this.#li(b);return t.uniform4f(E,y[0]/255,y[1]/255,y[2]/255,y[3]),e.isMaskAttached?t.stencilFunc(t.EQUAL,e._maskId,255):e._isMask&&t.stencilFunc(t.ALWAYS,e.id,255),this._render(S,t.TRIANGLE_FAN)};_bindText=(e,t,i,s,r)=>{const{u_resolution:n,a_position:a,a_texCoord:o,u_image:l}=r,{width:c,height:h}=e.boundariesBox,[u,d]=!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset,g=e.x-u,m=e.y-d-h,E=e.blendFunc?e.blendFunc:[t.ONE,t.ONE_MINUS_SRC_ALPHA],_=e.rotation||0,f=e.scale,p=0+c,T=0+h,b=[0,0,p,0,0,T,0,T,p,0,p,T],x=e._atlasPos;let R,A,S=[0,0,1,1],v=void 0!==x.atlasIndex?x.atlasIndex:this.#$t,y=this.#Jt[v],w=c,I=h;if(!0===x.isMeasurementsSet){const t