Pieces still read as slow. Cruising speed goes from 120ms per unit to 85: the median departure across the shipped fifty drops 970ms → 763ms and a level's whole animation budget 15.6s → 12.7s, about 18% off. The longest departures do not move — the cap holds them at 3.46s — so if those still drag, the dial is the cap, which was settled separately and is left alone. The gates that guarantee a level opens with something worth watching are stated in milliseconds, and they were picked while a piece crossed a unit in 120ms. Held fixed while the speed changes, they stop meaning what they meant: this change alone made 20 of the 50 shipped levels "fail" an opening gate every one of them had passed, purely from the unscaled number. Scaled to the dial, none fail — the set is unchanged, and the alarm was an artifact of the constant. So the cruise threshold and the opening floor now derive from the speed, naming the speed they were calibrated at. exitTiming takes msPerUnit the way it already took knee and maxMs, and the comparison lab gets a speed slider, reads the levels actually shipping rather than the prototype sweep they were selected from, and totals every route in the campaign instead of the four on screen — those four skew long, where the cap flattens any speed change to 6%. The test that pins constant cruising speed now reads the dial from the token instead of hard-coding 120, so tuning motion no longer looks like a broken guarantee. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
40 lines
2.3 KiB
JavaScript
40 lines
2.3 KiB
JavaScript
import { position, PORTS, trackPoints } from './path-math.js';
|
|
export { hexPoints, trackPoints, PORTS } from './path-math.js';
|
|
// pad adds that many cell radii of margin on every side (macaron keeps its exit dissolve inside the canvas with 0.3).
|
|
export function layout(cells,width,height,pad=0) {
|
|
const raw=cells.map(c=>position(c.q,c.r));
|
|
const minX=Math.min(...raw.map(p=>p.x))-1,maxX=Math.max(...raw.map(p=>p.x))+1;
|
|
const minY=Math.min(...raw.map(p=>p.y))-.866,maxY=Math.max(...raw.map(p=>p.y))+.866;
|
|
const cellLimit=Math.max(47,Math.min(76,Math.min(width,height)*.1));
|
|
const size=Math.min((width-48)/(maxX-minX+2*pad),(height-50)/(maxY-minY+2*pad),cellLimit);
|
|
const ox=width/2-(minX+maxX)/2*size,oy=height/2-(minY+maxY)/2*size;
|
|
return {size,ox,oy,bounds:{top:minY*size+oy,bottom:maxY*size+oy}};
|
|
}
|
|
export function center(cell, view) { const p=position(cell.q,cell.r,view.size); return {x:p.x+view.ox,y:p.y+view.oy}; }
|
|
export function routePoints(route,view,extend=false) {
|
|
if(route.travelPoints)return route.travelPoints.map(p=>({x:p.x*view.size+view.ox,y:p.y*view.size+view.oy}));
|
|
const points=[];
|
|
route.steps.forEach(s=>{
|
|
const c=center(s,view), end=PORTS[s.exit];
|
|
if(s.enter===null) points.push(c,{x:c.x+end.x*view.size,y:c.y+end.y*view.size});
|
|
else points.push(...trackPoints(c.x,c.y,view.size,s.enter,s.exit));
|
|
});
|
|
if(route.end) {
|
|
const c=center(route.end,view);points.push(c);
|
|
if(extend&&route.status==='exit') {const port=PORTS[route.steps[route.steps.length-1].exit];points.push({x:c.x+port.x*120,y:c.y+port.y*120});}
|
|
}
|
|
return points;
|
|
}
|
|
export function pointAlong(points,ratio) {
|
|
const lengths=points.slice(1).map((p,i)=>Math.hypot(p.x-points[i].x,p.y-points[i].y));
|
|
let distance=lengths.reduce((a,b)=>a+b,0)*Math.max(0,Math.min(1,ratio));
|
|
for(let i=0;i<lengths.length;i++) {
|
|
if(distance<=lengths[i]&&lengths[i]>0) {const t=distance/lengths[i],a=points[i],b=points[i+1];return {x:a.x+(b.x-a.x)*t,y:a.y+(b.y-a.y)*t,angle:Math.atan2(b.y-a.y,b.x-a.x)};}
|
|
distance-=lengths[i];
|
|
}
|
|
const a=points[points.length-2]||points[0],b=points[points.length-1];return {...b,angle:Math.atan2(b.y-a.y,b.x-a.x)};
|
|
}
|
|
export function hitCell(cells,view,x,y) {
|
|
return cells.find(cell=>{const c=center(cell,view),dx=Math.abs(x-c.x)/view.size,dy=Math.abs(y-c.y)/view.size;return dx<=1&&dy<=Math.sqrt(3)/2&&Math.sqrt(3)*dx+dy<=Math.sqrt(3);});
|
|
}
|