var p=Object.defineProperty;var b=(l,t,e)=>t in l?p(l,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[t]=e;var n=(l,t,e)=>(b(l,typeof t!="symbol"?t+"":t,e),e);function I(l){return l!=null}class k{constructor(){n(this,"events",{});n(this,"emitted",[]);n(this,"emitter",{})}on(t,e,s){var o,c,i,a,r,d;if(s!=null&&s.immediate&&this.emitted.includes(t)){e(),s.once||((c=(o=this.events)[t])!=null||(o[t]=[]),(i=this.events[t])==null||i.push({fn:e}));return}(r=(a=this.events)[t])!=null||(a[t]=[]),(d=this.events[t])==null||d.push({fn:e,once:s==null?void 0:s.once})}off(t,e){var o,c;const s=(o=this.events[t])==null?void 0:o.findIndex(i=>i.fn===e);s===-1||s===void 0||(c=this.events[t])==null||c.splice(s,1)}once(t,e){this.on(t,e,{once:!0})}emit(t,...e){var o,c;this.emitted.includes(t)||this.emitted.push(t);const s=(c=(o=this.events)[t])!=null?c:o[t]=[];if(this.emitter[t]){const i=this.emitter[t](s,...e);return this.events[t]=s.filter(a=>!a.once),i}else{const i=[];for(let a=0;a<s.length;a++){const r=s[a];i.push(r.fn(...e))}return this.events[t]=s.filter(a=>!a.once),i}}setEmitter(t,e){this.emitter[t]=e}removeAllListeners(t){I(t)?this.events[t]=[]:this.events={}}}class B extends k{constructor(){super(...arguments);n(this,"fnMap",{})}onIndex(e,s,o,c){const i=this.ensureMap(e);i.has(s)&&(console.warn("监听".concat(String(e),"出错：已存在标识符为").concat(String(s),"的监听函数，已将其覆盖")),this.offIndex(e,s)),i.set(s,o),this.on(e,o,c)}onceIndex(e,s,o){this.onIndex(e,s,o,{once:!0})}offIndex(e,s){const c=this.ensureMap(e).get(s);c&&this.off(e,c)}ensureMap(e){var s;return(s=this.fnMap[e])!=null?s:new Map}}class M extends k{constructor(){super();n(this,"autotileLoaded",0);n(this,"autotileNum");n(this,"autotileListened",!1);n(this,"materialsNum",main.materials.length);n(this,"materialsLoaded",0);this.on("coreInit",()=>{this.autotileNum=Object.keys(core.material.icons.autotile).length},{immediate:!0}),this.on("materialLoaded",()=>{core.loader._loadMaterials_afterLoad()})}addMaterialLoaded(){this.once("coreInit",()=>{this.materialsLoaded++,this.materialsLoaded===this.materialsNum&&this.emit("materialLoaded")})}addAutotileLoaded(){this.once("coreInit",()=>{this.autotileLoaded++,this.autotileLoaded===this.autotileNum&&this.emit("autotileLoaded")})}onAutotileLoaded(e){this.autotileListened||(this.autotileListened=!0,this.on("autotileLoaded",()=>{Object.keys(core.material.icons.autotile).forEach(o=>{core.material.images.autotile[o]=e[o]}),setTimeout(()=>{core.maps._makeAutotileEdges()})}))}}const y=new M,$=new k,f=class f extends k{constructor(){super();n(this,"num",f.num++);!main.replayChecking&&(window.core?this.init():y.once("coreInit",()=>{this.init()}))}init(){let e=-1,s=-1;const o=core.canvas.data.canvas,c=(i,a,r)=>[Math.floor((i*32/r+core.bigmap.offsetX)/32),Math.floor((a*32/r+core.bigmap.offsetY)/32)];o.addEventListener("mousemove",i=>{if(core.status.lockControl||!core.isPlaying()||!core.status.floorId)return;this.emit("mouseMove",i);const{x:a,y:r,size:d}=core.actions._getClickLoc(i.clientX,i.clientY),[u,h]=c(a,r,d),g=core.getMapBlocksObj();if(e!==u||s!==h){const m=g["".concat(e,",").concat(s)],x=g["".concat(u,",").concat(h)];m&&this.emit("leaveBlock",m,i,!1),x?(this.emit("hoverBlock",x,i),e=u,s=h):(e=-1,s=-1)}}),o.addEventListener("mouseleave",i=>{if(core.status.lockControl||!core.isPlaying()||!core.status.floorId)return;const r=core.getMapBlocksObj()["".concat(e,",").concat(s)];r&&this.emit("leaveBlock",r,i,!0),e=-1,s=-1}),o.addEventListener("click",i=>{if(core.status.lockControl||!core.isPlaying()||!core.status.floorId)return;const{x:a,y:r,size:d}=core.actions._getClickLoc(i.clientX,i.clientY),[u,h]=c(a,r,d),m=core.getMapBlocksObj()["".concat(u,",").concat(h)];m&&this.emit("clickBlock",m,i)})}};n(f,"num",0);let L=f;const w=new L;export{k as E,B as I,w as g,$ as h,y as l};
