From e64b6c6a8f3d7716cea9841265f60a5f05e84fdf Mon Sep 17 00:00:00 2001 From: Luiz Bills Date: Sat, 2 Mar 2024 13:56:59 -0300 Subject: [PATCH] Fix --- .prettierignore | 1 + package-lock.json | 17 +++++++++-------- package.json | 6 +++--- public/litecanvas.js | 6 +++++- script/copy-files.js | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1e97c8f --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +/public/litecanvas.js \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f2ccb33..7c414e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,12 +7,13 @@ "": { "name": "litecanvas-editor", "version": "1.6.0", + "hasInstallScript": true, "license": "MIT", "dependencies": { "@codemirror/lang-javascript": "^6.2.1", "@codemirror/theme-one-dark": "^6.1.2", - "@litecanvas/litecanvas": "^0.1.0", - "@litecanvas/plugin-asset-loader": "^0.1.0", + "@litecanvas/litecanvas": "*", + "@litecanvas/plugin-asset-loader": "*", "codemirror": "^6.0.1", "pako": "^2.1.0" }, @@ -521,14 +522,14 @@ } }, "node_modules/@litecanvas/litecanvas": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@litecanvas/litecanvas/-/litecanvas-0.1.2.tgz", - "integrity": "sha512-buRjkfkgox/T8njjk6c5gIkEmSo7vXgpk1T22TmG2DiWWwWSl1WpEcil8UGQxwOBzVjoqScvUnyZsuPMxksh5Q==" + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@litecanvas/litecanvas/-/litecanvas-0.2.0.tgz", + "integrity": "sha512-hIx69DpdmZYHQqkZmLBg4IzIenclLt3sRnaE7vqgU6JNovpQqDz/PlUxZaN0viho6biaAShLo4V4s0DpnC+P2Q==" }, "node_modules/@litecanvas/plugin-asset-loader": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/@litecanvas/plugin-asset-loader/-/plugin-asset-loader-0.1.2.tgz", - "integrity": "sha512-x4QCLh+DrgjwqIXFEl4X1yv2wJO0LGENNfOaAlnNMYUo7qRBpeiZEDQg+NpJFlffX7QtK7g79pgxFBfavO9www==" + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@litecanvas/plugin-asset-loader/-/plugin-asset-loader-0.1.3.tgz", + "integrity": "sha512-XGs4Iu1o9OEC9N1z0jo0t2jDGYUtRzhJhyp0/zyVCnEe9tgetcrPMbwxVXb2ykQl5dR8pzQKwtjmP6OhxbSQbw==" }, "node_modules/codemirror": { "version": "6.0.1", diff --git a/package.json b/package.json index c958fa5..0f4969e 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "scripts": { "start": "esbuild src/index.js --bundle --watch --outfile=public/app.js --servedir=public", "build": "esbuild src/index.js --bundle --minify --outfile=public/app.js", - "prepare": "node ./script/copy-files.js && npm run build" + "postinstall": "node ./script/copy-files.js && npm run build" }, "keywords": [ "game development" @@ -20,8 +20,8 @@ "dependencies": { "@codemirror/lang-javascript": "^6.2.1", "@codemirror/theme-one-dark": "^6.1.2", - "@litecanvas/litecanvas": "^0.1.0", - "@litecanvas/plugin-asset-loader": "^0.1.0", + "@litecanvas/litecanvas": "*", + "@litecanvas/plugin-asset-loader": "*", "codemirror": "^6.0.1", "pako": "^2.1.0" } diff --git a/public/litecanvas.js b/public/litecanvas.js index d541ba2..d696e6f 100644 --- a/public/litecanvas.js +++ b/public/litecanvas.js @@ -1,3 +1,7 @@ +(()=>{var ot=(...a)=>mt(Tt(...a));var tt=new AudioContext,mt=(...a)=>{let f=tt.createBuffer(a.length,a[0].length,44100),d=tt.createBufferSource();return a.map((s,z)=>f.getChannelData(z).set(s)),d.buffer=f,d.connect(tt.destination),d.start(),d},Tt=(a=1,f=.05,d=220,s=0,z=0,e=.1,N=0,j=1,v=0,k=0,L=0,R=0,I=0,q=0,w=0,U=0,A=0,M=1,_=0,E=0)=>{let u=Math.PI*2,b=J=>J>0?1:-1,W=v*=500*u/44100/44100,C=d*=(1+f*2*Math.random()-f)*u/44100,n=[],p=0,P=0,h=0,S=1,O=0,F=0,T=0,H,x;for(s=s*44100+9,_*=44100,z*=44100,e*=44100,A*=44100,k*=500*u/44100**3,w*=u/44100,L*=u/44100,R*=44100,I=I*44100|0,x=s+_+z+e+A|0;h1?N>2?N>3?Math.sin((p%u)**3):Math.max(Math.min(Math.tan(p),1),-1):1-(2*p/u%2+2)%2:1-4*Math.abs(Math.round(p/u)-p/u):Math.sin(p),T=(I?1-E+E*Math.sin(u*h/I):1)*b(T)*Math.abs(T)**j*a*.3*(hh?0:(hR&&(d+=L,C+=L,S=0),I&&!(++O%I)&&(d=C,v=W,S=S||1);return n};var m=["#1a1c2c","#333c57","#566c86","#f4f4f4","#5d275d","#b13e53","#f89b99","#ef7d57","#ffcd75","#a7f070","#38b764","#257179","#29366f","#3b5dc9","#41a6f6","#73eff7"];var it=[[1.5,,332,.01,.03,.2,,1.24,-3.6,,,,,.4,309,.3,,.77,.09],[1.5,,603,,.02,0,,.04,,-.4,473,,,.1,,,.18,.2,.1],[1.5,,152,.01,.07,.06,1,1.21,-16,,,,,,,,,.62,.03],[,,468,.02,.22,.45,1,.84,,5.6,-37,.05,.09,,,,,.8,.27,.05],[,,1959,.01,.04,.12,,.2,,.1,252,.04,,.1,,,,.5,.01,.09],[2.5,,450,.05,.15,.38,1,1.72,.2,-.2,128,.13,.18,,,,.08,.79,.13,.31],[1.5,,261.6256,.07,.1,.26,,1.58,,,,,,.3,,.1,,.43,.17],[2.63,,1727,,.03,.23,,2.65,,-89,5,.06,,,166,,.12,.72],[,,391,.03,.26,.45,1,.07,,,-11,.07,.1,,,,,.56,.14,.2],[1.34,,1117,.07,.07,0,2,.05,,,274,.08,.11,,10,,.09,.82,.11],[,,1705,.24,.15,.12,2,2.97,-5.7,,300,.04,.08],[1.35,,470,.18,.07,0,,2.23,,,-948,,.12,.1,-37,,.01,,,.21],[,,248,,.06,.07,4,1.26,,.3,,,.01,,,.1,,.7,.06,.38],[2.5,,328,.03,.26,.4,4,1.09,.5,.1,,,,.5,,.3,.33,.43,.05,.45],[1.5,,0,.02,,.04,,.37,9.9,,,,,.1,,,.24,,.15],[2,,657,.22,.33,0,3,.28,,-.7,,,.36,,,,.13,.8,.02,.73]];function lt(a={}){let f=window,d=f.document.body,s=(t,o,i)=>t.addEventListener(o,i),z=(t,o,i)=>t.removeEventListener(o,i),e={WIDTH:a.width??null,HEIGHT:a.height??a.width??null,CANVAS:f.document.createElement("canvas"),PARENT:a.parent??d,TAPPED:!1,TAPPING:!1,TAPX:0,TAPY:0,ELAPSED:0,FPS:0,CENTERX:0,CENTERY:0,loop:{init:[],update:[],draw:[]}},N=a.fps??60,j=a.background??0,v=a.global??!0,k=a.antialias??!0,L=a.pixelart??!1,R=a.fullscreen??!0,I=a.autoscale??!0,q=a.tappingInterval??100,w=a.loop??{},U=a.plugins??[],A="ontouchstart"in f||f.navigator.maxTouchPoints>0,M=0,_=0,E=null,u=1,b={top:0,left:0},W=null,C=null,n=null,p={},P=null,h=0,S=0,O=1/N,F=1e3/N,T=0,H=0,x={count:0,time:0},J=Math.PI/180,ft=180/Math.PI,$=Math.PI*2,rt=[],V,g={set(t,o){e[t]=o,v&&(f[t]=o)}};function K(){if(z(f,"DOMContentLoaded",K),_RATIO=e.WIDTH/e.HEIGHT,W=e.WIDTH,C=e.HEIGHT,A){let t=0,o=0;E=i=>{if(P=performance.now(),P-_>q){let l=i.touches[0];Y(!0,l.pageX,l.pageY),_=P}},s(e.CANVAS,"touchstart",function(i){i.preventDefault();let l=i.touches[0];t=l.pageX,o=l.pageY,s(d,"touchmove",E),Y(!0,l.pageX,l.pageY),_=M=performance.now()}),s(e.CANVAS,"touchend",function(i){i.preventDefault(),z(d,"touchmove",E),Y(!1),performance.now()-M<=150&&nt(!0,t,o)})}else E=t=>{P=performance.now(),P-_>q&&(_=P,Y(!0,t.pageX,t.pageY))},s(e.CANVAS,"mousedown",function(t){t.preventDefault(),s(d,"mousemove",E),Y(!0,t.pageX,t.pageY),_=M=performance.now()}),s(e.CANVAS,"mouseup",function(t){t.preventDefault(),z(d,"mousemove",E),Y(!1),performance.now()-M<=150&&nt(!0,t.pageX,t.pageY)});s(f,"focus",()=>{H===0&&(h=performance.now(),H=requestAnimationFrame(Q))}),s(f,"blur",()=>{H&&(cancelAnimationFrame(H),H=0),z(d,A?"mousemove":"touchmove",E),Y(!1)}),et(),(I||R)&&s(f,"resize",et),(w.init||f.init)&&e.loop.init.push(w.init||f.init),(w.update||f.update)&&e.loop.update.push(w.update||f.update),(w.draw||f.draw)&&e.loop.draw.push(w.draw||f.draw),at();for(let t of e.loop.init)t();j!=null&&(e.CANVAS.style.backgroundColor=m[j%16]),h=performance.now(),H=requestAnimationFrame(Q)}function Q(){let t=0;for(P=performance.now(),S=P-h,h=P,T+=S,S>1e3&&(T=F);T>=F;){for(let o of e.loop.update)o(O);g.set("ELAPSED",e.ELAPSED+O),T-=F,t++,ut()}if(t>0){for(let o of e.loop.draw)o();x.count++,x.time+=t*O,x.time>=1&&(g.set("FPS",x.count),x.time-=1,x.count=0)}H=requestAnimationFrame(Q)}function at(){U.sort((t,o)=>(t.priority??10)-(o.priority??10));for(let t of U)e.plugin(t)}function st(t){e.WIDTH>0&&R&&(R=!1,e.HEIGHT=e.HEIGHT>0?e.HEIGHT:e.WIDTH),t.width=e.WIDTH,t.height=e.HEIGHT,g.set("CENTERX",e.WIDTH/2),g.set("CENTERY",e.HEIGHT/2),e.PARENT.appendChild(t),t.ctx=t.getContext("2d"),n=t.ctx,n.textAlign="start",n.textBaseline="top",t.style.display="block",R?(t.style.position="absolute",t.style.top=t.style.bottom=t.style.left=t.style.right=0):I&&(t.style.margin="auto"),L&&(k=!1),k||(n.imageSmoothingEnabled=!1,t.style.imageRendering="pixelated"),b.top=t.offsetTop,b.left=t.offsetLeft}function et(){let t=e.CANVAS;!I&&!R||(W=f.innerWidth,C=f.innerHeight,R?(t.width=W,t.height=C,g.set("WIDTH",W),g.set("HEIGHT",C)):I&&(u=Math.min(W/e.WIDTH,C/e.HEIGHT),u=L?Math.floor(u):u,t.style.width=e.WIDTH*u+"px",t.style.height=e.HEIGHT*u+"px"),g.set("CENTERX",e.WIDTH/2),g.set("CENTERY",e.HEIGHT/2),b.top=t.offsetTop,b.left=t.offsetLeft,e.textalign(p.textAlign||V,p.textBaseline||V),e.linestyle(p.lineWidth||V,p.lineJoin||V,p.lineDash||V))}function ct(){for(let t in e){if(t in f){console.warn(`${t} already exists in global context`);continue}f[t]=e[t]}}function ut(){g.set("TAPPED",!1)}function nt(t,o,i){g.set("TAPPED",t),g.set("TAPX",(o-b.left)/u),g.set("TAPY",(i-b.top)/u)}function Y(t,o,i){g.set("TAPPING",t),g.set("TAPX",(o-b.left)/u),g.set("TAPY",(i-b.top)/u)}for(let t of["sin","cos","abs","ceil","round","floor","min","max","pow","sqrt","sign"])e[t]=f.Math[t];return e.lerp=(t,o,i)=>t+(o-t)*i,e.distance=(t,o)=>Math.abs(t-o),e.deg2rad=t=>t*J,e.rad2deg=t=>t*ft,e.clamp=function(t,o,i){return f.Math.min(Math.max(t,o),i)},e.rand=(t=0,o=1)=>f.Math.random()*(o-t)+t,e.randi=(t=1,o=100)=>e.floor(f.Math.random()*(o-t+1)+t),e.chance=(t=.5)=>e.rand()<=t,e.choose=t=>t[e.randi(0,t.length-1)],e.clear=(t=null)=>{t==null?n.clearRect(0,0,e.WIDTH,e.HEIGHT):(n.fillStyle=m[~~t%16],n.beginPath(),n.fillRect(0,0,e.WIDTH,e.HEIGHT))},e.rect=(t,o,i,l,r=0)=>{n.strokeStyle=m[~~r%16],n.beginPath(),n.strokeRect(~~t,~~o,~~i,~~l)},e.rectfill=(t,o,i,l,r=0)=>{n.fillStyle=m[~~r%16],n.beginPath(),n.fillRect(~~t,~~o,~~i,~~l)},e.circ=(t,o,i,l=0)=>{n.strokeStyle=m[~~l%16],n.beginPath(),n.arc(~~t,~~o,~~i,0,$),n.closePath(),n.stroke()},e.circfill=(t,o,i,l=0)=>{n.fillStyle=m[~~l%16],n.beginPath(),n.arc(~~t,~~o,~~i,0,$),n.closePath(),n.fill()},e.oval=(t,o,i,l,r=0)=>{n.strokeStyle=m[~~r%16],n.beginPath(),n.ellipse(~~t+~~i,~~o+~~l,~~i,~~l,0,0,$),n.closePath(),n.stroke()},e.ovalfill=(t,o,i,l,r=0)=>{n.fillStyle=m[~~r%16],n.beginPath(),n.ellipse(~~t+~~i,~~o+~~l,~~i,~~l,0,0,$),n.closePath(),n.fill()},e.poly=(t,o=0)=>{n.strokeStyle=m[~~o%16],n.beginPath();let i=t.length;for(let l=0;l{n.fillStyle=m[~~o%16],n.beginPath();let i=t.length;for(let l=0;l{n.strokeStyle=m[~~r%16],n.beginPath(),n.moveTo(~~t,~~o),n.lineTo(~~i,~~l),n.stroke()},e.linestyle=(t=1,o="miter",i=null)=>{n.lineWidth=p.lineWidth=t,n.lineJoin=p.lineJoin=o,i?(p.lineDash=Array.isArray(i)?i:[i],n.setLineDash(p.lineDash)):(p.lineDash=rt,n.setLineDash(p.lineDash))},e.text=(t,o,i,l=0,r=null,X="monospace")=>{r=r||Math.max(16,e.HEIGHT/16),n.font=~~r+"px "+X,n.fillStyle=m[~~l%16],n.fillText(i,~~t,~~o)},e.textalign=(t="start",o="top")=>{n.textAlign=p.textAlign=t,n.textBaseline=p.textBaseline=o},e.image=(t,o,i)=>{n.drawImage(i,~~t,~~o)},e.paint=(t,o,i)=>{let l=new OffscreenCanvas(t,o),r=n;if(l.width=t,l.height=o,n=l.getContext("2d"),typeof i=="function")i(l,n);else if(Array.isArray(i)){let X=n.createImageData(t,o),D=X.data,B=y=0;for(let pt of i){for(let Z of pt.split("")){let G=y*(t*4)+B*4;if(Z===" "||Z===".")D[G]=0,D[G+1]=0,D[G+2]=0,D[G+3]=0;else{c=m[~~parseInt(Z,16)];let ht=parseInt(c.slice(1,3),16),gt=parseInt(c.slice(3,5),16),dt=parseInt(c.slice(5,7),16);D[G]=ht,D[G+1]=gt,D[G+2]=dt,D[G+3]=255}B++}y++,B=0}n.putImageData(X,0,0)}return n=r,l},e.transform=(t,o,i=1,l=0)=>{n.setTransform(i,0,0,i,t,o),n.rotate(l)},e.alpha=(t=1)=>{n.globalAlpha=t},e.blendmode=(t="source-over")=>{n.globalCompositeOperation=t},e.push=()=>n.save(),e.pop=()=>n.restore(),e.sfx=(t=0,o=1,i=0,l=null)=>{if(navigator.userActivation&&!navigator.userActivation.hasBeenActive)return;let r=Array.isArray(t)?t:it[~~t%16];return(o!==1||i!==0||l!=null)&&(r=[...r],r[0]=(Number(o)||1)*(r[0]||1),r[1]=l>=0?l:void 0,r[10]=~~r[10]+~~i),ot(...r)},e.collision=(t,o,i,l,r,X,D,B)=>tr&&oX,e.plugin=t=>{let o=t(e,g);if(typeof o=="object")for(let i in o)g.set(i,o[i])},v&&ct(),st(e.CANVAS),f.document.readyState==="loading"?s(f,"DOMContentLoaded",K):K(),e}window.litecanvas=lt;})(); +//! ZzFXMicro - Zuper Zmall Zound Zynth - v1.2.1 by Frank Force ~ 880 bytes +//! default color palette based on https://lospec.com/palette-list/sweetie-16 +/*! litecanvas v0.2.0 by Luiz Bills | https://github.com/litecanvas/engine */ (()=>{var u=getScriptLoader=(t,{set:o})=>(a,e)=>{o("LOADING",t.LOADING+1),fetch(a).then(r=>r.ok?r.text():null).then(r=>{let n=null;r&&(n=document.createElement("script"),n.innerHTML=r,n.dataset.src=a,document.head.appendChild(n)),typeof e=="function"&&e(n),o("LOADING",t.LOADING-1)})};var f=getImageLoader=(t,{set:o})=>(a,e)=>{o("LOADING",t.LOADING+1);let r=new Image;r.onload=()=>{typeof e=="function"&&e(r),o("LOADING",t.LOADING-1)},r.onerror=function(){typeof e=="function"&&e(null),o("LOADING",t.LOADING-1)},r.src=a};window.pluginAssetLoader=i;function i(t,o){return t.LOADING=0,{loadScript:u(t,o),loadImage:f(t,o)}}})(); -/*! Asset Loader plugin for litecanvas v0.1.1 by Luiz Bills | MIT Licensed */ +/*! Asset Loader plugin for litecanvas v0.1.3 by Luiz Bills | MIT Licensed */ diff --git a/script/copy-files.js b/script/copy-files.js index 3a0f1a3..ef174d6 100644 --- a/script/copy-files.js +++ b/script/copy-files.js @@ -3,7 +3,7 @@ import { copyFile, unlink, readFile, appendFile } from "node:fs/promises"; const root = process.env["PWD"]; const engineFile = root + "/public/litecanvas.js"; -unlink(engineFile); +await unlink(engineFile); await copyFile( root + "/node_modules/@litecanvas/litecanvas/dist/dist.js",