UNPKG

ecspresso

Version:

A minimal Entity-Component-System library for typescript and javascript.

5 lines (3 loc) 2.35 kB
var v=((k)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(k,{get:(x,b)=>(typeof require<"u"?require:x)[b]}):k)(function(k){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+k+'" is not supported')});import{definePlugin as Z}from"ecspresso";var U={x:0,y:0};function R(k,x,b,z,B,J){return U.x=(k-x)*b+B,U.y=(k+x)*z+J,U}function $(k,x,b){return{x:(k-x)*(b.tileWidth/2)+b.originX,y:(k+x)*(b.tileHeight/2)+b.originY}}function C(k,x,b){let z=k-b.originX,B=x-b.originY;return{x:z/b.tileWidth+B/b.tileHeight,y:-z/b.tileWidth+B/b.tileHeight}}function _(k,x,b,z,B){let J=B.getBoundingClientRect(),N=k-(J.left+J.width/2),M=x-(J.top+J.height/2),L=$(b.x,b.y,z);return C(L.x+N/b.zoom,L.y+M/b.zoom,z)}function P(k){let{tileWidth:x=64,tileHeight:b=32,originX:z=0,originY:B=0,camera:J=!1,systemGroup:N="isometric"}=k??{};return Z("isometric-projection").withResourceTypes().requires().withGroups().install((M)=>{let L=x/2,Q=b/2;if(M.addResource("isoProjection",{tileWidth:x,tileHeight:b,originX:z,originY:B}),M.addSystem("isometric-projection").setPriority(400).inPhase("render").inGroup(N).addQuery("sprites",{with:["sprite","worldTransform"],changed:["worldTransform"]}).addQuery("graphics",{with:["graphics","worldTransform"],changed:["worldTransform"]}).addQuery("containers",{with:["container","worldTransform"],changed:["worldTransform"]}).setProcess(({queries:A})=>{for(let F of A.sprites){let{sprite:K,worldTransform:D}=F.components,E=R(D.x,D.y,L,Q,z,B);K.position.set(E.x,E.y)}for(let F of A.graphics){let{graphics:K,worldTransform:D}=F.components,E=R(D.x,D.y,L,Q,z,B);K.position.set(E.x,E.y)}for(let F of A.containers){let{container:K,worldTransform:D}=F.components,E=R(D.x,D.y,L,Q,z,B);K.position.set(E.x,E.y)}}),J)M.addSystem("isometric-camera-sync").setPriority(900).inPhase("render").inGroup(N).withResources(["cameraState","rootContainer","pixiApp"]).setProcess(({resources:{cameraState:A,rootContainer:F,pixiApp:K}})=>{let D=K.screen.width,E=K.screen.height,V=R(A.x+A.shakeOffsetX,A.y+A.shakeOffsetY,L,Q,z,B);F.position.set(D/2-V.x*A.zoom,E/2-V.y*A.zoom),F.scale.set(A.zoom),F.rotation=-(A.rotation+A.shakeRotation)})})}export{$ as worldToIso,_ as screenToIsoWorld,C as isoToWorld,P as createIsoProjectionPlugin}; //# debugId=07D2C07CA0A331EE64756E2164756E21 //# sourceMappingURL=projection.js.map