UNPKG

jsge

Version:

Javascript Game Engine

1 lines 88.5 kB
var e,t,i={},s={};function r(e){var t=s[e];if(void 0!==t)return t.exports;var n=s[e]={exports:{}};return i[e](n,n.exports,r),n.exports}r.m=i,r.d=(e,t)=>{for(var i in t)r.o(t,i)&&!r.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},r.f={},r.e=e=>Promise.all(Object.keys(r.f).reduce((t,i)=>(r.f[i](e,t),t),[])),r.u=e=>e+".index.es6.min.js",r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),e={},t="jsge:",r.l=(i,s,n,a)=>{if(e[i])e[i].push(s);else{var o,l;if(void 0!==n)for(var c=document.getElementsByTagName("script"),u=0;u<c.length;u++){var d=c[u];if(d.getAttribute("src")==i||d.getAttribute("data-webpack")==t+n){o=d;break}}o||(l=!0,(o=document.createElement("script")).type="module",o.charset="utf-8",o.timeout=120,r.nc&&o.setAttribute("nonce",r.nc),o.setAttribute("data-webpack",t+n),o.src=i),e[i]=[s];var h=(t,s)=>{o.onerror=o.onload=null,clearTimeout(g);var r=e[i];if(delete e[i],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(e=>e(s)),t)return t(s)},g=setTimeout(h.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=h.bind(null,o.onerror),o.onload=h.bind(null,o.onload),l&&document.head.appendChild(o)}},r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;if("string"==typeof import.meta.url&&(e=import.meta.url),!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),r.p=e})(),(()=>{var e={179:0};r.f.j=(t,i)=>{var s=r.o(e,t)?e[t]:void 0;if(0!==s)if(s)i.push(s[2]);else{var n=new Promise((i,r)=>s=e[t]=[i,r]);i.push(s[2]=n);var a=r.p+r.u(t),o=new Error;r.l(a,i=>{if(r.o(e,t)&&(0!==(s=e[t])&&(e[t]=void 0),s)){var n=i&&("load"===i.type?"missing":i.type),a=i&&i.target&&i.target.src;o.message="Loading chunk "+t+" failed.\n("+n+": "+a+")",o.name="ChunkLoadError",o.type=n,o.request=a,s[1](o)}},"chunk-"+t,t)}};var t=(t,i)=>{var s,n,[a,o,l]=i,c=0;if(a.some(t=>0!==e[t])){for(s in o)r.o(o,s)&&(r.m[s]=o[s]);l&&l(r)}for(t&&t(i);c<a.length;c++)n=a[c],r.o(e,n)&&e[n]&&e[n][0](),e[n]=0},i=self.webpackChunkjsge=self.webpackChunkjsge||[];i.forEach(t.bind(null,0)),i.push=t.bind(null,i.push.bind(i))})();var n={};r.d(n,{oX:()=>l,QD:()=>C,T_:()=>tt,uw:()=>le,xl:()=>a,xP:()=>rt,bq:()=>re,P6:()=>o});var a={};r.r(a),r.d(a,{Rectangle:()=>W,Vector:()=>j,Vertex:()=>F});var o={};r.r(o),r.d(o,{angle_2points:()=>me,angle_3points:()=>fe,calculateEllipseVertices:()=>Be,calculateLinesVertices:()=>Ne,countClosestTraversal:()=>he,countClosestTraversal2:()=>ge,countDistance:()=>Te,crossProduct:()=>pe,dotProduct:()=>_e,dotProductWithAngle:()=>Ee,generateUniqId:()=>Me,isCircleLineIntersect:()=>Ie,isEllipseCircleIntersect:()=>Pe,isEllipseLineIntersect:()=>Oe,isEllipsePolygonIntersect:()=>Ce,isLineShorter:()=>Re,isMobile:()=>ce,isPointCircleIntersect:()=>we,isPointInsidePolygon:()=>xe,isPointLineIntersect:()=>Ae,isPointOnTheLine:()=>be,isPointPolygonIntersect:()=>Se,isPointRectIntersect:()=>ye,isPolygonLineIntersect:()=>ve,isSafari:()=>ue,mat3Multiply:()=>Fe,mat3MultiplyPosCoords:()=>je,mat3MultiplyVector:()=>We,pointToCircleDistance:()=>de,randomFromArray:()=>De,verticesArrayToArrayNumbers:()=>Le});const l={MODE:{DEBUG:"DEBUG",PRODUCTION:"PRODUCTION"},SCREENS:{},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:"drawImages",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"}}},c="rect",u="conus",d="circle",h="polygon",g="line",m="text",f="image",E={CREATE_INSTANCE_ERROR:"CREATE_INSTANCE_ERROR",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"},_="NOT_FOUND",p="WORLD_DIMENSIONS_NOT_SET",b="UNHANDLED_DRAW_ISSUE",T="AUDIO_NOT_REGISTERED",R="AUDIO_NOT_LOADED",A="UNKNOWN_DRAW_OBJECT",v="METHOD_NOT_IMPLEMENTED",S="POLYGON_VERTICES_NOT_CORRECT";function x(e,t){throw new Error(e+": "+t)}function y(e,t){console.warn(e,t)}class w{#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 I{#l;#c;#u;#d;#h;#g=0;#m=0;#f=Me();#E=!1;#_;#p;#b=!1;#T=!1;constructor(e,t,i,s){this.#l=t,this.#c=i,this.#u=s,this.#d=e}get bgColor(){return this.#u}set bgColor(e){this.#u=e}get type(){return this.#d}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.#h}set blendFunc(e){this.#h=e}get rotation(){return this.#m}set rotation(e){this.#m=e}get id(){return this.#f}get isRemoved(){return this.#E}destroy(){this.#E=!0}get isMaskAttached(){return!!this.#_}get _maskId(){return this.#_}setMask(e){e._isMask=!0,this.#_=e.id}removeMask(){this.#_=null}set _isMask(e){this.#p=e}get _isMask(){return this.#p}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?Le(e):e}}class O{#R;#A;#v;#S=0;#x=0;#y=0;constructor(e,t){this._initiateStorageData(e,t)}get cells(){return this.#x}get vectors(){return this.#R}get textures(){return this.#A}get _bTempIndexes(){return this.#v}get bufferSize(){return this.#S}_initiateStorageData(e,t){this.#x=e,this.#y=t||e,this.#y>e&&(this.#y=e),this.#S=12*this.#y,this.#R=new Array(this.#S),this.#A=new Array(this.#S),this.#v=new Int32Array(4*this.#x)}}class P{#w;#I;#O;#P;#C="-#-";#M;#D;#L;#N;#B;#_;#g=0;#F=new Map;#b;#E=!1;constructor(e,t,i,s,r,n,a=!1,o){this.#w=e,this.#I=t,this.#O=i,this.#P=s,this.#D=[],this.#M=r,this.#L=n,this.#N=a,this.#B=a||!1,o&&this.setMask(o),this.#W(s,n)}get layerKey(){return this.#w}get tileMapKey(){return this.#I}get tilemap(){return this.#O}get tilesets(){return this.#P}get tilesetImages(){return this.#M}get layerData(){return this.#L}get setBoundaries(){return this.#N}get drawBoundaries(){return this.#B}set drawBoundaries(e){this.#B=e}get isRemoved(){return this.#E}set isRemoved(e){this.#E=e}get _maskId(){return this.#_}setMask(e){e._isMask=!0,this.#_=e.id}removeMask(){this.#_=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.#F.size>0}get _textureStorages(){return this.#D}_setTextureStorage(e,t){this.#D[e]=t}#W(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],u=c?c.firstgid:1e9;if(a)for(let n of a){const a=n.animation,c=n.objectgroup,u=n.id;if(a){const t=o+this.#C+u,i=this.#j(a),s=new w(t,i,!0);this.#F.set(t,s),e._hasAnimations||(e._hasAnimations=!0,e._animations=new Map,e._animations.set(u,i[0][0])),this.#G(s)}c&&this.#N&&(e._hasBoundaries||(e._hasBoundaries=!0,e._boundaries=new Map),e._boundaries.set(u,c),c.objects.forEach(e=>{if(e.ellipse){const e=t.data.filter(e=>e===u+l).length;i+=4*e}else if(e.point){const e=t.data.filter(e=>e===u+l).length;s+=2*e}else if(e.polygon){const i=t.data.filter(e=>e===u+l).length;r+=2*e.polygon.length*i}else{const e=t.data.filter(e=>e===u+l).length;r+=16*e}}))}const d=t.data.filter(e=>e>=l&&e<u).length,h=t.data.length;this.#N&&(r+=16*d),e._temp=new O(h,d)}),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.#F.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.#P.findIndex(e=>e.name===t);this.#P[s]._animations.set(parseInt(i),e.currentSprite)};stopRepeatedAnimation(e){this.#F.get(e).deactivateAnimation()}removeAllAnimations(){for(let[e,t]of this.#F.entries())this.removeEventListener(e,t.activateAnimation),t.deactivateAnimation();this.#F.clear(),this.#F=void 0}destroy(){this.removeAllAnimations(),super.destroy()}}class C extends I{#V;#k;#X;#Y;#z;#F;#H;#K;#Q=0;#Z=0;#q;#J;#$;constructor(e,t,i,s,r,n=0,a,o,l=0,c=0){super(f,e,t),this.#X=r,this.#z=new EventTarget,this.#F=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 imageIndex(){return this.#K}set imageIndex(e){this.#K=e}get spacing(){return this.#Q}get margin(){return this.#Z}get hasAnimations(){return this.#F.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.#F.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(E.UNEXPECTED_INPUT_PARAMS," animationSpriteIndexes should be Array of indexes, or Array of objects {duration:number, id:number}");const s=new w(e,t,i);this.#F.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.#F.get(t);this.#H&&this.#H!==t&&this.stopRepeatedAnimation(this.#H),i.activateAnimation(),this.#H=t,this.#K=i.currentSprite};stopRepeatedAnimation(e){this.#F.get(e).deactivateAnimation(),this.#H=null}removeAllAnimations(){for(let[e,t]of this.#F.entries())this.removeEventListener(e,t.activateAnimation),t.deactivateAnimation();this.#F.clear(),this.#F=void 0}destroy(){this.removeAllAnimations(),super.destroy()}}class M extends I{#te;#q;constructor(e,t,i,s){super(d,e,t,s),this.#te=i,this.#q=this._interpolateConus(i)}get vertices(){return this.#q}set vertices(e){this.#q=e}get radius(){return this.#te}}class D extends I{#te;#ie;#q;#se;constructor(e,t,i,s,r,n=0){super(u,e,t,s),this.#te=i,this.#ie=r,this.#se=n,this.#q=this._interpolateConus(i,r)}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 L extends I{#q;constructor(e,t){super(g,e[0][0],e[0][1],t),this.#q=e}get vertices(){return this.#q}set vertices(e){this.#q=e}}class N extends I{#q;constructor(e,t){super(h,e[0].x,e[0].y,t),this.#q=this._convertVerticesArray(e)}get vertices(){return this.#q}set vertices(e){this.#q=e}}class B extends I{#V;#k;#q;constructor(e,t,i,s,r){super(c,e,t,r),this.#V=i,this.#k=s,this.#q=this._calculateRectVertices(i,s)}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 F{#l;#c;constructor(e,t){this.#l=e,this.#c=t}get x(){return this.#l}get y(){return this.#c}}class W{#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 j{#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 G extends I{#re;#ne;#ae;#oe;#le;#ce;#ue;#de=document.createElement("canvas");#$;constructor(e,t,i,s,r){super(m,e,t),this.#ce=i,this.#re=s,this.#oe=r,this.#ue,this.#he()}get boundariesBox(){const e=this.textMetrics?Math.floor(this.textMetrics.width):300,t=this.textMetrics?Math.floor(this.textMetrics.fontBoundingBoxAscent+this.textMetrics.fontBoundingBoxDescent):30;return new W(this.x,this.y-t,e,t)}get vertices(){const e=this.boundariesBox;return this._calculateRectVertices(e.width,e.height)}get text(){return this.#ce}set text(e){e!==this.#ce&&(this.#ce=e,this.#he())}get font(){return this.#re}set font(e){e!==this.#re&&(this.#re=e,this.#he())}get textAlign(){return this.#ne}set textAlign(e){e!==this.#ne&&(this.#ne=e,this.#he())}get textBaseline(){return this.#ae}set textBaseline(e){e!==this.#ae&&(this.#ae=e,this.#he())}get fillStyle(){return this.#oe}set fillStyle(e){e!==this.#oe&&(this.#oe=e,this.#he())}get strokeStyle(){return this.#le}set strokeStyle(e){e!==this.#le&&(this.#le=e,this.#he())}get textMetrics(){return this.#ue}set _textMetrics(e){this.#ue=e}get _textureStorage(){return this.#$}set _textureStorage(e){this.#$=e}get _textureCanvas(){return this.#de}#he(){const e=this.#de.getContext("2d",{willReadFrequently:!0});if(e){e.font=this.font,this._textMetrics=e.measureText(this.text);const t=this.boundariesBox.width,i=this.boundariesBox.height;e.canvas.width=t,e.canvas.height=i,e.clearRect(0,0,t,i),e.font=this.font,e.textBaseline="bottom",this.fillStyle&&(e.fillStyle=this.fillStyle,e.fillText(this.text,0,i)),this.strokeStyle&&(e.strokeStyle=this.strokeStyle,e.strokeText(this.text,0,i)),this.#$&&(this.#$._isTextureRecalculated=!0)}else x(E.UNHANDLED_EXCEPTION,"can't getContext('2d')")}}class U{#ge;#me;#fe;#Ee;#_e=0;#pe=0;#be=0;#Te=0;#Re=0;#Ae=0;#ve=0;#Se=0;#xe=0;#ye=0;#we=0;#Ie;#Oe;#Pe;#Ce;#Me=[];#De=[];#b;#Le=!1;#Ne=[];#Be=!1;constructor(e){}isOffsetTurnedOff(){return this.#b}set mapRotate(e){this.#Re=e}#Fe(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.#Ne.push(...e[i])}_enableDebugObjectBoundaries(){this.#Be=!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.#Ie[this.#xe]=e,this.#xe++,this.#Ie[this.#xe]=t,this.#xe++,this.#Ie[this.#xe]=i,this.#xe++,this.#Ie[this.#xe]=s,this.#xe++}_addEllipseBoundary(e,t,i,s){this.#Oe[this.#we]=e,this.#we++,this.#Oe[this.#we]=t,this.#we++,this.#Oe[this.#we]=i,this.#we++,this.#Oe[this.#we]=s,this.#we++}_addPointBoundary(e,t){this.#Pe[this.#ye]=e,this.#ye++,this.#Pe[this.#ye]=t,this.#ye++}_removeBoundaryLine(e){this.#Ie[e]=0,this.#Ie[e+1]=0,this.#Ie[e+2]=0,this.#Ie[e+3]=0}_clearBoundaries(){this.#Ie.fill(0),this.#Oe.fill(0),this.#Pe.fill(0),this.#xe=0,this.#we=0,this.#ye=0,this.#Be&&(this.#Ne=[])}_initiateBoundariesData(){this.#Ie=new Float32Array(this.#Ae),this.#Oe=new Float32Array(this.#ve),this.#Pe=new Float32Array(this.#Se)}_setMaxBoundariesSize(e,t=0,i=0){this.#Ae=e,this.#ve=t,this.#Se=i}_setWorldDimensions(e,t){this.#ge=e,this.#me=t}_setCanvasDimensions(e,t){this.#fe=e,this.#Ee=t}_setMapBoundaries(){const[e,t]=[this.#ge,this.#me],[i,s]=[this.#_e,this.#pe],r=e-i,n=t-s;e&&t||y(p,"Can't set map boundaries."),this.#Fe({x1:0,y1:0,x2:r,y2:0}),this.#Fe({x1:r,y1:0,x2:r,y2:n}),this.#Fe({x1:r,y1:n,x2:0,y2:n}),this.#Fe({x1:0,y1:n,x2:0,y2:0})}_setWholeWorldMapBoundaries(){const[e,t]=[this.#ge,this.#me];e&&t||y(p,"Can't set map boundaries."),this.#Ce.push([0,0,e,0]),this.#Ce.push([e,0,e,t]),this.#Ce.push([e,t,0,t]),this.#Ce.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],u=a[3];t===c&&s===u&&r===o&&n===l&&(i.delete(e),i.delete(a)),r!==o||n!==l||t!==c&&s!==u||(a[0]=t,a[1]=s,i.delete(e))}}e?this.#Ie=Array.from(i):this.#Ce=Array.from(i),i.clear()}_setWholeMapBoundaries(e){this.#Ce.push(...e)}_enableMapBoundaries(){this.#Le=!0}_sortRenderObjectsBySortIndex(){this.#Me.sort((e,t)=>e.sortIndex-t.sortIndex)}_processPendingRenderObjects(){this.#De.length>0&&(this.#Me.push(...this.#De),this._sortRenderObjectsBySortIndex(),this.#De=[])}set _renderObject(e){this.#De.push(e)}set _renderObjects(e){e.forEach(e=>{this._renderObject=e})}getBoundaries(){const e=this.#Ie,t=this.#xe;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.#Ie}getEllipseBoundaries(){return this.#Oe}getPointBoundaries(){return this.#Pe}getWholeWorldBoundaries(){return this.#Ce}getDebugObjectBoundaries(){return this.#Ne}get isWorldBoundariesEnabled(){return this.#Le}get canvasDimensions(){return[this.#fe,this.#Ee]}get worldDimensions(){return[this.#ge,this.#me]}get worldOffset(){return[this.#_e,this.#pe]}get mapCenter(){return[this.#be,this.#Te]}get mapRotate(){return this.#Re}get boundariesLen(){return this.#xe}get ellipseBLen(){return this.#we}get pointBLen(){return this.#ye}centerCameraPosition=(e,t)=>{let[i,s]=this.worldOffset;const[r,n]=this.canvasDimensions,[a,o]=this.worldDimensions,l=r/2,c=n/2,u=c-s;if(l-i<e)if(e<a-l){const t=e-l;t>=0&&(this.#_e=Math.round(t))}else if(a>r){const e=a-r;this.#_e=Math.round(e)}if(u<t)if(t<o-c){const e=t-c;e>=0&&(this.#pe=Math.round(e))}else if(o>n){const e=o-n;this.#pe=Math.round(e)}this.#be=e,this.#Te=t};personRotatedCenterCamera=(e,t,i)=>{console.log("new centering algorithm")};get renderObjects(){return this.#Me}getObjectsByInstance(e){return this.#Me.filter(t=>t instanceof e)}cleanUp(){this.#Me=[],this.#De=[],this._clearBoundaries()}}const V={loadstart:"loadstart",progress:"progress",abort:"abort",error:"error",load:"load",timeout:"timeout"},k=" loader is not registered.",X="Too much recursion. Stop iteration.",Y="uploadMethod should be instance of Promise and return upload result value",z=" AtlasXML file extension is incorrect, only .xml file supported",H=" tilemap file extension is not correct, only .tmj, .json, .tmx, .xml files are supported",K=" fileKey and url should be provided",Q="Error loading related tileset ",Z="JSON",q="XML",J="UNKNOWN";class ${#We;#je;#Ge=new Map;#Ue=new Map;constructor(e,t){this.#We=e,this.#je=(e,i,...s)=>{const r=t(e,i,...s);if(r instanceof Promise)return r.then(t=>this.#Ve(t,e));throw new TypeError(Y)}}#Ve=(e,t)=>new Promise((i,s)=>{e||null===e||ie("AssetsManager: uploadMethod for "+this.#We+" returns incorrect value"),this.#ke(t,e),this.#Xe(t),i()});#ke(e,t){this.#Ue.set(e,t)}#Xe(e){this.#Ge.delete(e)}get filesWaitingForUpload(){return this.#Ge.size}get loadingQueue(){return this.#Ge}get uploadMethod(){return this.#je}_addFile=(e,t)=>{this.#Ge.has(e)&&ie("AssetsManager: File "+this.#We+" with key "+e+" is already added"),this.#Ge.set(e,t)};_isFileInQueue=e=>this.#Ge.has(e);_getFile=e=>this.#Ue.get(e)}class ee{#Ye=5;#z=new EventTarget;#ze=new Map;#He=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.#ze.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.#ze.get(e)||new $(e,t);this.#ze.set(e,i)};preload(){return this.#Ke(),new Promise(async(e,t)=>{this.#Qe().then(()=>{this.#Ze(),e()}).catch(e=>{t(e)})})}#Qe(e=0){return this.#qe().then(()=>{if(0===this.filesWaitingForUpload)return Promise.resolve();if(++e>this.#Ye){const e=new Error(X);return this.#Je(e),Promise.reject(new Error(X))}return this.#Qe(e)})}#qe(){return new Promise((e,t)=>{let i=[];Array.from(this.#ze.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.#$e(i)?t(i):(ie("AssetsManager: "+i.message),this.#Je(i))}e()})})}addEventListener(e,t,...i){V[e]?this.#z.addEventListener(e,t,...i):ie("AssetsManager: Event type should be one of the ProgressEvent.type")}removeEventListener(e,t,...i){this.#z.removeEventListener(e,t,...i)}_loadAtlasXml=(e,t)=>(this.#et(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.#tt(t);return this.addAtlasImageMap(e,i+r.value,n,i),s}{const t=new Error(e+" XML format is not correct.");return this.#Je(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,u=i.getNamedItem("height").value;t.push(createImageBitmap(l.getImageData(a,o,c,u),{premultiplyAlpha:"premultiply"})),s.push(n)}this.#it(),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.#Je(i),e(null)},n.src=t});_loadTileSet=(e,t,i=1,s)=>{const r=this.#st(t),n=s?s+t:t;return r===Z?fetch(n).then(e=>e.json()).then(e=>this._processTilesetData(e,s,i,t)).catch(()=>{const e=new Error(Q+t);return this.#Je(e),Promise.resolve(null)}):r===q?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(Q+t);return this.#Je(e),Promise.resolve(null)}):Promise.reject(n+H)};_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.#rt(t)===Z?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.#Je(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.#Je(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.#tt(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.#it(),Promise.resolve(e)));t.push(e)}else{const i=this._processTilesetData(e,s).then(e=>(this.#it(),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.#it(),e(i)}),i.addEventListener("error",()=>{const i=new Error("Error loading audio "+t);this.#Je(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.#it(),e(t)})},i.onerror=()=>{const i=new Error("Error loading image "+t);this.#Je(i),e(null)},i.src=t}});#et(e){e.includes(".xml")||te(e+z)}#st(e){return e.includes(".tsj")||e.includes(".json")?Z:e.includes(".tsx")||e.includes(".xml")?q:J}#rt(e){return e.includes(".tmj")||e.includes(".json")?Z:e.includes(".tmx")||e.includes(".xml")?q:J}#$e(e){return e.message.includes(Y)||e.message.includes(z)||e.message.includes(" tileset file extension is not correct, only .tsj, .json, .tsx, .xml files are supported")||e.message.includes(H)||e.message.includes(K)||e.message.includes(k)}#tt(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.#ze.get(e);r?(this.#nt(t,i,e),r._addFile(t,[i,...s])):te(e+k)}isFileInQueue(e,t){const i=this.#ze.get(e);if(i)return i._isFileInQueue(t);te("Loader for "+e+" is not registered!")}getFile(e,t){const i=this.#ze.get(e);if(i)return i._getFile(t);te("Loader for "+e+" is not registered!")}#nt(e,t,i){const s=K;e&&0!==e.trim().length||te("add"+i+"()"+s),t&&0!==t.trim().length||te("add"+i+"()"+s)}#Ke(){let e=this.filesWaitingForUpload;this.#z.dispatchEvent(new ProgressEvent(V.loadstart,{total:e}))}#Ze(){this.#z.dispatchEvent(new ProgressEvent(V.load))}#it(){const e=this.filesWaitingForUpload;this.#He+=1,this.#z.dispatchEvent(new ProgressEvent(V.progress,{lengthComputable:!0,loaded:this.#He,total:e}))}#Je(e){ie("AssetsManger: "+e.message),this.#z.dispatchEvent(new ErrorEvent(V.error,{error:e}))}}function te(e){throw new Error(e)}function ie(e){console.warn(e)}class se{#at;#ot;constructor(e){this.#at=e}get stageData(){return this.#ot}#lt(e){this.#ot._renderObject=e}rect(e,t,i,s,r){const n=new B(e,t,i,s,r);return this.#lt(n),n}text(e,t,i,s,r){const n=new G(e,t,i,s,r);return this.#lt(n),n}conus(e,t,i,s,r,n=0){const a=new D(e,t,i,s,r,n);return this.#lt(a),a}circle(e,t,i,s){const r=new M(e,t,i,s);return this.#lt(r),r}image(e,t,i,s,r,n=0,a,o=0,l=0){const c=this.#at.getImage(r);c||x(E.CANT_GET_THE_IMAGE,"iLoader can't get the image with key: "+r);const u=new C(e,t,i,s,r,n,a,c,o,l);return this.#lt(u),u}line(e,t){const i=new L(e,t);return this.#lt(i),i}polygon(e,t){const i=new N(e,t);return this.#lt(i),i}tiledLayer(e,t,i,s){const r=this.#at.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.#at.getImage(e.name)),c=new P(e,t,r,o,l,n,i,s);return l.length>1&&y("MULTIPLE_IMAGE_TILESET"," tileset "+e+" includes multiple images, it can case performance issues!"),this.#lt(c),c}_registerNewObjectMethod=(e,t)=>{this[e]=(...e)=>this.#ct(t,...e)};#ct=(e,...t)=>{const i=e(...t);return this.#lt(i),i};_attachPageData=e=>{this.#ot=e};_detachPageData=()=>{this.#ot=null}}class re{constructor(){}static mode=l.MODE.DEBUG;static gameOptions={library:l.LIBRARY.WEBGL,optimization:l.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:l.OPTIMIZATION.CYCLE_TIME_CALC.AVERAGES,averageFPStime:1e4},boundaries:{mapBoundariesEnabled:!0,realtimeCalculations:!0,wholeWorldPrecalculations:!1}},debug:{preserveDrawingBuffer:!1,checkWebGlErrors:!1,debugMobileTouch:!1,boundaries:{drawLayerBoundaries:!1,drawObjectBoundaries:!1,boundariesColor:"rgba(224, 12, 21, 0.6)",boundariesWidth:2},delayBetweenObjectRender:!1}};static network={enabled:!1,address:"https://gameserver.reslc.ru:9009",gatherRoomsInfoInterval:5e3};static canvasMaxSize={width:1800,height:1800};static worldSize={width:960,height:960};static defaultCanvasKey="default";static customSettings={}}class ne{static debug(...e){re.mode===l.MODE.DEBUG&&e.forEach(e=>console.log(e))}}class ae extends Event{#ut;constructor(e,t){super(e),this.#dt(e)||x(E.UNEXPECTED_EVENT_NAME,", Please check if event is exist"),this.#ut=t}#dt(e){return Object.values(l.EVENTS.WEBSOCKET.SERVER_CLIENT).find(t=>t===e)}get data(){return this.#ut}}class oe extends EventTarget{#ht;#gt;constructor(e){super(),e||x(E.CREATE_INSTANCE_ERROR,"systemSettings should be passed to class instance"),this.#ht=e}init(){r.e(319).then(r.bind(r,319)).then(e=>{this.#gt=e.io(this.#ht.network.address,{withCredentials:!0}),this.#mt()})}get isServerConnected(){return!(!this.#gt||!this.#gt.connected)}get playerId(){return this.#gt.id}sendGatherRoomsInfo(){this.#gt.emit(l.EVENTS.WEBSOCKET.CLIENT_SERVER.ROOMS_INFO_REQUEST)}sendCreateOrJoinRoom(e,t){this.#gt.emit(l.EVENTS.WEBSOCKET.CLIENT_SERVER.CREATE_OR_JOIN,e,t)}sendMessage(e){this.#gt.emit(l.EVENTS.WEBSOCKET.CLIENT_SERVER.CLIENT_MESSAGE,e)}#ft=()=>{ne.debug("connected, socket id: "+this.#gt.id),this.dispatchEvent(new Event(l.EVENTS.WEBSOCKET.SERVER_CLIENT.CONNECTION_STATUS_CHANGED))};#Et=e=>{ne.debug("server disconnected, reason: "+e),this.dispatchEvent(new Event(l.EVENTS.WEBSOCKET.SERVER_CLIENT.CONNECTION_STATUS_CHANGED))};#_t=e=>{console.warn("server data: ",e)};#pt=e=>{ne.debug("received new message from server: "+e),this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.SERVER_MESSAGE,e))};#bt=e=>{ne.debug("received roomsInfo "+e),this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.ROOMS_INFO,e))};#Tt=(e,t)=>{ne.debug("CLIENT SOCKET: Created room "+e),this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.CREATED,{room:e,map:t}))};#Rt=e=>{ne.debug("CLIENT SOCKET: Room is full, can't join: "+e),this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.FULL,{room:e}))};#At=(e,t)=>{ne.debug("CLIENT SOCKET: Joined to room: "+e,", map: ",t),this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.JOINED,{room:e,map:t}))};#vt=e=>{this.dispatchEvent(new ae(l.EVENTS.WEBSOCKET.SERVER_CLIENT.DISCONNECTED,{playerId:e}))};#mt(){this.#gt.on("connect",this.#ft),this.#gt.on("disconnect",this.#Et),this.#gt.on("data",this.#_t),this.#gt.on("roomsInfo",this.#bt),this.#gt.on("created",this.#Tt),this.#gt.on("full",this.#Rt),this.#gt.on("joined",this.#At),this.#gt.on("log",function(e){console.log.apply(console,e)}),this.#gt.on("message",this.#pt),this.#gt.on("removed",function(e){console.log("removed message"),console.log(e)}),this.#gt.on("disconnected",this.#vt),addEventListener("beforeunload",this.#St)}#St=()=>{this.#gt.disconnect()}}class le{#xt=.5;#yt=new Map;#wt;constructor(e){this.#wt=e}getAudio=e=>{const t=this.#yt.get(e);return null===t?(y(R,"Audio with key "+e+" exists, but not actually loaded"),t):t||(y(T,""),null)};getAudioCloned=e=>{const t=this.#yt.get(e);if(null===t)return y(R,"Audio with key "+e+" exists, but not actually loaded"),t;if(t){const e=t.cloneNode();return e.volume=this.#xt,e}return y(T),null};set volume(e){this.#xt=e,this.#It(e)}get volume(){return this.#xt}#It(e){for(const t of this.#yt.values())t&&(t.volume=e)}registerAudio(e){let t=this.#wt.getAudio(e);this.#yt.set(e,t)}}function ce(){return/Android|webOS|iPhone|iPad|iPod|Opera Mini/i.test(navigator.userAgent)}function ue(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function de(e,t,i){return new j(e,t,i.x,i.y).length-i.r}function he(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,u=r-i,d=n-s,h=a,g=o,m=e.x2-a,f=e.y2-o,E=Math.sqrt(u*u+d*d),_=Math.sqrt(m*m+f*f);if(u/E==m/_&&d/E==f/_)return null;const p=(u*(g-c)+d*(l-h))/(m*d-f*u),b=(h+m*p-l)/u;return b<0||isNaN(b)||p<0||p>1?null:{x:l+u*b,y:c+d*b,p:b}}function ge(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,u=(i-r)*(o-c)-(s-n)*(a-l);if(0===u)return;let d=((i*n-s*r)*(a-l)-(i-r)*(a*c-o*l))/u,h=((i*n-s*r)*(o-c)-(s-n)*(a*c-o*l))/u;const g={x:d,y:h};return be(g,e,1e-13)&&be(g,t,1e-13)?{x:d,y:h,p:Math.sqrt(Math.pow(d-i,2)+Math.pow(h-s,2))}:void 0}function me(e,t,i,s){return Math.atan2(s-t,i-e)}function fe(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 Ee(e,t,i){return e*t*Math.cos(i)}function _e(e,t){return e.x*t.x+e.y*t.y}function pe(e,t){return e.x*t.y-t.x*e.y}function be(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 Te(e,t){return new j(e.x,e.y,t.x,t.y).length}function Re(e,t){return new j(e.x1,e.y1,e.x2,e.y2).length<new j(t.x1,t.y1,t.x2,t.y2).length}function Ae(e,t){const i=new j(t.x1,t.y1,t.x2,t.y2).length;return new j(t.x1,t.y1,e.x,e.y).length+new j(t.x2,t.y2,e.x,e.y).length<=i+.2}function ve(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=ge({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=ge({x1:s[0],y1:s[1],x2:r[0],y2:r[1]},t);if(n)return n}return null}function Se(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]),Ae({x:e,y:t},{x1:s[0],y1:s[1],x2:n[0],y2:n[1]}))return!0}return!1}function xe(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],u=a[1];t<l!=t<u&&e<(c-o)*(t-l)/(u-l)+o&&r++}return r>0&&r%2!=0}function ye(e,t,i){return e>=i.x&&e<=i.width+i.x&&t>=i.y&&t<=i.y+i.height}function we(e,t,i){const s=i.r;return new j(e,t,i.x,i.y).length<s}function Ie(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},u={x:a-r,y:o-n},d={x:r-a,y:n-o},h=Math.sqrt(Math.pow(u.x,2)+Math.pow(u.y,2)),g=_e(l,d),m=_e(c,u);let f;return g>0&&m>0?(f=pe(l,c)/h,f<0&&(f*=-1)):f=Math.min(l.length,c.length),f<=i}function Oe(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)),u=Math.min(l,c);if(u>Math.max(r,n))return!1;const d=u===l?a:o,h=Math.atan2(d.y,d.x),g={x:0-Math.cos(h)*r,y:0-Math.sin(h)*n};return!(u>Math.sqrt(Math.pow(g.x,2)+Math.pow(g.y,2)))}function Pe(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=me(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 Ce(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]),Oe(e,[i,r]))return!0}return!1}function Me(){return Math.round(1e6*Math.random())}function De(e){return e[Math.floor(Math.random()*e.length)]}function Le(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 Ne(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],u=r[1],d=l[0],h=l[1],g=[c*Math.cos(i)-u*Math.sin(i)+e,c*Math.sin(i)+u*Math.cos(i)+t,d*Math.cos(i)-h*Math.sin(i)+e,d*Math.sin(i)+h*Math.cos(i)+t];n[a]=g,a++}return n}function Be(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 Fe(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 We(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 je(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 Ge{#Ot;#Pt;#Ct=!0;constructor(e,t=0){this.#Pt=e,this.#Ot=t}get _isTextureRecalculated(){return this.#Ct}set _isTextureRecalculated(e){this.#Ct=e}get _texture(){return this.#Pt}set _texture(e){this.#Pt=e}get _textureIndex(){return this.#Ot}}class Ue{#Mt;#Dt;#Lt;#Nt;#Bt;#wt;#Ft;#Wt;#jt=null;#Gt=null;#Ut=new Map;#Vt=new Map;#kt=new Map;#Xt;constructor(e,t,i){e&&e instanceof WebGLRenderingContext||x(E.UNEXPECTED_INPUT_PARAMS," context parameter should be specified and equal to WebGLRenderingContext"),this.#Mt=e,this.#Bt=t,this.#wt=i,this.#Nt=t.debug.checkWebGlErrors,this.#Dt=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.#Lt=e.getParameter(e.MAX_TEXTURE_SIZE),this.#Ft=e.createBuffer(),this.#Wt=e.createBuffer(),this._registerObjectRender(G.name,this._bindText,l.WEBGL.DRAW_PROGRAMS.IMAGES_M),this._registerObjectRender(B.name,this._bindPrimitives,l.WEBGL.DRAW_PROGRAMS.PRIMITIVES_M),this._registerObjectRender(N.name,this._bindPrimitives,l.WEBGL.DRAW_PROGRAMS.PRIMITIVES_M),this._registerObjectRender(M.name,this._bindConus,l.WEBGL.DRAW_PROGRAMS.PRIMITIVES),this._registerObjectRender(D.name,this._bindConus,l.WEBGL.DRAW_PROGRAMS.PRIMITIVES),this._registerObjectRender(L.name,this._bindLine,l.WEBGL.DRAW_PROGRAMS.PRIMITIVES),this._registerObjectRender(P.name,this._bindTileImages,l.WEBGL.DRAW_PROGRAMS.IMAGES_M),this._registerObjectRender(f,this._bindImage,l.WEBGL.DRAW_PROGRAMS.IMAGES_M)}getProgram(e){return this.#Ut.get(e)}getProgramVarLocations(e){return this.#Vt.get(e)}_fixCanvasSize(e,t){this.#Mt.viewport(0,0,e,t)}_initiateJsRender=e=>new Promise((t,i)=>{const s=e.getObjectsByInstance(P),[r,n]=e.worldDimensions;let a=0,o=0,l=0,c=0,u=0;s.forEach(e=>{const t=e.setBoundaries,i=e.layerData,s=e.tilemap,r=e.tilesets,{tileheight:n,tilewidth:d}=s,h=d,g=n;for(let e=0;e<r.length;e++){const e=h*i.width,s=g*i.height,r=i.polygonBoundariesLen,n=i.ellipseBoundariesLen,d=i.pointBoundariesLen;c<e&&(c=e),u<s&&(u=s),t&&(a+=r,o+=n,l+=d)}}),0===c||0===u||c===r&&u===n||(y("UNEXPECTED_WORLD_SIZE"," World size from tilemap is different than settings one, fixing..."),e._setWorldDimensions(c,u)),this.#Bt.render.boundaries.mapBoundariesEnabled&&(a+=16),e._setMaxBoundariesSize(a,o,l),e._initiateBoundariesData(),t(!0)});_initWebGlAttributes=()=>{const e=this.#Mt;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.#Bt.optimization===l.OPTIMIZATION.WEB_ASSEMBLY.NATIVE_WAT?this.#Bt.optimizationWASMUrl:this.#Bt.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.#Xt=e}_clearView(){const e=this.#Mt;this.#Xt.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.#Mt.drawArrays(t,i,e),Promise.resolve(e)}_preRender(){return new Promise((e,t)=>{const i=this.#Mt;if(this.#Nt){const e=this.#Nt?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.#Mt.drawArrays(s,0,i),t=i}return new Promise((e,i)=>{const s=this.#Mt;0!==t&&(this.#Xt.incrementDrawCallsCounter(),this.#Xt.verticesDraw=t),s.stencilFunc(s.ALWAYS,1,255),this.#Bt.debug.delayBetweenObjectRender?setTimeout(()=>{e()},1e3):e()})}_registerAndCompileWebGlProgram(e,t,i,s,r){const n=this.#Yt(t,i),a=this.#zt(n,s,r);return this.#Ut.set(e,n),this.#Vt.set(e,a),Promise.resolve()}#Yt(e,t){const i=this.#Mt,s=i.createProgram();if(s){const r=this.#Ht(i,e,i.VERTEX_SHADER);r?i.attachShader(s,r):x(E.WEBGL_ERROR,"#compileShader(vertexShaderSource) is null");const n=this.#Ht(i,t,i.FRAGMENT_SHADER);if(n?i.attachShader(s,n):x(E.WEBGL_ERROR,"#compileShader(fragmentShaderSource) is null"),i.linkProgram(s),!i.getProgramParameter(s,i.LINK_STATUS)){const e=i.getProgramInfoLog(s);x(E.WEBGL_ERROR,`Could not compile WebGL program. \n\n${e}`)}}else x(E.WEBGL_ERROR,"gl.createProgram() is null");return s}#zt(e,t,i){const s=this.#Mt;let r={};return t.forEach(t=>{r[t]=s.getUniformLocation(e,t)}),i.forEach(t=>{r[t]=s.getAttribLocation(e,t)}),r}#Ht(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(E.WEBGL_ERROR,"Couldn't compile webGl program. \n\n"+t)}}else x(E.WEBGL_ERROR,`gl.createShader(${i}) is null`);return s}_bindPrimitives=(e,t,i,s,r)=>{const[n,a]=!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset,o=e.x-n,l=e.y-a,u=[1,1],g=e.blendFunc?e.blendFunc:[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA],{u_resolution:m,u_color:f,a_position:E,u_fade_min:_}=r;let p=[];switch(e.type){case c:const t=0,i=0+e.width,s=0,r=0+e.height;p=[t,s,i,s,t,r,t,r,i,s,i,r];break;case d:p=e.vertices;break;case h:const n=this.#Kt(e.vertices);if(p=n,n.length%3!=0)return y(S,`polygons ${e.id}, vertices are not correct, skip drawing`),Promise.reject()}const b=Math.cos(e.rotation),T=Math.sin(e.rotation),R=[u[0],0,0,0,u[1],0,0,0,1],A=je(Fe(Fe([1,0,o,0,1,l,0,0,1],[b,-T,0,T,b,0,0,0,1]),R),p),v=this.getNextRenderObject(e,i);if(v&&this._canPrimitivesObjectsMerge(e,v))return null===this.#jt?(this.#jt=A,Promise.resolve(0)):(this.#jt.push(...A),Promise.resolve(0));{t.useProgram(s),t.uniform2f(m,t.canvas.width,t.canvas.height),t.uniform1f(_,0),null===this.#jt?this.#jt=A:this.#jt.push(...A),t.bindBuffer(t.ARRAY_BUFFER,this.#Ft),t.bufferData(t.ARRAY_BUFFER,new Float32Array(this.#jt),t.STATIC_DRAW);const i=2,r=t.FLOAT,n=!1,a=0,o=0;t.vertexAttribPointer(E,i,r,n,a,o);const l=this.#Qt(e.bgColor);t.uniform4f(f,l[0]/255,l[1]/255,l[2]/255,l[3]),g&&t.blendFunc(g[0],g[1]),e.isMaskAttached?t.stencilFunc(t.EQUAL,e._maskId,255):e._isMask&&t.stencilFunc(t.ALWAYS,e.id,255);const c=this.#jt.length/2;return this.#jt=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=[1,1],u=e.rotation,{u_translation:d,u_rotation:h,u_scale:g,u_resolution:m,u_color:f,a_position:E,u_fade_max:_,u_fade_min:p}=r,b=e.vertices,T=e.bgColor,R=e.fade_min,A=e.radius,v=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(d,o,l),t.uniform2f(g,c[0],c[1]),t.uniform1f(h,u),t.uniform1f(p,R),t.uniform1f(_,A),t.bindBuffer(t.ARRAY_BUFFER,this.#Ft),t.bufferData(t.ARRAY_BUFFER,new Float32Array(b),t.STATIC_DRAW),t.enableVertexAttribArray(E);const x=t.FLOAT;t.vertexAttribPointer(E,2,x,!1,0,0),S+=b.length/2,v&&t.blendFunc(v[0],v[1]);const y=this.#Qt(T);return t.uniform4f(f,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_translation:n,u_rotation:a,u_scale:o,u_resolution:l,a_position:c,a_texCoord:u,u_image:d}=r,{width:h,height:g}=e.boundariesBox,[m,f]=(e.text,!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset),E=e.x-m,_=e.y-f-g,p=e.blendFunc?e.blendFunc:[t.ONE,t.ONE_MINUS_SRC_ALPHA],b=e.rotation||0,T=[1,1],R=E+h,A=_+g,v=[E,_,R,_,E,A,E,A,R,_,R,A];let S=0;t.useProgram(s),t.uniform2f(l,t.canvas.width,t.canvas.height),t.uniform2f(n,E,_),t.uniform2f(o,T[0],T[1]),t.uniform1f(a,b),t.bindBuffer(t.ARRAY_BUFFER,this.#Ft),t.bufferData(t.ARRAY_BUFFER,new Float32Array(v),t.STATIC_DRAW),t.enableVertexAttribArray(c);const x=t.FLOAT;t.vertexAttribPointer(c,2,x,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this.#Wt),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(u),t.vertexAttribPointer(u,2,t.FLOAT,!1,0,0),S+=6,t.blendFunc(p[0],p[1]);let y=e._textureStorage;return y||(y=new Ge(t.createTexture()),e._textureStorage=y),!0===y._isTextureRecalculated?(this.#Zt(t,y._texture,e._textureCanvas),y._isTextureRecalculated=!1):this.#qt(t,y._texture),t.uniform1i(d,y._textureIndex),t.depthMask(!1),this._render(6,t.TRIANGLES)};_bindImage=(e,t,i,s,r)=>{const[n,a]=!0===e.isOffsetTurnedOff?[0,0]:i.worldOffset,o=e.x-n,l=e.y-a;e.vertices&&this.#Bt.debug.boundaries.drawObjectBoundaries&&