mudlet-map-renderer 0.8.3-konva → 0.8.5-konva

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,5 +22,5 @@ export default class ExitRenderer {
22
22
  strokeWidth: number;
23
23
  }>[];
24
24
  renderInnerExits(room: MapData.Room): import('konva/lib/Group').Group[];
25
- renderDoor(points: number[], type: 1 | 2 | 3, color?: string): import('konva/lib/shapes/Rect').Rect;
25
+ renderDoor(points: number[], type: 1 | 2 | 3): import('konva/lib/shapes/Rect').Rect;
26
26
  }
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("konva"),K=["north","south","east","west","northeast","northwest","southeast","southwest"],k={north:"n",south:"s",east:"e",west:"w",northeast:"ne",northwest:"nw",southeast:"se",southwest:"sw",up:"u",down:"d",in:"i",out:"o"},_={north:{x:0,y:-1},south:{x:0,y:1},east:{x:1,y:0},west:{x:-1,y:0},northeast:{x:1,y:-1},northwest:{x:-1,y:-1},southeast:{x:1,y:1},southwest:{x:-1,y:1}},Y=["north","south","east","west","northeast","northwest","southeast","southwest"],Q={north:"south",south:"north",east:"west",west:"east",northeast:"southwest",northwest:"southeast",southeast:"northwest",southwest:"northeast"};function U(u){return u?Object.prototype.hasOwnProperty.call(_,u):!1}function x(u,t,e,s=1){if(!U(e))return{x:u,y:t};const i=_[e];return{x:u+i.x*s,y:t+i.y*s}}const S={OPEN_DOOR:"rgb(10, 155, 10)",CLOSED_DOOR:"rgb(226, 205, 59)",LOCKED_DOOR:"rgb(155, 10, 10)"},J={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"},tt=["up","down","in","out"];function et(u){switch(u){case 1:return S.OPEN_DOOR;case 2:return S.CLOSED_DOOR;default:return S.LOCKED_DOOR}}class st{constructor(t){this.mapReader=t}render(t){return this.renderWithColor(t,h.lineColor)}renderWithColor(t,e){return t.aDir&&t.bDir?this.renderTwoWayExit(t,e):this.renderOneWayExit(t,e)}renderTwoWayExit(t,e){const s=this.mapReader.getRoom(t.a),i=this.mapReader.getRoom(t.b);if(!s||!i||!t.aDir||!t.bDir)return;const o=new f.Group,n=[];if(n.push(...Object.values(x(s.x,s.y,t.aDir,h.roomSize/2))),n.push(...Object.values(x(i.x,i.y,t.bDir,h.roomSize/2))),s.doors[k[t.aDir]]||i.doors[k[t.bDir]]){const a=this.renderDoor(n,s.doors[k[t.aDir]]??i.doors[k[t.bDir]],e);o.add(a)}const r=new f.Line({points:n,stroke:e,strokeWidth:.025});return o.add(r),o}renderOneWayExit(t,e){const s=t.aDir?this.mapReader.getRoom(t.a):this.mapReader.getRoom(t.b),i=t.aDir?this.mapReader.getRoom(t.b):this.mapReader.getRoom(t.a),o=t.aDir?t.aDir:t.bDir;if(!s||!i)return;if(s.area!=i.area&&o)return this.renderAreaExit(s,o,e);let n={x:i.x,y:i.y};(i.area!==s.area||i.z!==s.z)&&(n=x(s.x,s.y,o,h.roomSize/2));const r=x(s.x,s.y,o,.3),a=r.x-(r.x-n.x)/2,d=r.y-(r.y-n.y)/2,g=new f.Group,c=[];c.push(...Object.values(x(s.x,s.y,o,h.roomSize/2))),c.push(n.x,n.y);const l=new f.Line({points:c,stroke:e,strokeWidth:.025,dashEnabled:!0,dash:[.1,.05]});g.add(l);const m=new f.Arrow({points:[c[0],c[1],a,d],pointerLength:.5,pointerWidth:.35,strokeWidth:.035,stroke:e,fill:e,dashEnabled:!0,dash:[.1,.05]});return g.add(m),g}renderAreaExit(t,e,s){const i=x(t.x,t.y,e,h.roomSize/2),o=x(t.x,t.y,e,h.roomSize*1.5),n=s??this.mapReader.getColorValue(t.env);return new f.Arrow({points:[i.x,i.y,o.x,o.y],pointerLength:.3,pointerWidth:.3,strokeWidth:.035,stroke:n,fill:n})}renderSpecialExits(t,e){return Object.entries(t.customLines).map(([s,i])=>{const o=[t.x,t.y];i.points.reduce((g,c)=>(g.push(c.x,-c.y),g),o);const n=i.attributes.arrow?f.Arrow:f.Line,r=e??`rgb(${i.attributes.color.r}, ${i.attributes.color.g}, ${i.attributes.color.b})`,a=new n({points:o,strokeWidth:.025,stroke:r,fill:e??`rgb(${i.attributes.color.r}, ${i.attributes.color.g} , ${i.attributes.color.b})`,pointerLength:.3,pointerWidth:.2});let d=i.attributes.style;return d==="dot line"?(a.dash([.05,.05]),a.dashOffset(.1)):d==="dash line"?a.dash([.4,.2]):d==="solid line"||d!==void 0&&console.log("Brak opisu stylu: "+d),a})}renderStubs(t,e=h.lineColor){return t.stubs.map(s=>{const i=J[s],o=x(t.x,t.y,i,h.roomSize/2),n=x(t.x,t.y,i,h.roomSize/2+.5),r=[o.x,o.y,n.x,n.y];return new f.Line({points:r,stroke:e,strokeWidth:.025})})}renderInnerExits(t){return tt.map(e=>{if(t.exits[e]){const s=new f.Group,i=new f.RegularPolygon({x:t.x,y:t.y,sides:3,fill:this.mapReader.getSymbolColor(t.env,.6),stroke:this.mapReader.getSymbolColor(t.env),strokeWidth:.025,radius:h.roomSize/5,scaleX:1.4,scaleY:.8});s.add(i);let o=t.doors[e];if(o!==void 0)switch(o){case 1:i.stroke(S.OPEN_DOOR);break;case 2:i.stroke(S.CLOSED_DOOR);break;default:i.stroke(S.LOCKED_DOOR)}switch(e){case"up":i.position(x(t.x,t.y,"south",h.roomSize/4));break;case"down":i.rotation(180),i.position(x(t.x,t.y,"north",h.roomSize/4));break;case"in":const n=i.clone();n.rotation(-90),n.position(x(t.x,t.y,"east",h.roomSize/4)),s.add(n),i.rotation(90),i.position(x(t.x,t.y,"west",h.roomSize/4));break;case"out":const r=i.clone();r.rotation(90),r.position(x(t.x,t.y,"east",h.roomSize/4)),s.add(r),i.rotation(-90),i.position(x(t.x,t.y,"west",h.roomSize/4));break}return s}}).filter(e=>e!==void 0)}renderDoor(t,e,s){const i={x:t[0]+(t[2]-t[0])/2,y:t[1]+(t[3]-t[1])/2};return new f.Rect({x:i.x-h.roomSize/4,y:i.y-h.roomSize/4,width:h.roomSize/2,height:h.roomSize/2,stroke:s??et(e),strokeWidth:.025})}}class F{constructor(t,e){this.rooms=[],this.labels=[],this.rooms=t,this.bounds=this.createBounds(),this.labels=e}getRooms(){return this.rooms}getLabels(){return this.labels}getBounds(){return this.bounds}createBounds(){return this.rooms.reduce((t,e)=>({minX:Math.min(t.minX,e.x),maxX:Math.max(t.maxX,e.x),minY:Math.min(t.minY,e.y),maxY:Math.max(t.maxY,e.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY})}}class A{constructor(t){this.planes={},this.exits=new Map,this.version=0,this.area=t,this.planes=this.createPlanes(),this.createExits()}getAreaName(){return this.area.areaName}getAreaId(){return parseInt(this.area.areaId)}getVersion(){return this.version}markDirty(){this.version++}getPlane(t){return this.planes[t]}getPlanes(){return Object.values(this.planes)}getRooms(){return this.area.rooms}getLinkExits(t){return Array.from(this.exits.values()).filter(e=>e.zIndex.includes(t))}createPlanes(){const t=this.area.rooms.reduce((e,s)=>(e[s.z]||(e[s.z]=[]),e[s.z].push(s),e),{});return Object.entries(t).reduce((e,[s,i])=>(e[+s]=new F(i,this.area.labels.filter(o=>o.Z===+s)),e),{})}createExits(){this.area.rooms.forEach(t=>{Object.entries(t.exits).filter(([e,s])=>K.indexOf(e)>-1&&!t.customLines.hasOwnProperty(k[e])).forEach(([e,s])=>this.createHalfExit(t.id,s,t.z,e))})}createHalfExit(t,e,s,i){if(t===e)return;const o=Math.min(t,e),n=Math.max(t,e),r=`${o}-${n}`;let a=this.exits.get(r);a||(a={a:o,b:n,zIndex:[s]}),o==t?a.aDir=i:a.bDir=i,a.zIndex.push(s),this.exits.set(r,a)}}class X extends F{constructor(t,e){super(t.getRooms(),t.getLabels()),this.basePlane=t,this.visitedRooms=e}getRooms(){return this.basePlane.getRooms().filter(t=>this.visitedRooms.has(t.id))}getLabels(){return this.basePlane.getLabels()}getBounds(){const t=this.getRooms();return t.length?t.reduce((e,s)=>({minX:Math.min(e.minX,s.x),maxX:Math.max(e.maxX,s.x),minY:Math.min(e.minY,s.y),maxY:Math.max(e.maxY,s.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}):this.basePlane.getBounds()}}class P extends A{constructor(t,e){super(t),this.planeCache=new WeakMap,this.visitedRooms=e instanceof Set?e:new Set(e??[]),this.areaRoomIds=new Set(t.rooms.map(s=>s.id))}getPlane(t){const e=super.getPlane(t);if(!e)return e;let s=this.planeCache.get(e);return s||(s=new X(e,this.visitedRooms),this.planeCache.set(e,s)),s}getPlanes(){return super.getPlanes().map(t=>{let e=this.planeCache.get(t);return e||(e=new X(t,this.visitedRooms),this.planeCache.set(t,e)),e})}getLinkExits(t){return super.getLinkExits(t).filter(e=>this.visitedRooms.has(e.a)||this.visitedRooms.has(e.b))}getVisitedRoomCount(){return super.getRooms().reduce((t,e)=>t+(this.visitedRooms.has(e.id)?1:0),0)}getTotalRoomCount(){return this.areaRoomIds.size}hasVisitedRoom(t){return this.areaRoomIds.has(t)&&this.visitedRooms.has(t)}getVisitedRoomIds(){return super.getRooms().filter(t=>this.visitedRooms.has(t.id)).map(t=>t.id)}addVisitedRoom(t){const e=this.visitedRooms.has(t);this.visitedRooms.add(t);const s=!e&&this.areaRoomIds.has(t);return s&&this.markDirty(),s}addVisitedRooms(t){let e=0;for(const s of t){const i=this.visitedRooms.has(s);this.visitedRooms.add(s),!i&&this.areaRoomIds.has(s)&&e++}return e>0&&this.markDirty(),e}}class it{constructor(t,e){this.paths=[],this.mapReader=t,this.overlayLayer=e}renderPath(t,e,s,i="#66E64D"){if(e===void 0||s===void 0)return;const o=t.map(c=>this.mapReader.getRoom(c)).filter(c=>c!==void 0),n=[];let r=null;const a=()=>{r&&(r.length<4&&n.pop(),r=null)},d=()=>(r||(r=[],n.push(r)),r);o.forEach((c,l)=>{if(!this.isRoomVisible(c,e,s))return;const m=l>0?o[l-1]:void 0,R=l<o.length-1?o[l+1]:void 0;if(this.isRoomVisible(m,e,s))d();else{a();const b=d();if(m){const y=this.getDirectionTowards(c,m);if(y){const p=x(c.x,c.y,y,h.roomSize);b.push(p.x,p.y)}}}if(r==null||r.push(c.x,c.y),!this.isRoomVisible(R,e,s)&&R){const b=this.getDirectionTowards(c,R);if(b){const y=x(c.x,c.y,b,h.roomSize);r==null||r.push(y.x,y.y)}a()}}),a();const g=n.filter(c=>c.length>=4).map(c=>new f.Line({points:c,stroke:i,strokeWidth:.1}));return g.forEach(c=>{this.overlayLayer.add(c),this.paths.push(c)}),g[0]}clearPaths(){this.paths.forEach(t=>{t.destroy()}),this.paths=[]}isRoomVisible(t,e,s){return t?t.area===e&&t.z===s:!1}getDirectionTowards(t,e){for(const s of Y)if(t.exits[s]===e.id)return s;for(const s of Y)if(e.exits[s]===t.id)return Q[s]}}const G=.6,L=75,rt="rgb(225, 255, 225)",I="rgb(120, 72, 0)",D=class D{};D.roomSize=G,D.lineColor=rt,D.instantMapMove=!1,D.highlightCurrentRoom=!0,D.cullingEnabled=!0,D.cullingBounds=null,D.labelRenderMode="image";let h=D;class ot{constructor(t,e){this.highlights=new Map,this.currentZoom=1,this.currentRoomOverlay=[],this.roomNodes=new Map,this.standaloneExitNodes=[],this.cullingScheduled=!1,this.stage=new f.Stage({container:t,width:t.clientWidth,height:t.clientHeight,draggable:!0}),window.addEventListener("resize",()=>{this.onResize(t)}),t.addEventListener("resize",()=>{this.onResize(t)}),this.linkLayer=new f.Layer({listening:!1}),this.stage.add(this.linkLayer),this.roomLayer=new f.Layer,this.stage.add(this.roomLayer),this.overlayLayer=new f.Layer({listening:!1}),this.stage.add(this.overlayLayer),this.positionLayer=new f.Layer({listening:!1}),this.stage.add(this.positionLayer),this.mapReader=e,this.exitRenderer=new st(e),this.pathRenderer=new it(e,this.overlayLayer),this.initScaling(1.1),this.stage.on("dragmove",()=>this.scheduleRoomCulling()),this.stage.on("dragend",()=>this.scheduleRoomCulling())}onResize(t){this.stage.width(t.clientWidth),this.stage.height(t.clientHeight),this.currentRoomId&&this.centerOnRoom(this.mapReader.getRoom(this.currentRoomId),!1),this.stage.batchDraw(),this.scheduleRoomCulling()}initScaling(t){f.hitOnDragEnabled=!0;let e,s=!1,i=!1;this.stage.on("touchstart",o=>{const n=o.evt.touches;n&&n.length>1?(i=!0,this.stage.isDragging()&&(this.stage.stopDrag(),s=!0),this.stage.draggable(!1)):(i=!1,this.stage.draggable(!0))}),this.stage.on("touchend touchcancel",o=>{e=void 0;const n=o.evt.touches;(!n||n.length<=1)&&(i=!1,this.stage.draggable(!0))}),this.stage.on("wheel",o=>{o.evt.preventDefault();const n=this.stage.scaleX(),r=this.stage.getPointerPosition();if(!r)return;const a={x:(r.x-this.stage.x())/n,y:(r.y-this.stage.y())/n};let d=o.evt.deltaY>0?-1:1;o.evt.ctrlKey&&(d=-d);const g=d>0?this.currentZoom*t:this.currentZoom/t,c=g*L,l=this.setZoom(g),m={x:r.x-a.x*c,y:r.y-a.y*c};this.stage.position(m),this.scheduleRoomCulling(),l&&this.emitZoomChangeEvent()}),this.stage.on("touchmove",o=>{const n=o.evt.touches,r=n==null?void 0:n[0],a=n==null?void 0:n[1];if(a||i&&(i=!1,this.stage.draggable(!0)),r&&!a&&s&&!this.stage.isDragging()&&(this.stage.startDrag(),s=!1),!r||!a){e=void 0;return}o.evt.preventDefault(),this.stage.isDragging()&&(this.stage.stopDrag(),s=!0),i||(i=!0,this.stage.draggable(!1));const d=this.stage.container().getBoundingClientRect(),g={x:r.clientX-d.left,y:r.clientY-d.top},c={x:a.clientX-d.left,y:a.clientY-d.top},l=Math.hypot(g.x-c.x,g.y-c.y);if(e===void 0){e=l;return}if(e===0)return;const m=this.stage.scaleX(),R=this.stage.x(),v=this.stage.y(),E={x:this.stage.width()/2,y:this.stage.height()/2},b={x:(E.x-R)/m,y:(E.y-v)/m},y=this.currentZoom*(l/e),p=this.setZoom(y),w=this.stage.scaleX(),C={x:E.x-b.x*w,y:E.y-b.y*w};this.stage.position(C),this.stage.batchDraw(),this.scheduleRoomCulling(),e=l,p&&this.emitZoomChangeEvent()})}drawArea(t,e){const s=this.mapReader.getArea(t);if(!s)return;const i=s.getPlane(e);i&&(this.currentArea=t,this.currentAreaInstance=s,this.currentZIndex=e,this.currentAreaVersion=s.getVersion(),this.clearCurrentRoomOverlay(),this.roomLayer.destroyChildren(),this.linkLayer.destroyChildren(),this.roomNodes.clear(),this.standaloneExitNodes=[],this.stage.scale({x:L*this.currentZoom,y:L*this.currentZoom}),this.renderLabels(i.getLabels()),this.renderExits(s.getLinkExits(e)),this.renderRooms(i.getRooms()??[]),this.refreshHighlights(),this.stage.batchDraw(),this.scheduleRoomCulling())}emitRoomContextEvent(t,e,s){const i=this.stage.container(),o=i.getBoundingClientRect(),n={roomId:t,position:{x:e-o.left,y:s-o.top}},r=new CustomEvent("roomcontextmenu",{detail:n});i.dispatchEvent(r)}emitZoomChangeEvent(){const t=new CustomEvent("zoom",{detail:{zoom:this.currentZoom}});this.stage.container().dispatchEvent(t)}setZoom(t){return this.currentZoom===t?!1:(this.currentZoom=t,this.stage.scale({x:L*t,y:L*t}),this.scheduleRoomCulling(),!0)}getZoom(){return this.currentZoom}getCurrentArea(){return this.currentArea?this.mapReader.getArea(this.currentArea):void 0}setPosition(t){const e=this.mapReader.getRoom(t);if(!e)return;const s=this.mapReader.getArea(e.area),i=s==null?void 0:s.getVersion();let o=this.currentArea!==e.area||this.currentZIndex!==e.z;(this.currentArea!==e.area||this.currentZIndex!==e.z||i!==void 0&&this.currentAreaVersion!==i||s!==void 0&&this.currentAreaInstance!==s)&&this.drawArea(e.area,e.z),this.positionRender||(this.positionRender=new f.Circle({x:e.x,y:e.y,radius:G*.85,stroke:"rgb(0, 229, 178)",strokeWidth:.1,dash:[.05,.05],dashEnabled:!0}),this.positionLayer.add(this.positionRender)),this.centerOnRoom(e,o),this.updateCurrentRoomOverlay(e)}renderPath(t,e){return this.pathRenderer.renderPath(t,this.currentArea,this.currentZIndex,e)}clearPaths(){this.pathRenderer.clearPaths()}renderHighlight(t,e){const s=this.mapReader.getRoom(t);if(!s)return;const i=this.highlights.get(t);i!=null&&i.shape&&(i.shape.destroy(),delete i.shape);const o={color:e,area:s.area,z:s.z};if(this.highlights.set(t,o),s.area===this.currentArea&&s.z===this.currentZIndex){const n=this.createHighlightShape(s,e);return this.overlayLayer.add(n),o.shape=n,this.overlayLayer.batchDraw(),n}return o.shape}clearHighlights(){this.highlights.forEach(({shape:t})=>t==null?void 0:t.destroy()),this.highlights.clear(),this.overlayLayer.batchDraw()}refreshHighlights(){this.highlights.forEach((t,e)=>{var o;if((o=t.shape)==null||o.destroy(),delete t.shape,t.area!==this.currentArea||t.z!==this.currentZIndex)return;const s=this.mapReader.getRoom(e);if(!s)return;const i=this.createHighlightShape(s,t.color);this.overlayLayer.add(i),t.shape=i}),this.overlayLayer.batchDraw()}createHighlightShape(t,e){return new f.Circle({x:t.x,y:t.y,radius:h.roomSize*.9,stroke:e,strokeWidth:.15,dash:[.1,.05],dashEnabled:!0,listening:!1})}centerOnRoom(t,e=!1){var d;this.currentRoomId=t.id;const s={x:t.x,y:t.y};(d=this.positionRender)==null||d.position(t);const o=this.stage.getAbsoluteTransform().point(s),n={x:this.stage.width()/2,y:this.stage.height()/2},r=n.x-o.x,a=n.y-o.y;this.currentTransition&&(this.currentTransition.pause(),this.currentTransition.destroy(),delete this.currentTransition),e||h.instantMapMove?(this.stage.position({x:this.stage.x()+r,y:this.stage.y()+a}),this.scheduleRoomCulling()):(this.currentTransition=new f.Tween({node:this.stage,x:this.stage.x()+r,y:this.stage.y()+a,duration:.2,easing:f.Easings.EaseInOut,onUpdate:()=>this.scheduleRoomCulling(),onFinish:()=>this.scheduleRoomCulling()}),this.currentTransition.play())}renderRooms(t){t.forEach(e=>{const s=new f.Group({x:e.x-h.roomSize/2,y:e.y-h.roomSize/2}),i=new f.Rect({x:0,y:0,width:h.roomSize,height:h.roomSize,fill:this.mapReader.getColorValue(e.env),strokeWidth:.025,stroke:h.lineColor}),o=(l,m)=>this.emitRoomContextEvent(e.id,l,m);s.on("mouseenter",()=>{this.stage.container().style.cursor="pointer"}),s.on("mouseleave",()=>{this.stage.container().style.cursor="auto"}),s.on("contextmenu",l=>{l.evt.preventDefault();const m=l.evt;o(m.clientX,m.clientY)});let n,r,a;const d=()=>{a!==void 0&&(this.stage.draggable(a),a=void 0)},g=()=>{n!==void 0&&(window.clearTimeout(n),n=void 0),r=void 0,d()};s.on("touchstart",l=>{var R;if(g(),l.evt.touches&&l.evt.touches.length>1)return;const m=(R=l.evt.touches)==null?void 0:R[0];m&&(r={clientX:m.clientX,clientY:m.clientY},a=this.stage.draggable(),this.stage.draggable(!1),n=window.setTimeout(()=>{r&&o(r.clientX,r.clientY),g()},500))}),s.on("touchend",g),s.on("touchmove",l=>{var y;if(!r)return;const m=(y=l.evt.touches)==null?void 0:y[0];if(!m){g();return}const R=m.clientX-r.clientX,v=m.clientY-r.clientY,E=R*R+v*v,b=10;if(E>b*b){const p=a;g(),p&&this.stage.startDrag()}}),s.on("touchcancel",g),s.add(i),this.renderSymbol(e,s),this.roomLayer.add(s);const c=[];this.exitRenderer.renderSpecialExits(e).forEach(l=>{this.linkLayer.add(l),c.push(l)}),this.exitRenderer.renderStubs(e).forEach(l=>{this.linkLayer.add(l),c.push(l)}),this.exitRenderer.renderInnerExits(e).forEach(l=>{this.roomLayer.add(l)}),this.roomNodes.set(e.id,{room:e,group:s,linkNodes:c})})}scheduleRoomCulling(){this.cullingScheduled||(this.cullingScheduled=!0,window.requestAnimationFrame(()=>{this.cullingScheduled=!1,this.updateRoomCulling()}))}updateRoomCulling(){if(this.roomNodes.size===0&&this.standaloneExitNodes.length===0)return;const t=this.stage.scaleX();if(!t)return;const e=this.stage.position(),s=h.roomSize/2,i=h.cullingBounds,o=i?i.x:0,n=i?i.x+i.width:this.stage.width(),r=i?i.y:0,a=i?i.y+i.height:this.stage.height(),d=Math.min(o,n),g=Math.max(o,n),c=Math.min(r,a),l=Math.max(r,a),m=(d-e.x)/t,R=(g-e.x)/t,v=(c-e.y)/t,E=(l-e.y)/t;let b=!1,y=!1;if(!h.cullingEnabled){this.roomNodes.forEach(({group:p,linkNodes:w})=>{p.visible()||(p.visible(!0),b=!0),w.forEach(C=>{C.visible()||(C.visible(!0),y=!0)})}),this.standaloneExitNodes.forEach(p=>{p.visible()||(p.visible(!0),y=!0)}),b&&this.roomLayer.batchDraw(),y&&this.linkLayer.batchDraw();return}this.roomNodes.forEach(({room:p,group:w,linkNodes:C})=>{const V=p.x-s,z=p.x+s,N=p.y-s,O=p.y+s,M=z>=m&&V<=R&&O>=v&&N<=E;w.visible()!==M&&(w.visible(M),b=!0),C.forEach(T=>{T.visible()!==M&&(T.visible(M),y=!0)})}),this.standaloneExitNodes.forEach(p=>{const w=p.getClientRect({relativeTo:this.linkLayer}),C=w.x,V=w.x+w.width,z=w.y,N=w.y+w.height,O=V>=m&&C<=R&&N>=v&&z<=E;p.visible()!==O&&(p.visible(O),y=!0)}),b&&this.roomLayer.batchDraw(),y&&this.linkLayer.batchDraw()}clearCurrentRoomOverlay(){this.currentRoomOverlay.forEach(t=>t.destroy()),this.currentRoomOverlay=[],this.overlayLayer.batchDraw()}updateCurrentRoomOverlay(t){if(this.clearCurrentRoomOverlay(),t.area!==this.currentArea||t.z!==this.currentZIndex){this.overlayLayer.batchDraw();return}const e=new Map;e.set(t.id,t);const s=[],i=this.currentAreaInstance instanceof P?this.currentAreaInstance:void 0;this.currentAreaInstance&&this.currentZIndex!==void 0&&this.currentAreaInstance.getLinkExits(this.currentZIndex).filter(a=>a.a===t.id||a.b===t.id).forEach(a=>{const d=h.highlightCurrentRoom?this.exitRenderer.renderWithColor(a,I):this.exitRenderer.render(a);d&&s.push(d)});const o=h.highlightCurrentRoom?I:void 0;this.exitRenderer.renderSpecialExits(t,o).forEach(r=>{s.push(r)}),(h.highlightCurrentRoom?this.exitRenderer.renderStubs(t,I):this.exitRenderer.renderStubs(t)).forEach(r=>{s.push(r)}),[...Object.values(t.exits),...Object.values(t.specialExits)].forEach(r=>{const a=this.mapReader.getRoom(r),d=!i||i.hasVisitedRoom(r);a&&a.area===this.currentArea&&a.z===this.currentZIndex&&d&&e.set(r,a)}),s.forEach(r=>{this.overlayLayer.add(r),this.currentRoomOverlay.push(r)}),e.forEach((r,a)=>{const d=a===t.id,g=this.createOverlayRoomGroup(r,{stroke:d&&h.highlightCurrentRoom?I:h.lineColor});this.overlayLayer.add(g),this.currentRoomOverlay.push(g),this.exitRenderer.renderInnerExits(r).forEach(c=>{this.overlayLayer.add(c),this.currentRoomOverlay.push(c)})}),this.overlayLayer.batchDraw()}createOverlayRoomGroup(t,e){const s=new f.Group({x:t.x-h.roomSize/2,y:t.y-h.roomSize/2,listening:!1}),i=new f.Rect({x:0,y:0,width:h.roomSize,height:h.roomSize,fill:this.mapReader.getColorValue(t.env),stroke:e.stroke,strokeWidth:.025,strokeEnabled:!0});return s.add(i),this.renderSymbol(t,s),s}renderSymbol(t,e){if(t.roomChar!==void 0){const s=new f.Text({x:0,y:0,text:t.roomChar,fontSize:.45,fontStyle:"bold",fill:this.mapReader.getSymbolColor(t.env),align:"center",verticalAlign:"middle",width:h.roomSize,height:h.roomSize});e.add(s)}}renderExits(t){t.forEach(e=>{const s=this.exitRenderer.render(e);s&&(this.linkLayer.add(s),this.standaloneExitNodes.push(s))})}renderLabels(t){t.forEach(e=>{if(h.labelRenderMode==="image"){if(!e.pixMap)return;const s=new Image;s.src=`data:image/png;base64,${e.pixMap}`;const i=new f.Image({x:e.X,y:-e.Y,width:e.Width,height:e.Height,image:s,listening:!1});this.linkLayer.add(i);return}this.renderLabelAsData(e)})}renderLabelAsData(t){var r;const e=new f.Group({listening:!1}),s=new f.Rect({x:t.X,y:-t.Y,width:t.Width,height:t.Height,listening:!1});(((r=t.BgColor)==null?void 0:r.alpha)??0)>0&&!h.transparentLabels?s.fill(this.getLabelColor(t.BgColor)):s.fillEnabled(!1),e.add(s);const i=Math.min(.75,t.Width/Math.max(t.Text.length/2,1)),o=Math.max(.1,Math.min(i,Math.max(t.Height*.9,.1))),n=new f.Text({x:t.X,y:-t.Y,width:t.Width,height:t.Height,text:t.Text,fontSize:o,fillEnabled:!0,fill:this.getLabelColor(t.FgColor),align:"center",verticalAlign:"middle",listening:!1});e.add(n),this.linkLayer.add(e)}getLabelColor(t){const e=((t==null?void 0:t.alpha)??255)/255,s=i=>Math.min(255,Math.max(0,i??0));return`rgba(${s(t==null?void 0:t.r)}, ${s(t==null?void 0:t.g)}, ${s(t==null?void 0:t.b)}, ${e})`}}const W={rgbValue:"rgb(114, 1, 0)",symbolColor:[225,225,225]};function $(u){const t=u[0]/255,e=u[1]/255,s=u[2]/255,i=Math.max(t,e,s),o=Math.min(t,e,s);return(i+o)/2}class nt{constructor(t,e){this.rooms={},this.areas={},this.areaSources={},this.explorationEnabled=!1,this.colors={},t.forEach(s=>{s.rooms.forEach(o=>{o.y=-o.y,this.rooms[o.id]=o});const i=parseInt(s.areaId);this.areas[i]=new A(s),this.areaSources[i]=s}),this.colors=e.reduce((s,i)=>({...s,[i.envId]:{rgb:i.colors,rgbValue:`rgb(${i.colors.join(",")}`,symbolColor:$(i.colors)>.41?[25,25,25]:[225,255,255],symbolColorValue:$(i.colors)>.41?"rgb(25,25,25)":"rgb(225,255,255)"}}),{})}getArea(t){return this.areas[t]}getExplorationArea(t){const e=this.areas[t];if(e instanceof P)return e}getAreas(){return Object.values(this.areas)}getRooms(){return Object.values(this.rooms)}getRoom(t){return this.rooms[t]}ensureVisitedRooms(){return this.visitedRooms||(this.visitedRooms=new Set),this.visitedRooms}applyExplorationDecoration(){this.visitedRooms&&Object.entries(this.areaSources).forEach(([t,e])=>{const s=parseInt(t,10);this.areas[s]=new P(e,this.visitedRooms)})}decorateWithExploration(t){return t!==void 0?this.setVisitedRooms(t):this.ensureVisitedRooms(),this.applyExplorationDecoration(),this.explorationEnabled=!0,this.visitedRooms}getVisitedRooms(){return this.visitedRooms}clearExplorationDecoration(){Object.entries(this.areaSources).forEach(([t,e])=>{const s=parseInt(t,10);this.areas[s]=new A(e)}),this.explorationEnabled=!1}isExplorationEnabled(){return this.explorationEnabled}setVisitedRooms(t){return this.visitedRooms=t instanceof Set?t:new Set(t),this.explorationEnabled&&this.applyExplorationDecoration(),this.visitedRooms}addVisitedRoom(t){if(this.explorationEnabled){const i=this.getRoom(t);if(i){const o=this.getExplorationArea(i.area);if(o)return o.addVisitedRoom(t)}}const e=this.ensureVisitedRooms(),s=e.has(t);return e.add(t),!s}addVisitedRooms(t){const e=this.ensureVisitedRooms();let s=0;for(const i of t){if(this.explorationEnabled){const n=this.getRoom(i);if(n){const r=this.getExplorationArea(n.area);if(r){r.addVisitedRoom(i)&&s++;continue}}}const o=e.has(i);e.add(i),o||s++}return s}hasVisitedRoom(t){var e;return((e=this.visitedRooms)==null?void 0:e.has(t))??!1}getColorValue(t){var e;return((e=this.colors[t])==null?void 0:e.rgbValue)??W.rgbValue}getSymbolColor(t,e){var n;const s=((n=this.colors[t])==null?void 0:n.symbolColor)??W.symbolColor,i=Math.min(Math.max(e??1,0),1),o=s.join(",");return i!=1?`rgba(${o}, ${i})`:`rgba(${o})`}}function at(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}class ht{constructor(){this.keys=new Set,this.queue=[]}sort(){this.queue.sort((t,e)=>t.priority-e.priority)}set(t,e){const s=Number(e);if(isNaN(s))throw new TypeError('"priority" must be a number');return this.keys.has(t)?this.queue.map(i=>(i.key===t&&Object.assign(i,{priority:s}),i)):(this.keys.add(t),this.queue.push({key:t,priority:s})),this.sort(),this.queue.length}next(){const t=this.queue.shift();return this.keys.delete(t.key),t}isEmpty(){return this.queue.length===0}has(t){return this.keys.has(t)}get(t){return this.queue.find(e=>e.key===t)}}var ct=ht;function B(u,t){const e=new Map;for(const[s,i]of u)s!==t&&i instanceof Map?e.set(s,B(i,t)):s!==t&&e.set(s,i);return e}var lt=B;function ut(u){const t=Number(u);return!(isNaN(t)||t<=0)}function H(u){const t=new Map;return Object.keys(u).forEach(s=>{const i=u[s];if(i!==null&&typeof i=="object"&&!Array.isArray(i))return t.set(s,H(i));if(!ut(i))throw new Error(`Could not add node at key "${s}", make sure it's a valid node`,i);return t.set(s,Number(i))}),t}var dt=H;function q(u){if(!(u instanceof Map))throw new Error(`Invalid graph: Expected Map instead found ${typeof u}`);u.forEach((t,e)=>{if(typeof t=="object"&&t instanceof Map){q(t);return}if(typeof t!="number"||t<=0)throw new Error(`Values must be numbers greater than 0. Found value ${t} at ${e}`)})}var gt=q;const mt=ct,ft=lt,Z=dt,j=gt;class pt{constructor(t){t instanceof Map?(j(t),this.graph=t):t?this.graph=Z(t):this.graph=new Map}addNode(t,e){let s;return e instanceof Map?(j(e),s=e):s=Z(e),this.graph.set(t,s),this}addVertex(t,e){return this.addNode(t,e)}removeNode(t){return this.graph=ft(this.graph,t),this}path(t,e,s={}){if(!this.graph.size)return s.cost?{path:null,cost:0}:null;const i=new Set,o=new mt,n=new Map;let r=[],a=0,d=[];if(s.avoid&&(d=[].concat(s.avoid)),d.includes(t))throw new Error(`Starting node (${t}) cannot be avoided`);if(d.includes(e))throw new Error(`Ending node (${e}) cannot be avoided`);for(o.set(t,0);!o.isEmpty();){const g=o.next();if(g.key===e){a=g.priority;let l=g.key;for(;n.has(l);)r.push(l),l=n.get(l);break}i.add(g.key),(this.graph.get(g.key)||new Map).forEach((l,m)=>{if(i.has(m)||d.includes(m))return null;if(!o.has(m))return n.set(m,g.key),o.set(m,g.priority+l);const R=o.get(m).priority,v=g.priority+l;return v<R?(n.set(m,g.key),o.set(m,v)):null})}return r.length?(s.trim?r.shift():r=r.concat([t]),s.reverse||(r=r.reverse()),s.cost?{path:r,cost:a}:r):s.cost?{path:null,cost:0}:null}shortestPath(...t){return this.path(...t)}}var yt=pt;const xt=at(yt),Rt={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"};class bt{constructor(t){this.cache=new Map,this.mapReader=t,this.graph=this.buildGraph()}buildGraph(){const t={};return this.mapReader.getRooms().forEach(e=>{const s={},i=new Set((e.exitLocks??[]).map(n=>Rt[n]).filter(n=>!!n)),o=new Set(e.mSpecialExitLocks??[]);Object.entries(e.exits??{}).forEach(([n,r])=>{i.has(n)||this.mapReader.getRoom(r)&&(s[r.toString()]=1)}),Object.values(e.specialExits??{}).forEach(n=>{o.has(n)||this.mapReader.getRoom(n)&&(s[n.toString()]=1)}),t[e.id.toString()]=s}),new xt(t)}findPath(t,e){const s=`${t}->${e}`;if(this.cache.has(s))return this.cache.get(s);if(t===e){const r=this.mapReader.getRoom(t)?[t]:null;return this.cache.set(s,r),r}if(!this.mapReader.getRoom(t)||!this.mapReader.getRoom(e))return this.cache.set(s,null),null;const i=this.graph.path(t.toString(),e.toString()),o=Array.isArray(i)?i:i==null?void 0:i.path,n=o?o.map(r=>Number(r)):null;return this.cache.set(s,n),n}}exports.ExplorationArea=P;exports.MapReader=nt;exports.PathFinder=bt;exports.Renderer=ot;exports.Settings=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("konva"),Y=["north","south","east","west","northeast","northwest","southeast","southwest"],L={north:"n",south:"s",east:"e",west:"w",northeast:"ne",northwest:"nw",southeast:"se",southwest:"sw",up:"u",down:"d",in:"i",out:"o"},F={north:{x:0,y:-1},south:{x:0,y:1},east:{x:1,y:0},west:{x:-1,y:0},northeast:{x:1,y:-1},northwest:{x:-1,y:-1},southeast:{x:1,y:1},southwest:{x:-1,y:1}},X=["north","south","east","west","northeast","northwest","southeast","southwest"],Q={north:"south",south:"north",east:"west",west:"east",northeast:"southwest",northwest:"southeast",southeast:"northwest",southwest:"northeast"};function U(u){return u?Object.prototype.hasOwnProperty.call(F,u):!1}function x(u,t,e,s=1){if(!U(e))return{x:u,y:t};const i=F[e];return{x:u+i.x*s,y:t+i.y*s}}const S={OPEN_DOOR:"rgb(10, 155, 10)",CLOSED_DOOR:"rgb(226, 205, 59)",LOCKED_DOOR:"rgb(155, 10, 10)",ONE_WAY_FILL:"rgb(155, 10, 10)"},J={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"},tt=["up","down","in","out"];function et(u){switch(u){case 1:return S.OPEN_DOOR;case 2:return S.CLOSED_DOOR;default:return S.LOCKED_DOOR}}class st{constructor(t){this.mapReader=t}render(t){return this.renderWithColor(t,h.lineColor)}renderWithColor(t,e){return t.aDir&&t.bDir?this.renderTwoWayExit(t,e):this.renderOneWayExit(t,e)}renderTwoWayExit(t,e){const s=this.mapReader.getRoom(t.a),i=this.mapReader.getRoom(t.b);if(!s||!i||!t.aDir||!t.bDir||!Y.includes(t.aDir)||!Y.includes(t.bDir)||s.customLines[L[t.aDir]]&&i.customLines[L[t.bDir]])return;const o=new f.Group,n=[];if(n.push(...Object.values(x(s.x,s.y,t.aDir,h.roomSize/2))),n.push(...Object.values(x(i.x,i.y,t.bDir,h.roomSize/2))),s.doors[L[t.aDir]]||i.doors[L[t.bDir]]){const a=this.renderDoor(n,s.doors[L[t.aDir]]??i.doors[L[t.bDir]]);o.add(a)}const r=new f.Line({points:n,stroke:e,strokeWidth:.025});return o.add(r),o}renderOneWayExit(t,e){const s=t.aDir?this.mapReader.getRoom(t.a):this.mapReader.getRoom(t.b),i=t.aDir?this.mapReader.getRoom(t.b):this.mapReader.getRoom(t.a),o=t.aDir?t.aDir:t.bDir;if(!s||!i)return;if(s.area!=i.area&&o)return this.renderAreaExit(s,o,e);let n={x:i.x,y:i.y};(i.area!==s.area||i.z!==s.z)&&(n=x(s.x,s.y,o,h.roomSize/2));const r=x(s.x,s.y,o,.3),a=r.x-(r.x-n.x)/2,d=r.y-(r.y-n.y)/2,g=new f.Group,c=[];c.push(...Object.values(x(s.x,s.y,o,h.roomSize/2))),c.push(n.x,n.y);const l=new f.Line({points:c,stroke:e,strokeWidth:.025,dashEnabled:!0,dash:[.1,.05]});g.add(l);const m=new f.Arrow({points:[c[0],c[1],a,d],pointerLength:.5,pointerWidth:.35,strokeWidth:.035,stroke:e,fill:S.ONE_WAY_FILL,dashEnabled:!0,dash:[.1,.05]});return g.add(m),g}renderAreaExit(t,e,s){const i=x(t.x,t.y,e,h.roomSize/2),o=x(t.x,t.y,e,h.roomSize*1.5),n=s??this.mapReader.getColorValue(t.env);return new f.Arrow({points:[i.x,i.y,o.x,o.y],pointerLength:.3,pointerWidth:.3,strokeWidth:.035,stroke:n,fill:n})}renderSpecialExits(t,e){return Object.entries(t.customLines).map(([s,i])=>{const o=[t.x,t.y];i.points.reduce((g,c)=>(g.push(c.x,-c.y),g),o);const n=i.attributes.arrow?f.Arrow:f.Line,r=e??`rgb(${i.attributes.color.r}, ${i.attributes.color.g}, ${i.attributes.color.b})`,a=new n({points:o,strokeWidth:.025,stroke:r,fill:e??`rgb(${i.attributes.color.r}, ${i.attributes.color.g} , ${i.attributes.color.b})`,pointerLength:.3,pointerWidth:.2});let d=i.attributes.style;return d==="dot line"?(a.dash([.05,.05]),a.dashOffset(.1)):d==="dash line"?a.dash([.4,.2]):d==="solid line"||d!==void 0&&console.log("Brak opisu stylu: "+d),a})}renderStubs(t,e=h.lineColor){return t.stubs.map(s=>{const i=J[s],o=x(t.x,t.y,i,h.roomSize/2),n=x(t.x,t.y,i,h.roomSize/2+.5),r=[o.x,o.y,n.x,n.y];return new f.Line({points:r,stroke:e,strokeWidth:.025})})}renderInnerExits(t){return tt.map(e=>{if(t.exits[e]){const s=new f.Group,i=new f.RegularPolygon({x:t.x,y:t.y,sides:3,fill:this.mapReader.getSymbolColor(t.env,.6),stroke:this.mapReader.getSymbolColor(t.env),strokeWidth:.025,radius:h.roomSize/5,scaleX:1.4,scaleY:.8});s.add(i);let o=t.doors[e];if(o!==void 0)switch(o){case 1:i.stroke(S.OPEN_DOOR);break;case 2:i.stroke(S.CLOSED_DOOR);break;default:i.stroke(S.LOCKED_DOOR)}switch(e){case"up":i.position(x(t.x,t.y,"south",h.roomSize/4));break;case"down":i.rotation(180),i.position(x(t.x,t.y,"north",h.roomSize/4));break;case"in":const n=i.clone();n.rotation(-90),n.position(x(t.x,t.y,"east",h.roomSize/4)),s.add(n),i.rotation(90),i.position(x(t.x,t.y,"west",h.roomSize/4));break;case"out":const r=i.clone();r.rotation(90),r.position(x(t.x,t.y,"east",h.roomSize/4)),s.add(r),i.rotation(-90),i.position(x(t.x,t.y,"west",h.roomSize/4));break}return s}}).filter(e=>e!==void 0)}renderDoor(t,e){const s={x:t[0]+(t[2]-t[0])/2,y:t[1]+(t[3]-t[1])/2};return new f.Rect({x:s.x-h.roomSize/4,y:s.y-h.roomSize/4,width:h.roomSize/2,height:h.roomSize/2,stroke:et(e),strokeWidth:.025})}}class G{constructor(t,e){this.rooms=[],this.labels=[],this.rooms=t,this.bounds=this.createBounds(),this.labels=e}getRooms(){return this.rooms}getLabels(){return this.labels}getBounds(){return this.bounds}createBounds(){return this.rooms.reduce((t,e)=>({minX:Math.min(t.minX,e.x),maxX:Math.max(t.maxX,e.x),minY:Math.min(t.minY,e.y),maxY:Math.max(t.maxY,e.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY})}}class A{constructor(t){this.planes={},this.exits=new Map,this.version=0,this.area=t,this.planes=this.createPlanes(),this.createExits()}getAreaName(){return this.area.areaName}getAreaId(){return parseInt(this.area.areaId)}getVersion(){return this.version}markDirty(){this.version++}getPlane(t){return this.planes[t]}getPlanes(){return Object.values(this.planes)}getRooms(){return this.area.rooms}getLinkExits(t){return Array.from(this.exits.values()).filter(e=>e.zIndex.includes(t))}createPlanes(){const t=this.area.rooms.reduce((e,s)=>(e[s.z]||(e[s.z]=[]),e[s.z].push(s),e),{});return Object.entries(t).reduce((e,[s,i])=>(e[+s]=new G(i,this.area.labels.filter(o=>o.Z===+s)),e),{})}createExits(){this.area.rooms.forEach(t=>{Object.entries(t.specialExits).forEach(([e,s])=>this.createHalfExit(t.id,s,t.z,e)),Object.entries(t.exits).forEach(([e,s])=>this.createHalfExit(t.id,s,t.z,e))})}createHalfExit(t,e,s,i){if(t===e)return;const o=Math.min(t,e),n=Math.max(t,e),r=`${o}-${n}`;let a=this.exits.get(r);a||(a={a:o,b:n,zIndex:[s]}),o==t?a.aDir=i:a.bDir=i,a.zIndex.push(s),this.exits.set(r,a)}}class W extends G{constructor(t,e){super(t.getRooms(),t.getLabels()),this.basePlane=t,this.visitedRooms=e}getRooms(){return this.basePlane.getRooms().filter(t=>this.visitedRooms.has(t.id))}getLabels(){return this.basePlane.getLabels()}getBounds(){const t=this.getRooms();return t.length?t.reduce((e,s)=>({minX:Math.min(e.minX,s.x),maxX:Math.max(e.maxX,s.x),minY:Math.min(e.minY,s.y),maxY:Math.max(e.maxY,s.y)}),{minX:Number.POSITIVE_INFINITY,maxX:Number.NEGATIVE_INFINITY,minY:Number.POSITIVE_INFINITY,maxY:Number.NEGATIVE_INFINITY}):this.basePlane.getBounds()}}class z extends A{constructor(t,e){super(t),this.planeCache=new WeakMap,this.visitedRooms=e instanceof Set?e:new Set(e??[]),this.areaRoomIds=new Set(t.rooms.map(s=>s.id))}getPlane(t){const e=super.getPlane(t);if(!e)return e;let s=this.planeCache.get(e);return s||(s=new W(e,this.visitedRooms),this.planeCache.set(e,s)),s}getPlanes(){return super.getPlanes().map(t=>{let e=this.planeCache.get(t);return e||(e=new W(t,this.visitedRooms),this.planeCache.set(t,e)),e})}getLinkExits(t){return super.getLinkExits(t).filter(e=>this.visitedRooms.has(e.a)||this.visitedRooms.has(e.b))}getVisitedRoomCount(){return super.getRooms().reduce((t,e)=>t+(this.visitedRooms.has(e.id)?1:0),0)}getTotalRoomCount(){return this.areaRoomIds.size}hasVisitedRoom(t){return this.areaRoomIds.has(t)&&this.visitedRooms.has(t)}getVisitedRoomIds(){return super.getRooms().filter(t=>this.visitedRooms.has(t.id)).map(t=>t.id)}addVisitedRoom(t){const e=this.visitedRooms.has(t);this.visitedRooms.add(t);const s=!e&&this.areaRoomIds.has(t);return s&&this.markDirty(),s}addVisitedRooms(t){let e=0;for(const s of t){const i=this.visitedRooms.has(s);this.visitedRooms.add(s),!i&&this.areaRoomIds.has(s)&&e++}return e>0&&this.markDirty(),e}}class it{constructor(t,e){this.paths=[],this.mapReader=t,this.overlayLayer=e}renderPath(t,e,s,i="#66E64D"){if(e===void 0||s===void 0)return;const o=t.map(c=>this.mapReader.getRoom(c)).filter(c=>c!==void 0),n=[];let r=null;const a=()=>{r&&(r.length<4&&n.pop(),r=null)},d=()=>(r||(r=[],n.push(r)),r);o.forEach((c,l)=>{if(!this.isRoomVisible(c,e,s))return;const m=l>0?o[l-1]:void 0,R=l<o.length-1?o[l+1]:void 0;if(this.isRoomVisible(m,e,s))d();else{a();const b=d();if(m){const y=this.getDirectionTowards(c,m);if(y){const p=x(c.x,c.y,y,h.roomSize);b.push(p.x,p.y)}}}if(r==null||r.push(c.x,c.y),!this.isRoomVisible(R,e,s)&&R){const b=this.getDirectionTowards(c,R);if(b){const y=x(c.x,c.y,b,h.roomSize);r==null||r.push(y.x,y.y)}a()}}),a();const g=n.filter(c=>c.length>=4).map(c=>new f.Line({points:c,stroke:i,strokeWidth:.1}));return g.forEach(c=>{this.overlayLayer.add(c),this.paths.push(c)}),g[0]}clearPaths(){this.paths.forEach(t=>{t.destroy()}),this.paths=[]}isRoomVisible(t,e,s){return t?t.area===e&&t.z===s:!1}getDirectionTowards(t,e){for(const s of X)if(t.exits[s]===e.id)return s;for(const s of X)if(e.exits[s]===t.id)return Q[s]}}const B=.6,k=75,rt="rgb(225, 255, 225)",I="rgb(120, 72, 0)",D=class D{};D.roomSize=B,D.lineColor=rt,D.instantMapMove=!1,D.highlightCurrentRoom=!0,D.cullingEnabled=!0,D.cullingBounds=null,D.labelRenderMode="image";let h=D;class ot{constructor(t,e){this.highlights=new Map,this.currentZoom=1,this.currentRoomOverlay=[],this.roomNodes=new Map,this.standaloneExitNodes=[],this.cullingScheduled=!1,this.stage=new f.Stage({container:t,width:t.clientWidth,height:t.clientHeight,draggable:!0}),window.addEventListener("resize",()=>{this.onResize(t)}),t.addEventListener("resize",()=>{this.onResize(t)}),this.linkLayer=new f.Layer({listening:!1}),this.stage.add(this.linkLayer),this.roomLayer=new f.Layer,this.stage.add(this.roomLayer),this.overlayLayer=new f.Layer({listening:!1}),this.stage.add(this.overlayLayer),this.positionLayer=new f.Layer({listening:!1}),this.stage.add(this.positionLayer),this.mapReader=e,this.exitRenderer=new st(e),this.pathRenderer=new it(e,this.overlayLayer),this.initScaling(1.1),this.stage.on("dragmove",()=>this.scheduleRoomCulling()),this.stage.on("dragend",()=>this.scheduleRoomCulling())}onResize(t){this.stage.width(t.clientWidth),this.stage.height(t.clientHeight),this.currentRoomId&&this.centerOnRoom(this.mapReader.getRoom(this.currentRoomId),!1),this.stage.batchDraw(),this.scheduleRoomCulling()}initScaling(t){f.hitOnDragEnabled=!0;let e,s=!1,i=!1;this.stage.on("touchstart",o=>{const n=o.evt.touches;n&&n.length>1?(i=!0,this.stage.isDragging()&&(this.stage.stopDrag(),s=!0),this.stage.draggable(!1)):(i=!1,this.stage.draggable(!0))}),this.stage.on("touchend touchcancel",o=>{e=void 0;const n=o.evt.touches;(!n||n.length<=1)&&(i=!1,this.stage.draggable(!0))}),this.stage.on("wheel",o=>{o.evt.preventDefault();const n=this.stage.scaleX(),r=this.stage.getPointerPosition();if(!r)return;const a={x:(r.x-this.stage.x())/n,y:(r.y-this.stage.y())/n};let d=o.evt.deltaY>0?-1:1;o.evt.ctrlKey&&(d=-d);const g=d>0?this.currentZoom*t:this.currentZoom/t,c=g*k,l=this.setZoom(g),m={x:r.x-a.x*c,y:r.y-a.y*c};this.stage.position(m),this.scheduleRoomCulling(),l&&this.emitZoomChangeEvent()}),this.stage.on("touchmove",o=>{const n=o.evt.touches,r=n==null?void 0:n[0],a=n==null?void 0:n[1];if(a||i&&(i=!1,this.stage.draggable(!0)),r&&!a&&s&&!this.stage.isDragging()&&(this.stage.startDrag(),s=!1),!r||!a){e=void 0;return}o.evt.preventDefault(),this.stage.isDragging()&&(this.stage.stopDrag(),s=!0),i||(i=!0,this.stage.draggable(!1));const d=this.stage.container().getBoundingClientRect(),g={x:r.clientX-d.left,y:r.clientY-d.top},c={x:a.clientX-d.left,y:a.clientY-d.top},l=Math.hypot(g.x-c.x,g.y-c.y);if(e===void 0){e=l;return}if(e===0)return;const m=this.stage.scaleX(),R=this.stage.x(),v=this.stage.y(),E={x:this.stage.width()/2,y:this.stage.height()/2},b={x:(E.x-R)/m,y:(E.y-v)/m},y=this.currentZoom*(l/e),p=this.setZoom(y),w=this.stage.scaleX(),C={x:E.x-b.x*w,y:E.y-b.y*w};this.stage.position(C),this.stage.batchDraw(),this.scheduleRoomCulling(),e=l,p&&this.emitZoomChangeEvent()})}drawArea(t,e){const s=this.mapReader.getArea(t);if(!s)return;const i=s.getPlane(e);i&&(this.currentArea=t,this.currentAreaInstance=s,this.currentZIndex=e,this.currentAreaVersion=s.getVersion(),this.clearCurrentRoomOverlay(),this.roomLayer.destroyChildren(),this.linkLayer.destroyChildren(),this.roomNodes.clear(),this.standaloneExitNodes=[],this.stage.scale({x:k*this.currentZoom,y:k*this.currentZoom}),this.renderLabels(i.getLabels()),this.renderExits(s.getLinkExits(e)),this.renderRooms(i.getRooms()??[]),this.refreshHighlights(),this.stage.batchDraw(),this.scheduleRoomCulling())}emitRoomContextEvent(t,e,s){const i=this.stage.container(),o=i.getBoundingClientRect(),n={roomId:t,position:{x:e-o.left,y:s-o.top}},r=new CustomEvent("roomcontextmenu",{detail:n});i.dispatchEvent(r)}emitZoomChangeEvent(){const t=new CustomEvent("zoom",{detail:{zoom:this.currentZoom}});this.stage.container().dispatchEvent(t)}setZoom(t){return this.currentZoom===t?!1:(this.currentZoom=t,this.stage.scale({x:k*t,y:k*t}),this.scheduleRoomCulling(),!0)}getZoom(){return this.currentZoom}getCurrentArea(){return this.currentArea?this.mapReader.getArea(this.currentArea):void 0}setPosition(t){const e=this.mapReader.getRoom(t);if(!e)return;const s=this.mapReader.getArea(e.area),i=s==null?void 0:s.getVersion();let o=this.currentArea!==e.area||this.currentZIndex!==e.z;(this.currentArea!==e.area||this.currentZIndex!==e.z||i!==void 0&&this.currentAreaVersion!==i||s!==void 0&&this.currentAreaInstance!==s)&&this.drawArea(e.area,e.z),this.positionRender||(this.positionRender=new f.Circle({x:e.x,y:e.y,radius:B*.85,stroke:"rgb(0, 229, 178)",strokeWidth:.1,dash:[.05,.05],dashEnabled:!0}),this.positionLayer.add(this.positionRender)),this.centerOnRoom(e,o),this.updateCurrentRoomOverlay(e)}renderPath(t,e){return this.pathRenderer.renderPath(t,this.currentArea,this.currentZIndex,e)}clearPaths(){this.pathRenderer.clearPaths()}renderHighlight(t,e){const s=this.mapReader.getRoom(t);if(!s)return;const i=this.highlights.get(t);i!=null&&i.shape&&(i.shape.destroy(),delete i.shape);const o={color:e,area:s.area,z:s.z};if(this.highlights.set(t,o),s.area===this.currentArea&&s.z===this.currentZIndex){const n=this.createHighlightShape(s,e);return this.overlayLayer.add(n),o.shape=n,this.overlayLayer.batchDraw(),n}return o.shape}clearHighlights(){this.highlights.forEach(({shape:t})=>t==null?void 0:t.destroy()),this.highlights.clear(),this.overlayLayer.batchDraw()}refreshHighlights(){this.highlights.forEach((t,e)=>{var o;if((o=t.shape)==null||o.destroy(),delete t.shape,t.area!==this.currentArea||t.z!==this.currentZIndex)return;const s=this.mapReader.getRoom(e);if(!s)return;const i=this.createHighlightShape(s,t.color);this.overlayLayer.add(i),t.shape=i}),this.overlayLayer.batchDraw()}createHighlightShape(t,e){return new f.Circle({x:t.x,y:t.y,radius:h.roomSize*.9,stroke:e,strokeWidth:.15,dash:[.1,.05],dashEnabled:!0,listening:!1})}centerOnRoom(t,e=!1){var d;this.currentRoomId=t.id;const s={x:t.x,y:t.y};(d=this.positionRender)==null||d.position(t);const o=this.stage.getAbsoluteTransform().point(s),n={x:this.stage.width()/2,y:this.stage.height()/2},r=n.x-o.x,a=n.y-o.y;this.currentTransition&&(this.currentTransition.pause(),this.currentTransition.destroy(),delete this.currentTransition),e||h.instantMapMove?(this.stage.position({x:this.stage.x()+r,y:this.stage.y()+a}),this.scheduleRoomCulling()):(this.currentTransition=new f.Tween({node:this.stage,x:this.stage.x()+r,y:this.stage.y()+a,duration:.2,easing:f.Easings.EaseInOut,onUpdate:()=>this.scheduleRoomCulling(),onFinish:()=>this.scheduleRoomCulling()}),this.currentTransition.play())}renderRooms(t){t.forEach(e=>{const s=new f.Group({x:e.x-h.roomSize/2,y:e.y-h.roomSize/2}),i=new f.Rect({x:0,y:0,width:h.roomSize,height:h.roomSize,fill:this.mapReader.getColorValue(e.env),strokeWidth:.025,stroke:h.lineColor}),o=(l,m)=>this.emitRoomContextEvent(e.id,l,m);s.on("mouseenter",()=>{this.stage.container().style.cursor="pointer"}),s.on("mouseleave",()=>{this.stage.container().style.cursor="auto"}),s.on("contextmenu",l=>{l.evt.preventDefault();const m=l.evt;o(m.clientX,m.clientY)});let n,r,a;const d=()=>{a!==void 0&&(this.stage.draggable(a),a=void 0)},g=()=>{n!==void 0&&(window.clearTimeout(n),n=void 0),r=void 0,d()};s.on("touchstart",l=>{var R;if(g(),l.evt.touches&&l.evt.touches.length>1)return;const m=(R=l.evt.touches)==null?void 0:R[0];m&&(r={clientX:m.clientX,clientY:m.clientY},a=this.stage.draggable(),this.stage.draggable(!1),n=window.setTimeout(()=>{r&&o(r.clientX,r.clientY),g()},500))}),s.on("touchend",g),s.on("touchmove",l=>{var y;if(!r)return;const m=(y=l.evt.touches)==null?void 0:y[0];if(!m){g();return}const R=m.clientX-r.clientX,v=m.clientY-r.clientY,E=R*R+v*v,b=10;if(E>b*b){const p=a;g(),p&&this.stage.startDrag()}}),s.on("touchcancel",g),s.add(i),this.renderSymbol(e,s),this.roomLayer.add(s);const c=[];this.exitRenderer.renderSpecialExits(e).forEach(l=>{this.linkLayer.add(l),c.push(l)}),this.exitRenderer.renderStubs(e).forEach(l=>{this.linkLayer.add(l),c.push(l)}),this.exitRenderer.renderInnerExits(e).forEach(l=>{this.roomLayer.add(l)}),this.roomNodes.set(e.id,{room:e,group:s,linkNodes:c})})}scheduleRoomCulling(){this.cullingScheduled||(this.cullingScheduled=!0,window.requestAnimationFrame(()=>{this.cullingScheduled=!1,this.updateRoomCulling()}))}updateRoomCulling(){if(this.roomNodes.size===0&&this.standaloneExitNodes.length===0)return;const t=this.stage.scaleX();if(!t)return;const e=this.stage.position(),s=h.roomSize/2,i=h.cullingBounds,o=i?i.x:0,n=i?i.x+i.width:this.stage.width(),r=i?i.y:0,a=i?i.y+i.height:this.stage.height(),d=Math.min(o,n),g=Math.max(o,n),c=Math.min(r,a),l=Math.max(r,a),m=(d-e.x)/t,R=(g-e.x)/t,v=(c-e.y)/t,E=(l-e.y)/t;let b=!1,y=!1;if(!h.cullingEnabled){this.roomNodes.forEach(({group:p,linkNodes:w})=>{p.visible()||(p.visible(!0),b=!0),w.forEach(C=>{C.visible()||(C.visible(!0),y=!0)})}),this.standaloneExitNodes.forEach(p=>{p.visible()||(p.visible(!0),y=!0)}),b&&this.roomLayer.batchDraw(),y&&this.linkLayer.batchDraw();return}this.roomNodes.forEach(({room:p,group:w,linkNodes:C})=>{const P=p.x-s,V=p.x+s,N=p.y-s,O=p.y+s,M=V>=m&&P<=R&&O>=v&&N<=E;w.visible()!==M&&(w.visible(M),b=!0),C.forEach(T=>{T.visible()!==M&&(T.visible(M),y=!0)})}),this.standaloneExitNodes.forEach(p=>{const w=p.getClientRect({relativeTo:this.linkLayer}),C=w.x,P=w.x+w.width,V=w.y,N=w.y+w.height,O=P>=m&&C<=R&&N>=v&&V<=E;p.visible()!==O&&(p.visible(O),y=!0)}),b&&this.roomLayer.batchDraw(),y&&this.linkLayer.batchDraw()}clearCurrentRoomOverlay(){this.currentRoomOverlay.forEach(t=>t.destroy()),this.currentRoomOverlay=[],this.overlayLayer.batchDraw()}updateCurrentRoomOverlay(t){if(this.clearCurrentRoomOverlay(),t.area!==this.currentArea||t.z!==this.currentZIndex){this.overlayLayer.batchDraw();return}const e=new Map;e.set(t.id,t);const s=[],i=this.currentAreaInstance instanceof z?this.currentAreaInstance:void 0;this.currentAreaInstance&&this.currentZIndex!==void 0&&this.currentAreaInstance.getLinkExits(this.currentZIndex).filter(a=>a.a===t.id||a.b===t.id).forEach(a=>{const d=h.highlightCurrentRoom?this.exitRenderer.renderWithColor(a,I):this.exitRenderer.render(a);d&&s.push(d)});const o=h.highlightCurrentRoom?I:void 0;this.exitRenderer.renderSpecialExits(t,o).forEach(r=>{s.push(r)}),(h.highlightCurrentRoom?this.exitRenderer.renderStubs(t,I):this.exitRenderer.renderStubs(t)).forEach(r=>{s.push(r)}),[...Object.values(t.exits),...Object.values(t.specialExits)].forEach(r=>{const a=this.mapReader.getRoom(r),d=!i||i.hasVisitedRoom(r);a&&a.area===this.currentArea&&a.z===this.currentZIndex&&d&&e.set(r,a)}),s.forEach(r=>{this.overlayLayer.add(r),this.currentRoomOverlay.push(r)}),e.forEach((r,a)=>{const d=a===t.id,g=this.createOverlayRoomGroup(r,{stroke:d&&h.highlightCurrentRoom?I:h.lineColor});this.overlayLayer.add(g),this.currentRoomOverlay.push(g),this.exitRenderer.renderInnerExits(r).forEach(c=>{this.overlayLayer.add(c),this.currentRoomOverlay.push(c)})}),this.overlayLayer.batchDraw()}createOverlayRoomGroup(t,e){const s=new f.Group({x:t.x-h.roomSize/2,y:t.y-h.roomSize/2,listening:!1}),i=new f.Rect({x:0,y:0,width:h.roomSize,height:h.roomSize,fill:this.mapReader.getColorValue(t.env),stroke:e.stroke,strokeWidth:.025,strokeEnabled:!0});return s.add(i),this.renderSymbol(t,s),s}renderSymbol(t,e){if(t.roomChar!==void 0){const s=new f.Text({x:0,y:0,text:t.roomChar,fontSize:.45,fontStyle:"bold",fill:this.mapReader.getSymbolColor(t.env),align:"center",verticalAlign:"middle",width:h.roomSize,height:h.roomSize});e.add(s)}}renderExits(t){t.forEach(e=>{const s=this.exitRenderer.render(e);s&&(this.linkLayer.add(s),this.standaloneExitNodes.push(s))})}renderLabels(t){t.forEach(e=>{if(h.labelRenderMode==="image"){if(!e.pixMap)return;const s=new Image;s.src=`data:image/png;base64,${e.pixMap}`;const i=new f.Image({x:e.X,y:-e.Y,width:e.Width,height:e.Height,image:s,listening:!1});this.linkLayer.add(i);return}this.renderLabelAsData(e)})}renderLabelAsData(t){var r;const e=new f.Group({listening:!1}),s=new f.Rect({x:t.X,y:-t.Y,width:t.Width,height:t.Height,listening:!1});(((r=t.BgColor)==null?void 0:r.alpha)??0)>0&&!h.transparentLabels?s.fill(this.getLabelColor(t.BgColor)):s.fillEnabled(!1),e.add(s);const i=Math.min(.75,t.Width/Math.max(t.Text.length/2,1)),o=Math.max(.1,Math.min(i,Math.max(t.Height*.9,.1))),n=new f.Text({x:t.X,y:-t.Y,width:t.Width,height:t.Height,text:t.Text,fontSize:o,fillEnabled:!0,fill:this.getLabelColor(t.FgColor),align:"center",verticalAlign:"middle",listening:!1});e.add(n),this.linkLayer.add(e)}getLabelColor(t){const e=((t==null?void 0:t.alpha)??255)/255,s=i=>Math.min(255,Math.max(0,i??0));return`rgba(${s(t==null?void 0:t.r)}, ${s(t==null?void 0:t.g)}, ${s(t==null?void 0:t.b)}, ${e})`}}const $={rgbValue:"rgb(114, 1, 0)",symbolColor:[225,225,225]};function Z(u){const t=u[0]/255,e=u[1]/255,s=u[2]/255,i=Math.max(t,e,s),o=Math.min(t,e,s);return(i+o)/2}class nt{constructor(t,e){this.rooms={},this.areas={},this.areaSources={},this.explorationEnabled=!1,this.colors={},t.forEach(s=>{s.rooms.forEach(o=>{o.y=-o.y,this.rooms[o.id]=o});const i=parseInt(s.areaId);this.areas[i]=new A(s),this.areaSources[i]=s}),this.colors=e.reduce((s,i)=>({...s,[i.envId]:{rgb:i.colors,rgbValue:`rgb(${i.colors.join(",")}`,symbolColor:Z(i.colors)>.41?[25,25,25]:[225,255,255],symbolColorValue:Z(i.colors)>.41?"rgb(25,25,25)":"rgb(225,255,255)"}}),{})}getArea(t){return this.areas[t]}getExplorationArea(t){const e=this.areas[t];if(e instanceof z)return e}getAreas(){return Object.values(this.areas)}getRooms(){return Object.values(this.rooms)}getRoom(t){return this.rooms[t]}ensureVisitedRooms(){return this.visitedRooms||(this.visitedRooms=new Set),this.visitedRooms}applyExplorationDecoration(){this.visitedRooms&&Object.entries(this.areaSources).forEach(([t,e])=>{const s=parseInt(t,10);this.areas[s]=new z(e,this.visitedRooms)})}decorateWithExploration(t){return t!==void 0?this.setVisitedRooms(t):this.ensureVisitedRooms(),this.applyExplorationDecoration(),this.explorationEnabled=!0,this.visitedRooms}getVisitedRooms(){return this.visitedRooms}clearExplorationDecoration(){Object.entries(this.areaSources).forEach(([t,e])=>{const s=parseInt(t,10);this.areas[s]=new A(e)}),this.explorationEnabled=!1}isExplorationEnabled(){return this.explorationEnabled}setVisitedRooms(t){return this.visitedRooms=t instanceof Set?t:new Set(t),this.explorationEnabled&&this.applyExplorationDecoration(),this.visitedRooms}addVisitedRoom(t){if(this.explorationEnabled){const i=this.getRoom(t);if(i){const o=this.getExplorationArea(i.area);if(o)return o.addVisitedRoom(t)}}const e=this.ensureVisitedRooms(),s=e.has(t);return e.add(t),!s}addVisitedRooms(t){const e=this.ensureVisitedRooms();let s=0;for(const i of t){if(this.explorationEnabled){const n=this.getRoom(i);if(n){const r=this.getExplorationArea(n.area);if(r){r.addVisitedRoom(i)&&s++;continue}}}const o=e.has(i);e.add(i),o||s++}return s}hasVisitedRoom(t){var e;return((e=this.visitedRooms)==null?void 0:e.has(t))??!1}getColorValue(t){var e;return((e=this.colors[t])==null?void 0:e.rgbValue)??$.rgbValue}getSymbolColor(t,e){var n;const s=((n=this.colors[t])==null?void 0:n.symbolColor)??$.symbolColor,i=Math.min(Math.max(e??1,0),1),o=s.join(",");return i!=1?`rgba(${o}, ${i})`:`rgba(${o})`}}function at(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}class ht{constructor(){this.keys=new Set,this.queue=[]}sort(){this.queue.sort((t,e)=>t.priority-e.priority)}set(t,e){const s=Number(e);if(isNaN(s))throw new TypeError('"priority" must be a number');return this.keys.has(t)?this.queue.map(i=>(i.key===t&&Object.assign(i,{priority:s}),i)):(this.keys.add(t),this.queue.push({key:t,priority:s})),this.sort(),this.queue.length}next(){const t=this.queue.shift();return this.keys.delete(t.key),t}isEmpty(){return this.queue.length===0}has(t){return this.keys.has(t)}get(t){return this.queue.find(e=>e.key===t)}}var ct=ht;function H(u,t){const e=new Map;for(const[s,i]of u)s!==t&&i instanceof Map?e.set(s,H(i,t)):s!==t&&e.set(s,i);return e}var lt=H;function ut(u){const t=Number(u);return!(isNaN(t)||t<=0)}function q(u){const t=new Map;return Object.keys(u).forEach(s=>{const i=u[s];if(i!==null&&typeof i=="object"&&!Array.isArray(i))return t.set(s,q(i));if(!ut(i))throw new Error(`Could not add node at key "${s}", make sure it's a valid node`,i);return t.set(s,Number(i))}),t}var dt=q;function K(u){if(!(u instanceof Map))throw new Error(`Invalid graph: Expected Map instead found ${typeof u}`);u.forEach((t,e)=>{if(typeof t=="object"&&t instanceof Map){K(t);return}if(typeof t!="number"||t<=0)throw new Error(`Values must be numbers greater than 0. Found value ${t} at ${e}`)})}var gt=K;const mt=ct,ft=lt,j=dt,_=gt;class pt{constructor(t){t instanceof Map?(_(t),this.graph=t):t?this.graph=j(t):this.graph=new Map}addNode(t,e){let s;return e instanceof Map?(_(e),s=e):s=j(e),this.graph.set(t,s),this}addVertex(t,e){return this.addNode(t,e)}removeNode(t){return this.graph=ft(this.graph,t),this}path(t,e,s={}){if(!this.graph.size)return s.cost?{path:null,cost:0}:null;const i=new Set,o=new mt,n=new Map;let r=[],a=0,d=[];if(s.avoid&&(d=[].concat(s.avoid)),d.includes(t))throw new Error(`Starting node (${t}) cannot be avoided`);if(d.includes(e))throw new Error(`Ending node (${e}) cannot be avoided`);for(o.set(t,0);!o.isEmpty();){const g=o.next();if(g.key===e){a=g.priority;let l=g.key;for(;n.has(l);)r.push(l),l=n.get(l);break}i.add(g.key),(this.graph.get(g.key)||new Map).forEach((l,m)=>{if(i.has(m)||d.includes(m))return null;if(!o.has(m))return n.set(m,g.key),o.set(m,g.priority+l);const R=o.get(m).priority,v=g.priority+l;return v<R?(n.set(m,g.key),o.set(m,v)):null})}return r.length?(s.trim?r.shift():r=r.concat([t]),s.reverse||(r=r.reverse()),s.cost?{path:r,cost:a}:r):s.cost?{path:null,cost:0}:null}shortestPath(...t){return this.path(...t)}}var yt=pt;const xt=at(yt),Rt={1:"north",2:"northeast",3:"northwest",4:"east",5:"west",6:"south",7:"southeast",8:"southwest",9:"up",10:"down",11:"in",12:"out"};class bt{constructor(t){this.cache=new Map,this.mapReader=t,this.graph=this.buildGraph()}buildGraph(){const t={};return this.mapReader.getRooms().forEach(e=>{const s={},i=new Set((e.exitLocks??[]).map(n=>Rt[n]).filter(n=>!!n)),o=new Set(e.mSpecialExitLocks??[]);Object.entries(e.exits??{}).forEach(([n,r])=>{i.has(n)||this.mapReader.getRoom(r)&&(s[r.toString()]=1)}),Object.values(e.specialExits??{}).forEach(n=>{o.has(n)||this.mapReader.getRoom(n)&&(s[n.toString()]=1)}),t[e.id.toString()]=s}),new xt(t)}findPath(t,e){const s=`${t}->${e}`;if(this.cache.has(s))return this.cache.get(s);if(t===e){const r=this.mapReader.getRoom(t)?[t]:null;return this.cache.set(s,r),r}if(!this.mapReader.getRoom(t)||!this.mapReader.getRoom(e))return this.cache.set(s,null),null;const i=this.graph.path(t.toString(),e.toString()),o=Array.isArray(i)?i:i==null?void 0:i.path,n=o?o.map(r=>Number(r)):null;return this.cache.set(s,n),n}}exports.ExplorationArea=z;exports.MapReader=nt;exports.PathFinder=bt;exports.Renderer=ot;exports.Settings=h;
2
2
  //# sourceMappingURL=index.cjs.map