File: C:/Users/fred/AppData/Local/Microsoft/OneDrive/26.168.0830.0006/WebAssets/static/views/hallway.js
(function(){"use strict";const F=70*Math.PI/180,X=6,W=.0015,B=55,y=document.getElementById("canvas"),n=y.getContext("2d"),R=document.getElementById("prompt"),q=document.getElementById("crosshair");let T,f,b,x=0,K=1.5,w=2,A=0,p=0;const G=Math.PI*.42;let E={},M=!1,D=[],O=new Map,k=performance.now();function v(){T=y.width=window.innerWidth,f=y.height=window.innerHeight,b=T/2/Math.tan(F/2)}v(),window.addEventListener("resize",v),y.addEventListener("click",()=>{M||y.requestPointerLock()}),document.addEventListener("pointerlockchange",()=>{M=document.pointerLockElement===y,R.classList.toggle("hidden",M),q.classList.toggle("visible",M)}),document.addEventListener("mousemove",t=>{M&&(A+=t.movementX*W,p-=t.movementY*W,p=Math.max(-G,Math.min(G,p)))}),window.addEventListener("keydown",t=>{E[t.code]=!0}),window.addEventListener("keyup",t=>{E[t.code]=!1});async function Z(){try{const l=(await(await fetch("/api/thumbnails?offset=0&limit=200",{_od4ApiName:"thumbnail.batch"})).json()).items.filter(e=>e.thumbnailId);for(let e=0;e<l.length;e+=2){const c=2.5*(Math.floor(e/2)+1);if(c>=200)break;const i=l[e],d=i.width&&i.height?i.width/i.height:1.33;D.push({thumbnailId:i.thumbnailId,name:i.name||"",takenDateTime:i.takenDateTime,x:-3+.01,z:c,y:1.5,width:1.5,height:1.5/d,isLeft:!0});const o=new Image;if(o.dataset.od4ApiName="thumbnail.single",o.src="/api/thumbnail/"+i.thumbnailId,o.onload=()=>O.set(i.thumbnailId,o),e+1<l.length){const a=l[e+1],h=a.width&&a.height?a.width/a.height:1.33;D.push({thumbnailId:a.thumbnailId,name:a.name||"",takenDateTime:a.takenDateTime,x:3-.01,z:c,y:1.5,width:1.5,height:1.5/h,isLeft:!1});const m=new Image;m.dataset.od4ApiName="thumbnail.single",m.src="/api/thumbnail/"+a.thumbnailId,m.onload=()=>O.set(a.thumbnailId,m)}}document.getElementById("loading").classList.add("hidden"),requestAnimationFrame(Y)}catch{document.getElementById("loading").textContent="Failed to load photos"}}function j(t){const s=Math.cos(A),l=Math.sin(A),e=l,c=s,i=s,d=-l;let o=0,a=0;E.KeyW&&(o+=e,a+=c),E.KeyS&&(o-=e,a-=c),E.KeyA&&(o-=i,a-=d),E.KeyD&&(o+=i,a+=d);const h=Math.sqrt(o*o+a*a);if(h>0){const m=X*t/h;x+=o*m,w+=a*m}x=Math.max(-3+.5,Math.min(3-.5,x)),w=Math.max(.5,Math.min(200,w))}function u(t,s,l){let e=t-x,c=s-K,i=l-w;const d=Math.cos(A),o=Math.sin(A),a=e*d-i*o,h=e*o+i*d,m=Math.cos(p),g=Math.sin(p),L=c*m-h*g,I=c*g+h*m;return I<=.1?null:{x:T/2+a/I*b,y:f/2-L/I*b,z:I}}function U(){n.fillStyle="#000",n.fillRect(0,0,T,f);const t=n.createLinearGradient(0,0,0,f/2);t.addColorStop(0,"#2a2a2a"),t.addColorStop(1,"#1a1a1a"),n.fillStyle=t,n.fillRect(0,0,T,f/2);const s=n.createLinearGradient(0,f/2,0,f);s.addColorStop(0,"#1a1a1a"),s.addColorStop(1,"#2a1f12"),n.fillStyle=s,n.fillRect(0,f/2,T,f/2),V();const l=D.map(e=>({p:e,dist:Math.hypot(e.x-x,e.z-w)})).sort((e,c)=>c.dist-e.dist);for(const{p:e,dist:c}of l)Q(e,c)}function V(){for(let s=1;s<50;s++){const l=(s-1)/50*200,e=s/50*200;N(-3,l,e,"#2a2a2a"),N(3,l,e,"#2a2a2a")}}function N(t,s,l,e){const c=u(t,3,s),i=u(t,3,l),d=u(t,0,l),o=u(t,0,s);!c||!i||!d||!o||(n.fillStyle=e,n.beginPath(),n.moveTo(c.x,c.y),n.lineTo(i.x,i.y),n.lineTo(d.x,d.y),n.lineTo(o.x,o.y),n.closePath(),n.fill())}function Q(t,s){const l=O.get(t.thumbnailId);if(!l)return;const e=t.width/2,c=t.height/2,i=t.x,d=t.y,o=t.z,a=u(i,d+c,o-e),h=u(i,d+c,o+e),m=u(i,d-c,o-e),g=u(i,d-c,o+e);if(!a||!h||!m||!g)return;const L=Math.min(a.x,h.x,m.x,g.x),I=Math.max(a.x,h.x,m.x,g.x),S=Math.min(a.y,h.y,m.y,g.y),P=Math.max(a.y,h.y,m.y,g.y),H=I-L,_=P-S;if(H<2||_<2)return;const r=Math.max(2,H*.06);n.fillStyle="#2a1a08",n.fillRect(L-r,S-r,H+r*2,_+r*2),n.drawImage(l,L,S,H,_);const z=Math.min(.85,Math.max(0,s/B));if(z>.01&&(n.globalAlpha=z,n.fillStyle="#000",n.fillRect(L-r,S-r,H+r*2,_+r*2),n.globalAlpha=1),s<8){const $=Math.max(0,1-s/8);n.globalAlpha=$,n.font=`${Math.max(8,Math.min(13,H*.08))}px -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif`,n.fillStyle="#ccc",n.textAlign="center";const C=(L+I)/2;t.name&&n.fillText(t.name,C,P+r+14),t.takenDateTime&&(n.fillStyle="#888",n.fillText(Od4Shared.DateFormat.formatAsRecorded(t.takenDateTime,null,Od4Strings.resolveLocale()),C,P+r+26)),n.globalAlpha=1}}function Y(t){requestAnimationFrame(Y);const s=Math.min((t-k)/1e3,.1);k=t,j(s),U()}Z()})();