2 lines
801 B
JavaScript
Executable File
2 lines
801 B
JavaScript
Executable File
(function(){"use strict";let n=null,o=null,l=0,c=0;function r(i,t){(!n||l!==i||c!==t)&&(n=new OffscreenCanvas(i,t),o=n.getContext("2d"),l=i,c=t)}self.onmessage=async i=>{const t=i.data;if(t.type==="init"){r(t.width,t.height);return}if(t.type==="tiles"){const{tiles:f,solids:b,width:m,height:p,cursorX:d,cursorY:u,tileSize:s}=t;if(r(m,p),!o)return;for(const a of b)o.fillStyle=`rgb(${a.r},${a.g},${a.b})`,o.fillRect(a.col*s,a.row*s,s,s);if(f.length>0){const a=await Promise.all(f.map(async e=>{const w=new Blob([e.data],{type:"image/jpeg"});return{bitmap:await createImageBitmap(w),col:e.col,row:e.row}}));for(const e of a)o.drawImage(e.bitmap,e.col*s,e.row*s),e.bitmap.close()}const g=n.transferToImageBitmap();self.postMessage({type:"frame",bitmap:g,width:m,height:p,cursorX:d,cursorY:u},[g])}}})();
|