Zoom in twice as far; ships at anchor keep clear of their port
ZMAX goes from 16 to 32. A club ship near its home city is drawn at least 46 px (times the icon scale) out from the city's marker, along the line from the city, and a tap on a city's own marker picks the city before any ship.
This commit is contained in:
parent
0ad36c2178
commit
ac5ce7fa05
4 changed files with 56 additions and 4 deletions
|
|
@ -2,6 +2,8 @@
|
|||
function hitCity(x,y,r=28){let best=null,bd=r*iconScale();const KS=visibleKs();const pz=pzOn();for(const C of CITIES){if(C.off&&!cityOn(C.id))continue;if(pz&&!pzKind(C.id))continue;for(const k of KS){const [sx,sy]=toS(C.x,C.y,k);const d=Math.hypot(sx-x,sy+4-y);if(d<bd){bd=d;best={id:C.id,sx,sy};}}}return best;}
|
||||
// A tap on a city's icon picks the city; in the rest of its (generous) tap circle, a link right under the finger wins,
|
||||
// or a short link between two close cities could not be picked at all (#126).
|
||||
// On a city's own marker: that tap is for the city, whatever else is drawn close by.
|
||||
const cityCore=(x,y)=>{const h=hitCity(x,y);return !!h&&Math.hypot(h.sx-x,h.sy+4-y)<=16*iconScale();};
|
||||
function pickCity(x,y){const h=hitCity(x,y);if(!h)return null;if(Math.hypot(h.sx-x,h.sy+4-y)<=16*iconScale())return h;return hitLink(x,y)?null:h;}
|
||||
function hitLink(x,y){if(!S)return null;let best=null,bd=12;const KS=visibleKs(),PI=pairIdx();for(const grp of linkGroups()){const l=grp[0];const g=linkGeom(l,PI.get(edgeKey(l)));for(const k of KS){let prev=null;for(const p of g.pts){const q=toS(p[0],p[1],k);if(prev){const d=segDist(x,y,prev,q);if(d<bd){bd=d;best=l.id;}}prev=q;}}}return best;}
|
||||
function wrapCam(){cam.x=((cam.x%W)+W)%W;cam.y=clamp(cam.y,0,H);}
|
||||
|
|
@ -26,7 +28,7 @@ function endPtr(e){
|
|||
ptrs.delete(e.pointerId);const d=UI.drag;if(!d)return;
|
||||
if(d.mode==='pinch'){if(ptrs.size===0){UI.drag=null;UI.snap=null;cv.classList.remove('linking');}return;}
|
||||
if(d.mode==='link'){if(UI.snap&&UI.snap.id!==d.from){if(pzOn())pzLinkModal(d.from,UI.snap.id);else openLinkModal(d.from,UI.snap.id);sfx('click');}}
|
||||
else if(!d.moved&&S&&shipHit(e.clientX,e.clientY))shipTap(shipHit(e.clientX,e.clientY));
|
||||
else if(!d.moved&&S&&shipHit(e.clientX,e.clientY)&&!cityCore(e.clientX,e.clientY))shipTap(shipHit(e.clientX,e.clientY));
|
||||
else if(!d.moved&&S&&mkOn()&&mkHit(e.clientX,e.clientY)){sfx('click');toast(tr('chaos_monkey.tap'),'',[{l:tr('chaos_monkey.banana',{cost:fmt$(mkBananaCost())}),act:'mkBanana',args:{}}]);}
|
||||
else if(!d.moved&&S){const h=pickCity(e.clientX,e.clientY);
|
||||
if(h){selectCity(h.id);renderLeft();sfx('click');}
|
||||
|
|
@ -37,7 +39,7 @@ function endPtr(e){
|
|||
function cancelPtr(e){ptrs.delete(e.pointerId);if(ptrs.size)return;UI.drag=null;UI.snap=null;cv.classList.remove('linking');cv.style.cursor='grab';renderHint();}
|
||||
cv.addEventListener('pointerup',endPtr);cv.addEventListener('pointercancel',cancelPtr);
|
||||
// Dense regions (southern Brazil, the Benelux) need a close look: cities stop growing past 1.35×, so zooming spreads them out (#126).
|
||||
const ZMIN=0.35,ZMAX=16;
|
||||
const ZMIN=0.35,ZMAX=32;
|
||||
function zoomAt(mx,my,f){const wx=cam.x+(mx-CW/2)/cam.z,wy=cam.y+(my-CH/2)/cam.z;cam.z=clamp(cam.z*f,ZMIN,ZMAX);cam.x=wx-(mx-CW/2)/cam.z;cam.y=wy-(my-CH/2)/cam.z;wrapCam();}
|
||||
cv.addEventListener('wheel',e=>{e.preventDefault();zoomAt(e.clientX,e.clientY,Math.exp(-e.deltaY*0.0015));},{passive:false});
|
||||
addEventListener('keydown',e=>{if(e.key==='Enter'&&e.target.id==='metIn'){ACT.metricSet({id:e.target.dataset.id});return;}if(e.target.closest&&e.target.closest('input,textarea,select,[contenteditable]'))return;if(e.ctrlKey||e.metaKey||e.altKey)return;if(e.code==='Space'&&e.target.closest&&e.target.closest('button,a'))return;if(e.code==='Space'&&(!S||rule('clock'))&&!pzOn()&&!UI.clockLocked){e.preventDefault();UI.speed=UI.speed?0:1;renderHUD();}if(e.key==='0')ACT.speed({v:0.5});if(e.key==='1')ACT.speed({v:1});if(e.key==='2')ACT.speed({v:2});if(e.key==='3')ACT.speed({v:4});if(e.key==='4')ACT.speed({v:8});if(e.key==='Escape'&&!$('bankBox').hidden){$('bankBox').hidden=true;return;}if(e.key==='Escape'&&!$('dash').hidden){$('dash').hidden=true;return;}if(e.key==='Escape'){if(!$('modal').hidden){if(S&&UI.started&&!S.lost)closeModal();}else{UI.sel=null;renderPanel();}}});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue