Spaces:
Running on Zero
Running on Zero
player dragging
Browse files
film.py
CHANGED
|
@@ -93,6 +93,21 @@ select{background:var(--navy3);color:var(--ink);border:1px solid var(--line);bor
|
|
| 93 |
.yd{font:800 2.5px var(--cond);fill:#fff;text-anchor:middle;opacity:.82}
|
| 94 |
.hl{font:700 .72px var(--sans);fill:#fff;text-anchor:middle;pointer-events:none}
|
| 95 |
.pl{cursor:pointer}.hd{cursor:grab}.hd:active{cursor:grabbing}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
</style></head><body>
|
| 97 |
<div id="bug"></div>
|
| 98 |
<div id="main">
|
|
@@ -105,6 +120,16 @@ select{background:var(--navy3);color:var(--ink);border:1px solid var(--line);bor
|
|
| 105 |
<div id="legend"></div>
|
| 106 |
<svg id="field" xmlns="http://www.w3.org/2000/svg"></svg>
|
| 107 |
<div id="chy"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</div>
|
| 109 |
<div id="side"></div>
|
| 110 |
</div>
|
|
@@ -146,6 +171,7 @@ let mode=C.mode||(B?'overlay':'orig'), cam='fixed', t=0, playing=false, speed=1,
|
|
| 146 |
let sel=C.sel&&idx[C.sel]!=null?C.sel:null, hsel=null;
|
| 147 |
let edits=JSON.parse(JSON.stringify(C.edits||{})), reacts=JSON.parse(JSON.stringify(C.react||{}));
|
| 148 |
const base=C.paths;
|
|
|
|
| 149 |
function main(){return mode==='orig'||!B?A:B;}
|
| 150 |
function curPath(pid){return edits[pid]||base[pid];}
|
| 151 |
function isEdited(pid){return !!edits[pid];}
|
|
@@ -185,8 +211,9 @@ svg.innerHTML=`<defs>
|
|
| 185 |
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation=".28" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
|
| 186 |
<marker id="mw" viewBox="0 0 10 10" refX="6.5" refY="5" markerWidth="3.6" markerHeight="3.6" orient="auto"><path d="M0 0L10 5L0 10z" fill="#fff"/></marker>
|
| 187 |
<marker id="mc" viewBox="0 0 10 10" refX="6.5" refY="5" markerWidth="3.6" markerHeight="3.6" orient="auto"><path d="M0 0L10 5L0 10z" fill="#22d3ee"/></marker>
|
| 188 |
-
</defs><g id="gField"></g><g id="gOver"></g><g id="gPaths"></g><g id="gTrail"></g><g id="gGhost"></g><g id="gSep"></g><g id="gPl"></g><g id="gBall"></g><g id="gEdit"></g>`;
|
| 189 |
-
const gF=$('#gField'),gO=$('#gOver'),gP=$('#gPaths'),gT=$('#gTrail'),gG=$('#gGhost'),gS=$('#gSep'),gPl=$('#gPl'),gB=$('#gBall'),gE=$('#gEdit');
|
|
|
|
| 190 |
function drawField(){
|
| 191 |
let h=`<rect x="-4" y="-4" width="128" height="${W+8}" fill="#04101f"/><rect x="-.6" y="-.6" width="121.2" height="${W+1.2}" fill="#e8edf5"/><rect x="0" y="0" width="120" height="${W}" fill="url(#turf)"/>`;
|
| 192 |
for(let i=0;i<20;i++) if(i%2===0) h+=`<rect x="${10+i*5}" y="0" width="5" height="${W}" fill="#000" opacity=".085"/>`;
|
|
@@ -235,6 +262,7 @@ function player(i,x,y,ghost){
|
|
| 235 |
const m=meta[i], g=m.side==='O'?'gO':'gD', s=sel===m.id;
|
| 236 |
if(ghost) return `<g transform="translate(${x} ${y})" opacity=".62"><circle r="1" fill="rgba(255,255,255,.08)" stroke="#fff" stroke-width=".13" stroke-dasharray=".35 .25"/><text class="pn" dy=".36" style="opacity:.8">${m.num}</text></g>`;
|
| 237 |
return `<g class="pl" data-id="${m.id}" transform="translate(${x} ${y})">`+
|
|
|
|
| 238 |
(s?`<circle r="1.75" fill="none" stroke="#ffd400" stroke-width=".2" filter="url(#glow)"/>`:'')+
|
| 239 |
`<circle r="1" fill="url(#${g})" stroke="#fff" stroke-width=".15" filter="url(#sh)"/>`+
|
| 240 |
`<text class="pn" dy=".37">${m.num}</text>`+
|
|
@@ -248,7 +276,7 @@ function renderDynamic(){
|
|
| 248 |
let hp='';
|
| 249 |
for(let i=0;i<N;i++){const pid=ids[i]; if(pid===sel) continue; const pa=base[pid]; if(!pa||pa.length<2) continue;
|
| 250 |
let d='M'+pa.map(q=>q[1]+' '+q[2]).join('L'); hp+=`<path d="${d}" fill="none" stroke="${meta[i].side==='O'?'#e8f0ff':'#ffb0b0'}" stroke-opacity=".2" stroke-width=".13" stroke-linejoin="round"/>`;
|
| 251 |
-
if(isEdited(pid)&&!same(edits[pid],base[pid])){hp+=`<path d="M${edits[pid].map(q=>q[1]+' '+q[2]).join('L')}" fill="none" stroke="#22d3ee" stroke-width=".26" marker-end="url(#mc)" opacity=".9"/>`;}}
|
| 252 |
gP.innerHTML=hp;
|
| 253 |
// trails
|
| 254 |
let ht='';
|
|
@@ -278,17 +306,19 @@ function renderDynamic(){
|
|
| 278 |
chyron(rep); timeline(); setView();}
|
| 279 |
|
| 280 |
function renderEdit(){
|
| 281 |
-
if(!sel){gE.innerHTML=''; return;}
|
| 282 |
const pid=sel, p=curPath(pid), i=idx[pid], sg=segs(pid), edited=!!changed()[pid];
|
| 283 |
-
let h='';
|
| 284 |
-
if(edited) h+=`<path d="M${base[pid].map(q=>q[1]+' '+q[2]).join('L')}" fill="none" stroke="#fff" stroke-width=".2" stroke-dasharray=".7 .5" opacity=".85" marker-end="url(#mw)"/>`;
|
| 285 |
-
for(let k=1;k<p.length;k++){h+=`<line x1="${p[k-1][1]}" y1="${p[k-1][2]}" x2="${p[k][1]}" y2="${p[k][2]}" stroke="${col(sg[k-1].r,sg[k-1].dt)}" stroke-width="${edited?.42:.3}" stroke-linecap="round" opacity="${edited?1:.85}" filter="url(#glow)"/>`;
|
| 286 |
-
|
|
|
|
|
|
|
| 287 |
for(let k=0;k<p.length;k++){const on=hsel===k;
|
| 288 |
if(k===0){h+=`<rect x="${p[0][1]-.4}" y="${p[0][2]-.4}" width=".8" height=".8" fill="#fff" opacity=".9" pointer-events="none"/>`; continue;}
|
| 289 |
h+=`<g class="hd" data-k="${k}" transform="translate(${p[k][1]} ${p[k][2]})"><circle r=".95" fill="transparent"/><circle r="${on?.62:.46}" fill="${on?'#ffd400':'#22d3ee'}" stroke="#fff" stroke-width=".15"/>`+
|
| 290 |
`<g transform="translate(0 -1.25)"><rect x="-1.15" y="-.5" width="2.3" height="1" rx=".4" fill="rgba(3,10,26,.9)"/><text class="hl" dy=".24" style="font-size:.66px">${f1(p[k][0])}s</text></g></g>`;}
|
| 291 |
-
gE.innerHTML=h;}
|
| 292 |
|
| 293 |
function chyron(rep){
|
| 294 |
const ev=rep.events.filter(e=>e.t<=t+0.001).slice(-1)[0], el=$('#chy');
|
|
@@ -327,7 +357,7 @@ function renderCharts(){
|
|
| 327 |
function renderPanel(){
|
| 328 |
const el=$('#side');
|
| 329 |
if(!sel){el.innerHTML=`<h4>Player</h4><div class="hint"><b>Click any player</b> on the field to see his card, separation and speed, and to edit his path.<br><br>
|
| 330 |
-
<b>
|
| 331 |
Line colour shows what his body can do: <span class="pill ok">green</span> within reach, <span class="pill warn">amber</span> near top speed, <span class="pill bad">red</span> faster than he can run.<br><br>Then press <b>Run what-if</b> to replay the play hundreds of times with your path against the original.</div>`; return;}
|
| 332 |
const i=idx[sel], m=meta[i], hasB=m.ht!=null, ft=hasB?Math.floor(m.ht/12):0, inch=hasB?m.ht%12:0, sg=segs(sel), p=curPath(sel), reps=(mode==='overlay'&&B)?[[A,'#9db0cf',true],[B,'#22d3ee',false]]:[[main(),m.side==='O'?'#9dbcff':'#ff9a9a',false]];
|
| 333 |
const sep=reps.map(r=>({d:series(r[0],i,'sep'),c:r[1],dash:r[2]})), spd=reps.map(r=>({d:series(r[0],i,'spd'),c:r[1],dash:r[2]}));
|
|
@@ -345,33 +375,118 @@ function renderPanel(){
|
|
| 345 |
<div class="chartbox"><div class="cap"><span>yards</span><span id="livesep" style="color:#fff;font-weight:700"></span></div>${chartSvg(sep,ymaxS)}</div>
|
| 346 |
<h4>Speed</h4>
|
| 347 |
<div class="chartbox"><div class="cap"><span>mph</span><span id="livesp" style="color:#fff;font-weight:700"></span></div>${chartSvg(spd,ymaxV,m.mph)}</div>
|
|
|
|
|
|
|
|
|
|
| 348 |
<h4>Path · timed waypoints</h4>
|
| 349 |
<table class="wp"><tr><th>pt</th><th>time</th><th>depth</th><th>y</th><th>needs</th></tr>${rows}</table>
|
| 350 |
<div class="tools"><button id="tm">−0.1s</button><button id="tp">+0.1s</button><button id="tdel">Remove point</button><button id="tres">Reset this path</button></div>`;
|
| 351 |
-
if(canReact){const bump=d=>{const v=Math.round(((reacts[sel]||0)+d)*100)/100; if(Math.abs(v)<.001) delete reacts[sel]; else reacts[sel]=Math.max(-.6,Math.min(.6,v)); afterEdit();};
|
| 352 |
-
$('#rm').onclick=()=>bump(-.1); $('#rp').onclick=()=>bump(.1); $('#rr').onclick=()=>{delete reacts[sel]; afterEdit();};}
|
| 353 |
-
|
|
|
|
| 354 |
el.querySelectorAll('table.wp tr[data-k]').forEach(r=>r.onclick=()=>{hsel=+r.dataset.k||null; renderPanel(); renderEdit();});
|
| 355 |
renderCharts();}
|
| 356 |
|
| 357 |
// ------------------------------------------------------------------ editing
|
| 358 |
-
function
|
| 359 |
-
function
|
| 360 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
let dragH=null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
svg.addEventListener('pointerdown',e=>{
|
| 363 |
-
|
| 364 |
-
const
|
| 365 |
-
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
const row=document.querySelector(`table.wp tr[data-k="${k}"]`); if(row){const c=row.children; c[2].textContent=(p[k][1]-bx>=0?'+':'')+f1(p[k][1]-bx); c[3].textContent=f1(p[k][2]);}});
|
| 368 |
-
function endDrag(){
|
|
|
|
|
|
|
|
|
|
| 369 |
svg.addEventListener('pointerup',endDrag); svg.addEventListener('pointercancel',endDrag);
|
| 370 |
svg.addEventListener('dblclick',e=>{const sg=e.target.closest('.seg'); if(!sg||!sel) return; const k=+sg.dataset.k, p=ownPath(sel), [mx,my]=toSvg(e);
|
| 371 |
const a=p[k-1], b=p[k], dx=b[1]-a[1], dy=b[2]-a[2], L2=dx*dx+dy*dy||1e-9, f=clamp(((mx-a[1])*dx+(my-a[2])*dy)/L2,.1,.9);
|
| 372 |
-
p.splice(k,0,[+(a[0]+(b[0]-a[0])*f).toFixed(2),+(a[1]+dx*f).toFixed(2),+(a[2]+dy*f).toFixed(2)]); hsel=k; afterEdit();});
|
| 373 |
svg.addEventListener('contextmenu',e=>{const hd=e.target.closest('.hd'); if(hd){e.preventDefault(); removePt(+hd.dataset.k);}});
|
| 374 |
window.addEventListener('keydown',e=>{
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
if(e.key==='['){retime(-.1);} else if(e.key===']'){retime(.1);} else if((e.key==='Delete'||e.key==='Backspace')&&hsel){removePt(hsel);} else if(e.key==='Escape'){sel=null;hsel=null;renderPanel();renderDynamic();status();post('sel');}
|
| 376 |
else if(e.key===' '){e.preventDefault(); togglePlay();}});
|
| 377 |
|
|
@@ -390,15 +505,17 @@ $('#bghost').onclick=()=>{ghostHash=!ghostHash; $('#bghost').className=ghostHash
|
|
| 390 |
function togglePlay(){if(!playing&&t>=TMAX-.05) t=0; playing=!playing; $('#bplay').innerHTML=playing?'❚❚':'▶';}
|
| 391 |
$('#bplay').onclick=togglePlay; $('#brest').onclick=()=>{t=0; playing=true; $('#bplay').innerHTML='❚❚'; renderDynamic(); renderCharts();};
|
| 392 |
$('#bspd').onchange=e=>{speed=+e.target.value;};
|
| 393 |
-
$('#brun').onclick=()=>{post('run');}; $('#breset').onclick=()=>{edits={}; reacts={}; hsel=null; afterEdit();};
|
| 394 |
$('#bexp').onclick=()=>{const o={level:C.levelShort,offense:C.offPlay,defense:C.defCall,ball:[bx,by],original:base,edits:changed(),reaction_changes:reactsChanged()};
|
| 395 |
const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([JSON.stringify(o,null,2)],{type:'application/json'})); a.download='hawk_one_paths.json'; a.click();};
|
| 396 |
let last=performance.now();
|
| 397 |
function loop(now){const dt=Math.min(.1,(now-last)/1000); last=now; if(playing){t+=dt*speed; if(t>=TMAX){t=TMAX; playing=false; $('#bplay').innerHTML='▶';} renderDynamic(); renderCharts();} requestAnimationFrame(loop);}
|
|
|
|
|
|
|
| 398 |
window.addEventListener('resize',setView);
|
| 399 |
// test hooks (used by the automated checks)
|
| 400 |
-
window.__film={get sel(){return sel;},get edits(){return changed();},set t(v){t=v; renderDynamic(); renderCharts();},get mode(){return mode;}};
|
| 401 |
-
drawField(); drawOver(); drawMode(); bug(); renderPanel(); renderDynamic(); status(); $('#bghost').className=ghostHash?'on':'';
|
| 402 |
setTimeout(()=>{setView(); if(C.autoplay){playing=true; $('#bplay').innerHTML='❚❚';}},50);
|
| 403 |
requestAnimationFrame(n=>{last=n; loop(n);});
|
| 404 |
})();
|
|
@@ -433,4 +550,4 @@ def build_film_html(level_key, setup, rep_a, rep_b, paths, edits=None, sel=None,
|
|
| 433 |
def build_film_doc(*a, **k) -> str:
|
| 434 |
"""The bare document (for headless checks)."""
|
| 435 |
h = build_film_html(*a, **k)
|
| 436 |
-
return html.unescape(h.split('srcdoc="', 1)[1].rsplit('" sandbox', 1)[0])
|
|
|
|
| 93 |
.yd{font:800 2.5px var(--cond);fill:#fff;text-anchor:middle;opacity:.82}
|
| 94 |
.hl{font:700 .72px var(--sans);fill:#fff;text-anchor:middle;pointer-events:none}
|
| 95 |
.pl{cursor:pointer}.hd{cursor:grab}.hd:active{cursor:grabbing}
|
| 96 |
+
|
| 97 |
+
#tools{position:absolute;left:50%;transform:translateX(-50%);bottom:14px;z-index:4;display:flex;align-items:center;gap:4px;padding:5px;border:1px solid var(--line);border-radius:12px;background:rgba(5,15,34,.92);backdrop-filter:blur(4px);box-shadow:0 8px 24px rgba(0,0,0,.5)}
|
| 98 |
+
#tools button{border:0;background:transparent;font:700 13px var(--cond);letter-spacing:.9px;text-transform:uppercase;padding:7px 12px;border-radius:8px;display:flex;align-items:center;gap:6px}
|
| 99 |
+
#tools button.on{background:var(--blue)}#tools button:hover:not(.on):not(:disabled){background:#17376a}
|
| 100 |
+
#tools .sep{width:1px;height:22px;background:var(--line);margin:0 3px}
|
| 101 |
+
#tools select{border:0;background:transparent;font:700 12px var(--cond);letter-spacing:.8px;text-transform:uppercase;padding:6px 2px}
|
| 102 |
+
#tools kbd{font:600 10px var(--sans);color:var(--mute);border:1px solid var(--line);border-radius:4px;padding:0 4px}
|
| 103 |
+
#toast{position:absolute;left:50%;top:58px;transform:translateX(-50%);z-index:5;background:#ffd400;color:#201700;font:700 13px var(--sans);padding:7px 14px;border-radius:8px;display:none;box-shadow:0 6px 18px rgba(0,0,0,.4)}
|
| 104 |
+
#coach{position:absolute;left:12px;top:58px;z-index:3;max-width:290px;background:rgba(5,15,34,.86);border:1px solid var(--line);border-radius:8px;padding:7px 10px;font-size:11.5px;line-height:1.45;color:#cfe0ff;display:none}
|
| 105 |
+
#coach b{color:#fff}
|
| 106 |
+
.rt{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;padding:10px 14px 4px}
|
| 107 |
+
.rt button{padding:8px 2px;font:700 12px var(--cond);letter-spacing:.8px;text-transform:uppercase;display:flex;flex-direction:column;align-items:center;gap:3px}
|
| 108 |
+
.rt svg{width:34px;height:34px;display:block}
|
| 109 |
+
.rt .cap{padding:0 14px 8px;color:var(--mute);font-size:11.5px}
|
| 110 |
+
svg#field.drawing{cursor:crosshair}
|
| 111 |
</style></head><body>
|
| 112 |
<div id="bug"></div>
|
| 113 |
<div id="main">
|
|
|
|
| 120 |
<div id="legend"></div>
|
| 121 |
<svg id="field" xmlns="http://www.w3.org/2000/svg"></svg>
|
| 122 |
<div id="chy"></div>
|
| 123 |
+
<div id="coach"></div><div id="toast"></div>
|
| 124 |
+
<div id="tools">
|
| 125 |
+
<button data-t="move" id="tmove" title="Move (V): click a player, drag him to where he should be at this moment, or drag the cyan points">✥ Move</button>
|
| 126 |
+
<button data-t="draw" id="tdraw" title="Draw (D): press on a player and drag out his route">✎ Draw</button>
|
| 127 |
+
<span class="sep"></span>
|
| 128 |
+
<select id="pace" title="How fast he runs the line you draw"><option value="orig">Pace: as original</option><option value="fast">Pace: full speed</option><option value="jog">Pace: jog</option></select>
|
| 129 |
+
<span class="sep"></span>
|
| 130 |
+
<button id="bundo" title="Undo (Ctrl+Z)">↶</button><button id="bredo" title="Redo (Ctrl+Shift+Z)">↷</button>
|
| 131 |
+
<button id="bmir" title="Flip the route across his starting line (M)">Mirror</button>
|
| 132 |
+
</div>
|
| 133 |
</div>
|
| 134 |
<div id="side"></div>
|
| 135 |
</div>
|
|
|
|
| 171 |
let sel=C.sel&&idx[C.sel]!=null?C.sel:null, hsel=null;
|
| 172 |
let edits=JSON.parse(JSON.stringify(C.edits||{})), reacts=JSON.parse(JSON.stringify(C.react||{}));
|
| 173 |
const base=C.paths;
|
| 174 |
+
let tool='move', hist=[], redoS=[], drawing=null, bodyDrag=null, pace='orig';
|
| 175 |
function main(){return mode==='orig'||!B?A:B;}
|
| 176 |
function curPath(pid){return edits[pid]||base[pid];}
|
| 177 |
function isEdited(pid){return !!edits[pid];}
|
|
|
|
| 211 |
<filter id="glow" x="-50%" y="-50%" width="200%" height="200%"><feGaussianBlur stdDeviation=".28" result="b"/><feMerge><feMergeNode in="b"/><feMergeNode in="SourceGraphic"/></feMerge></filter>
|
| 212 |
<marker id="mw" viewBox="0 0 10 10" refX="6.5" refY="5" markerWidth="3.6" markerHeight="3.6" orient="auto"><path d="M0 0L10 5L0 10z" fill="#fff"/></marker>
|
| 213 |
<marker id="mc" viewBox="0 0 10 10" refX="6.5" refY="5" markerWidth="3.6" markerHeight="3.6" orient="auto"><path d="M0 0L10 5L0 10z" fill="#22d3ee"/></marker>
|
| 214 |
+
</defs><g id="gField"></g><g id="gOver"></g><g id="gPaths"></g><g id="gTrail"></g><g id="gGhost"></g><g id="gSep"></g><g id="gSeg"></g><g id="gPl"></g><g id="gBall"></g><g id="gEdit"></g>`;
|
| 215 |
+
const gF=$('#gField'),gO=$('#gOver'),gP=$('#gPaths'),gT=$('#gTrail'),gG=$('#gGhost'),gS=$('#gSep'),gPl=$('#gPl'),gB=$('#gBall'),gE=$('#gEdit'),gSg=$('#gSeg');
|
| 216 |
+
[gF,gO,gP,gT,gG,gS,gB].forEach(g=>g.style.pointerEvents='none');
|
| 217 |
function drawField(){
|
| 218 |
let h=`<rect x="-4" y="-4" width="128" height="${W+8}" fill="#04101f"/><rect x="-.6" y="-.6" width="121.2" height="${W+1.2}" fill="#e8edf5"/><rect x="0" y="0" width="120" height="${W}" fill="url(#turf)"/>`;
|
| 219 |
for(let i=0;i<20;i++) if(i%2===0) h+=`<rect x="${10+i*5}" y="0" width="5" height="${W}" fill="#000" opacity=".085"/>`;
|
|
|
|
| 262 |
const m=meta[i], g=m.side==='O'?'gO':'gD', s=sel===m.id;
|
| 263 |
if(ghost) return `<g transform="translate(${x} ${y})" opacity=".62"><circle r="1" fill="rgba(255,255,255,.08)" stroke="#fff" stroke-width=".13" stroke-dasharray=".35 .25"/><text class="pn" dy=".36" style="opacity:.8">${m.num}</text></g>`;
|
| 264 |
return `<g class="pl" data-id="${m.id}" transform="translate(${x} ${y})">`+
|
| 265 |
+
`<circle r="1.7" fill="transparent"/>`+
|
| 266 |
(s?`<circle r="1.75" fill="none" stroke="#ffd400" stroke-width=".2" filter="url(#glow)"/>`:'')+
|
| 267 |
`<circle r="1" fill="url(#${g})" stroke="#fff" stroke-width=".15" filter="url(#sh)"/>`+
|
| 268 |
`<text class="pn" dy=".37">${m.num}</text>`+
|
|
|
|
| 276 |
let hp='';
|
| 277 |
for(let i=0;i<N;i++){const pid=ids[i]; if(pid===sel) continue; const pa=base[pid]; if(!pa||pa.length<2) continue;
|
| 278 |
let d='M'+pa.map(q=>q[1]+' '+q[2]).join('L'); hp+=`<path d="${d}" fill="none" stroke="${meta[i].side==='O'?'#e8f0ff':'#ffb0b0'}" stroke-opacity=".2" stroke-width=".13" stroke-linejoin="round"/>`;
|
| 279 |
+
if(isEdited(pid)&&!same(edits[pid],base[pid])){hp+=`<path d="M${edits[pid].map(q=>q[1]+' '+q[2]).join('L')}" fill="none" stroke="#22d3ee" stroke-width=".26" marker-end="url(#mc)" opacity=".9"/>`; const rq=pathPos(edits[pid],t); hp+=`<circle cx="${rq[0]}" cy="${rq[1]}" r="1.05" fill="rgba(34,211,238,.2)" stroke="#22d3ee" stroke-width=".2"/>`;}}
|
| 280 |
gP.innerHTML=hp;
|
| 281 |
// trails
|
| 282 |
let ht='';
|
|
|
|
| 306 |
chyron(rep); timeline(); setView();}
|
| 307 |
|
| 308 |
function renderEdit(){
|
| 309 |
+
if(!sel){gE.innerHTML=''; gSg.innerHTML=''; return;}
|
| 310 |
const pid=sel, p=curPath(pid), i=idx[pid], sg=segs(pid), edited=!!changed()[pid];
|
| 311 |
+
let h='', sg2='';
|
| 312 |
+
if(edited) h+=`<path d="M${base[pid].map(q=>q[1]+' '+q[2]).join('L')}" fill="none" stroke="#fff" stroke-width=".2" stroke-dasharray=".7 .5" opacity=".85" marker-end="url(#mw)" pointer-events="none"/>`;
|
| 313 |
+
for(let k=1;k<p.length;k++){h+=`<line x1="${p[k-1][1]}" y1="${p[k-1][2]}" x2="${p[k][1]}" y2="${p[k][2]}" stroke="${col(sg[k-1].r,sg[k-1].dt)}" stroke-width="${edited?.42:.3}" stroke-linecap="round" opacity="${edited?1:.85}" filter="url(#glow)" pointer-events="none"/>`;
|
| 314 |
+
sg2+=`<line class="seg" data-k="${k}" x1="${p[k-1][1]}" y1="${p[k-1][2]}" x2="${p[k][1]}" y2="${p[k][2]}" stroke="transparent" stroke-width="1.6" style="cursor:copy"/>`;}
|
| 315 |
+
if(edited){for(let tk=.5;tk<p[p.length-1][0];tk+=.5){const q=pathPos(p,tk); h+=`<circle cx="${q[0]}" cy="${q[1]}" r=".16" fill="#fff" opacity=".8" pointer-events="none"/>`;}
|
| 316 |
+
const q=pathPos(p,t); h+=`<g transform="translate(${q[0]} ${q[1]})" pointer-events="none"><circle r="1.25" fill="rgba(34,211,238,.22)" stroke="#22d3ee" stroke-width=".22"/><text class="pn" dy=".37" style="fill:#22d3ee">${meta[i].num}</text></g>`;}
|
| 317 |
for(let k=0;k<p.length;k++){const on=hsel===k;
|
| 318 |
if(k===0){h+=`<rect x="${p[0][1]-.4}" y="${p[0][2]-.4}" width=".8" height=".8" fill="#fff" opacity=".9" pointer-events="none"/>`; continue;}
|
| 319 |
h+=`<g class="hd" data-k="${k}" transform="translate(${p[k][1]} ${p[k][2]})"><circle r=".95" fill="transparent"/><circle r="${on?.62:.46}" fill="${on?'#ffd400':'#22d3ee'}" stroke="#fff" stroke-width=".15"/>`+
|
| 320 |
`<g transform="translate(0 -1.25)"><rect x="-1.15" y="-.5" width="2.3" height="1" rx=".4" fill="rgba(3,10,26,.9)"/><text class="hl" dy=".24" style="font-size:.66px">${f1(p[k][0])}s</text></g></g>`;}
|
| 321 |
+
gE.innerHTML=h; gSg.innerHTML=sg2;}
|
| 322 |
|
| 323 |
function chyron(rep){
|
| 324 |
const ev=rep.events.filter(e=>e.t<=t+0.001).slice(-1)[0], el=$('#chy');
|
|
|
|
| 357 |
function renderPanel(){
|
| 358 |
const el=$('#side');
|
| 359 |
if(!sel){el.innerHTML=`<h4>Player</h4><div class="hint"><b>Click any player</b> on the field to see his card, separation and speed, and to edit his path.<br><br>
|
| 360 |
+
<b>Move</b> (V): scrub to a moment, then <b>drag the player</b> to where he should be. Or drag a cyan point.<br><b>Draw</b> (D): press a player and <b>drag out his route</b>; it is cleaned up and timed for you.<br><b>Double-click</b> a line to add a point. <b>Right-click</b> a point to remove it. <b>[</b> <b>]</b> retime it.<br><b>Ctrl+Z</b> undo, <b>M</b> mirror.<br><br>
|
| 361 |
Line colour shows what his body can do: <span class="pill ok">green</span> within reach, <span class="pill warn">amber</span> near top speed, <span class="pill bad">red</span> faster than he can run.<br><br>Then press <b>Run what-if</b> to replay the play hundreds of times with your path against the original.</div>`; return;}
|
| 362 |
const i=idx[sel], m=meta[i], hasB=m.ht!=null, ft=hasB?Math.floor(m.ht/12):0, inch=hasB?m.ht%12:0, sg=segs(sel), p=curPath(sel), reps=(mode==='overlay'&&B)?[[A,'#9db0cf',true],[B,'#22d3ee',false]]:[[main(),m.side==='O'?'#9dbcff':'#ff9a9a',false]];
|
| 363 |
const sep=reps.map(r=>({d:series(r[0],i,'sep'),c:r[1],dash:r[2]})), spd=reps.map(r=>({d:series(r[0],i,'spd'),c:r[1],dash:r[2]}));
|
|
|
|
| 375 |
<div class="chartbox"><div class="cap"><span>yards</span><span id="livesep" style="color:#fff;font-weight:700"></span></div>${chartSvg(sep,ymaxS)}</div>
|
| 376 |
<h4>Speed</h4>
|
| 377 |
<div class="chartbox"><div class="cap"><span>mph</span><span id="livesp" style="color:#fff;font-weight:700"></span></div>${chartSvg(spd,ymaxV,m.mph)}</div>
|
| 378 |
+
<h4>${m.side==='O'?'Route tree':'Defender moves'}</h4>
|
| 379 |
+
<div class="rt">${m.side==='O'?Object.keys(ROUTES).map(n=>`<button data-r="${n}">${routeIcon(ROUTES[n])}${n}</button>`).join(''):Object.keys(DEFS).map(n=>`<button data-r="${n}"><span style="font-size:20px;line-height:34px">${{'Break on ball':'☉','Bail deep':'↑','Attack line':'↓','Shade inside':'↖'}[n]}</span>${n}</button>`).join('')}</div>
|
| 380 |
+
<div class="cap" style="padding:0 14px 8px;color:var(--mute);font-size:11.5px">One click lays the route from his snap spot. Then drag the points to fine-tune.</div>
|
| 381 |
<h4>Path · timed waypoints</h4>
|
| 382 |
<table class="wp"><tr><th>pt</th><th>time</th><th>depth</th><th>y</th><th>needs</th></tr>${rows}</table>
|
| 383 |
<div class="tools"><button id="tm">−0.1s</button><button id="tp">+0.1s</button><button id="tdel">Remove point</button><button id="tres">Reset this path</button></div>`;
|
| 384 |
+
if(canReact){const bump=d=>{pushHist(); const v=Math.round(((reacts[sel]||0)+d)*100)/100; if(Math.abs(v)<.001) delete reacts[sel]; else reacts[sel]=Math.max(-.6,Math.min(.6,v)); afterEdit();};
|
| 385 |
+
$('#rm').onclick=()=>bump(-.1); $('#rp').onclick=()=>bump(.1); $('#rr').onclick=()=>{pushHist(); delete reacts[sel]; afterEdit();};}
|
| 386 |
+
el.querySelectorAll('.rt button').forEach(b=>b.onclick=()=>applyRoute(b.dataset.r));
|
| 387 |
+
$('#tm').onclick=()=>retime(-.1); $('#tp').onclick=()=>retime(.1); $('#tdel').onclick=()=>removePt(hsel); $('#tres').onclick=()=>{pushHist(); delete edits[sel]; hsel=null; afterEdit();};
|
| 388 |
el.querySelectorAll('table.wp tr[data-k]').forEach(r=>r.onclick=()=>{hsel=+r.dataset.k||null; renderPanel(); renderEdit();});
|
| 389 |
renderCharts();}
|
| 390 |
|
| 391 |
// ------------------------------------------------------------------ editing
|
| 392 |
+
function stateStr(){return JSON.stringify({e:edits,r:reacts});}
|
| 393 |
+
function pushHist(){hist.push(stateStr()); if(hist.length>80) hist.shift(); redoS=[]; tbState();}
|
| 394 |
+
function restore(str){const o=JSON.parse(str); edits=o.e; reacts=o.r; hsel=null; afterEdit();}
|
| 395 |
+
function undo(){if(!hist.length) return; redoS.push(stateStr()); restore(hist.pop());}
|
| 396 |
+
function redo(){if(!redoS.length) return; hist.push(stateStr()); restore(redoS.pop());}
|
| 397 |
+
function toast(m){const e=$('#toast'); e.textContent=m; e.style.display='block'; clearTimeout(toast.h); toast.h=setTimeout(()=>e.style.display='none',2200);}
|
| 398 |
+
function pathPos(p,tt){if(tt<=p[0][0]) return [p[0][1],p[0][2]];
|
| 399 |
+
for(let i=1;i<p.length;i++) if(tt<=p[i][0]){const u=(tt-p[i-1][0])/Math.max(1e-6,p[i][0]-p[i-1][0]); return [p[i-1][1]+(p[i][1]-p[i-1][1])*u,p[i-1][2]+(p[i][2]-p[i-1][2])*u];}
|
| 400 |
+
const l=p[p.length-1]; return [l[1],l[2]];}
|
| 401 |
+
function pathLen(p){let L=0; for(let i=1;i<p.length;i++) L+=Math.hypot(p[i][1]-p[i-1][1],p[i][2]-p[i-1][2]); return L;}
|
| 402 |
+
function paceSpeed(pid){const vm=meta[idx[pid]].vmax, b=base[pid], L=pathLen(b), T=b[b.length-1][0]-b[0][0];
|
| 403 |
+
if(pace==='fast') return vm*.92; if(pace==='jog') return vm*.55;
|
| 404 |
+
const v=T>0.3&&L>2?L/T:vm*.7; return clamp(v,vm*.45,vm*.95);}
|
| 405 |
+
function rdp(pts,eps){if(pts.length<3) return pts.slice(); let dm=0,ix=0; const a=pts[0],b=pts[pts.length-1], dx=b[0]-a[0], dy=b[1]-a[1], L=Math.hypot(dx,dy)||1e-9;
|
| 406 |
+
for(let i=1;i<pts.length-1;i++){const d=Math.abs((pts[i][0]-a[0])*dy-(pts[i][1]-a[1])*dx)/L; if(d>dm){dm=d;ix=i;}}
|
| 407 |
+
if(dm<=eps) return [a,b]; const l=rdp(pts.slice(0,ix+1),eps), r=rdp(pts.slice(ix),eps); return l.slice(0,-1).concat(r);}
|
| 408 |
+
function timed(pid,xy){ // xy: [[x,y]...] starting at his snap spot; assign times from the chosen pace
|
| 409 |
+
const v=paceSpeed(pid); let tt=0, out=[[0,+xy[0][0].toFixed(2),+xy[0][1].toFixed(2)]];
|
| 410 |
+
for(let i=1;i<xy.length;i++){tt+=Math.max(.1,Math.hypot(xy[i][0]-xy[i-1][0],xy[i][1]-xy[i-1][1])/v); out.push([+tt.toFixed(2),+xy[i][0].toFixed(2),+xy[i][1].toFixed(2)]);}
|
| 411 |
+
if(tt>7.5){const f=7.5/tt; for(let i=1;i<out.length;i++) out[i][0]=+Math.max(out[i-1][0]+.1,out[i][0]*f).toFixed(2);}
|
| 412 |
+
return out;}
|
| 413 |
+
function setRoute(pid,xy){const p0=base[pid][0]; xy=xy.map(q=>[clamp(q[0],.5,119.5),clamp(q[1],.5,W-.5)]); xy[0]=[p0[1],p0[2]];
|
| 414 |
+
if(pathLen(timed(pid,xy).map(q=>q))<1.2){toast('Too short. Draw a longer line.'); return false;}
|
| 415 |
+
pushHist(); edits[pid]=timed(pid,xy); hsel=null; return true;}
|
| 416 |
+
function strokeToRoute(pid,pts){const p0=base[pid][0]; let xy=[[p0[1],p0[2]]].concat(pts);
|
| 417 |
+
// light smoothing, then simplify to a few clean corners
|
| 418 |
+
const sm=xy.map((q,i)=>(i===0||i===xy.length-1)?q:[(xy[i-1][0]+2*q[0]+xy[i+1][0])/4,(xy[i-1][1]+2*q[1]+xy[i+1][1])/4]);
|
| 419 |
+
let eps=.55, r=rdp(sm,eps); while(r.length>8&&eps<4){eps+=.25; r=rdp(sm,eps);} return r;}
|
| 420 |
+
function placeAt(pid,tt,x,y){ // put him at (x,y) at time tt: move the nearest point, or insert one
|
| 421 |
+
const p=ownPath(pid); tt=+clamp(tt,.2,7.9).toFixed(2); x=+clamp(x,.5,119.5).toFixed(2); y=+clamp(y,.5,W-.5).toFixed(2);
|
| 422 |
+
let k=-1,bd=1e9; for(let i=1;i<p.length;i++){const d=Math.abs(p[i][0]-tt); if(d<bd){bd=d;k=i;}}
|
| 423 |
+
if(k>0&&bd<.15){p[k][1]=x;p[k][2]=y;} else {let j=1; while(j<p.length&&p[j][0]<tt) j++; p.splice(j,0,[tt,x,y]); k=j;}
|
| 424 |
+
hsel=k;}
|
| 425 |
+
const ROUTES={ // depth (yards downfield) and lateral (+ toward his sideline) from the snap
|
| 426 |
+
Go:[[22,0]],Slant:[[2,0],[9,-6]],Out:[[10,0],[10,8]],Dig:[[12,0],[12,-12]],Post:[[10,0],[22,-8]],Corner:[[10,0],[20,8]],Curl:[[12,0],[10,-1.5]],Flat:[[.5,5],[1,11]]};
|
| 427 |
+
const DEFS={'Break on ball':'ball','Bail deep':[[10,0]],'Attack line':[[-5,0]],'Shade inside':[[3,-4]]};
|
| 428 |
+
function routeXY(pid,def){const p0=base[pid][0], m=meta[idx[pid]], out=p0[2]<W/2?-1:1, sgn=m.side==='O'?1:1;
|
| 429 |
+
if(def==='ball'){const rp=A, lt=(rp.marks&&rp.marks.land)||endT(rp), b=ballAt(rp,lt); return [[p0[1],p0[2]],[b[0],b[1]]];}
|
| 430 |
+
return [[p0[1],p0[2]]].concat(def.map(d=>[p0[1]+d[0]*sgn,p0[2]+d[1]*out]));}
|
| 431 |
+
function applyRoute(name){if(!sel) return; const def=ROUTES[name]||DEFS[name]; if(!setRoute(sel,routeXY(sel,def))) return; afterEdit();}
|
| 432 |
+
function routeIcon(def){ // tiny pictogram of a route
|
| 433 |
+
const pts=def.map(d=>[d[1]*1.4+17,32-d[0]*1.3]); let xy=[[17,32]].concat(pts); const d='M'+xy.map(q=>q[0].toFixed(1)+' '+clamp(q[1],3,32).toFixed(1)).join('L');
|
| 434 |
+
return `<svg viewBox="0 0 34 34"><path d="${d}" fill="none" stroke="#22d3ee" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/><circle cx="17" cy="32" r="2.4" fill="#fff"/></svg>`;}
|
| 435 |
+
function mirror(){if(!sel) return; const b=base[sel][0][2]; pushHist(); const p=ownPath(sel); for(let i=1;i<p.length;i++) p[i][2]=+clamp(2*b-p[i][2],.5,W-.5).toFixed(2); afterEdit();}
|
| 436 |
+
function tbState(){$('#bundo').disabled=!hist.length; $('#bredo').disabled=!redoS.length; $('#bmir').disabled=!sel;
|
| 437 |
+
$('#tmove').className=tool==='move'?'on':''; $('#tdraw').className=tool==='draw'?'on':''; svg.classList.toggle('drawing',tool==='draw');
|
| 438 |
+
const c=$('#coach'); c.style.display='block';
|
| 439 |
+
c.innerHTML=tool==='draw'?(sel?`<b>Draw:</b> press anywhere and drag his route. It starts at his snap spot.`:`<b>Draw:</b> press on a player and drag out his route.`)
|
| 440 |
+
:(sel?`<b>Move:</b> scrub to a moment, then drag him to where he should be. Or drag a cyan point.`:`<b>Click a player</b> to edit him. Press <b>D</b> to draw a route.`);}
|
| 441 |
+
function afterEdit(){renderPanel(); renderDynamic(); status(); tbState(); post('edits');}
|
| 442 |
+
function retime(dt){if(!sel||!hsel) return; pushHist(); const p=ownPath(sel), k=hsel; const lo=p[k-1][0]+.1, hi=k+1<p.length?p[k+1][0]-.1:8; p[k][0]=+clamp(p[k][0]+dt,lo,hi).toFixed(2); afterEdit();}
|
| 443 |
+
function removePt(k){if(!sel||!k) return; const p=ownPath(sel); if(p.length<=2||k<=0) return; pushHist(); p.splice(k,1); hsel=null; afterEdit();}
|
| 444 |
let dragH=null;
|
| 445 |
+
function selectPlayer(id){if(sel===id) return; sel=id; hsel=null; renderPanel(); renderDynamic(); status(); tbState(); post('sel');}
|
| 446 |
+
function drawPreview(){ // live line while drawing, and live ghost while placing a player
|
| 447 |
+
let h='';
|
| 448 |
+
if(drawing){const pid=sel, xy=strokeToRoute(pid,drawing.pts), tm=timed(pid,xy), vm=meta[idx[pid]].vmax;
|
| 449 |
+
for(let i=1;i<tm.length;i++){const dt=tm[i][0]-tm[i-1][0], v=Math.hypot(tm[i][1]-tm[i-1][1],tm[i][2]-tm[i-1][2])/dt;
|
| 450 |
+
h+=`<line x1="${tm[i-1][1]}" y1="${tm[i-1][2]}" x2="${tm[i][1]}" y2="${tm[i][2]}" stroke="${col(v/vm,dt)}" stroke-width=".42" stroke-linecap="round" filter="url(#glow)"/>`;}
|
| 451 |
+
h+=`<path d="M${drawing.pts.map(q=>q[0].toFixed(2)+' '+q[1].toFixed(2)).join('L')}" fill="none" stroke="#fff" stroke-width=".12" opacity=".55"/>`;
|
| 452 |
+
h+=tm.map(q=>`<circle cx="${q[1]}" cy="${q[2]}" r=".34" fill="#22d3ee" stroke="#fff" stroke-width=".1"/>`).join('');
|
| 453 |
+
const l=tm[tm.length-1]; h+=`<g transform="translate(${l[1]} ${l[2]-1.3})"><rect x="-1.15" y="-.5" width="2.3" height="1" rx=".4" fill="rgba(3,10,26,.9)"/><text class="hl" dy=".24" style="font-size:.66px">${f1(l[0])}s</text></g>`;}
|
| 454 |
+
if(bodyDrag&&bodyDrag.moved){const m=meta[idx[bodyDrag.id]], q=bodyDrag.cur;
|
| 455 |
+
h+=`<g transform="translate(${q[0]} ${q[1]})"><circle r="1.15" fill="rgba(34,211,238,.28)" stroke="#22d3ee" stroke-width=".2" stroke-dasharray=".4 .25"/><text class="pn" dy=".37">${m.num}</text>`+
|
| 456 |
+
`<g transform="translate(0 -1.9)"><rect x="-1.5" y="-.52" width="3" height="1.04" rx=".45" fill="#22d3ee"/><text class="hl" dy=".25" style="font-size:.7px;fill:#041a24">at ${f1(t)}s</text></g></g>`;}
|
| 457 |
+
gE.innerHTML=h;}
|
| 458 |
svg.addEventListener('pointerdown',e=>{
|
| 459 |
+
if(e.button!==0&&e.pointerType==='mouse') return;
|
| 460 |
+
const hd=e.target.closest('.hd'); if(hd&&tool==='move'){pushHist(); dragH={k:+hd.dataset.k}; hsel=dragH.k; svg.setPointerCapture(e.pointerId); ownPath(sel); renderPanel(); renderEdit(); e.preventDefault(); return;}
|
| 461 |
+
const pl=e.target.closest('.pl');
|
| 462 |
+
if(tool==='draw'){
|
| 463 |
+
if(pl) selectPlayer(pl.dataset.id);
|
| 464 |
+
if(!sel) return;
|
| 465 |
+
drawing={pts:[toSvg(e)]}; playing=false; $('#bplay').innerHTML='▶'; svg.setPointerCapture(e.pointerId); e.preventDefault(); return;}
|
| 466 |
+
if(pl){selectPlayer(pl.dataset.id); const id=pl.dataset.id, p=posAt(main(),idx[id],t), q=toSvg(e);
|
| 467 |
+
bodyDrag={id:id,off:[p[0]-q[0],p[1]-q[1]],start:q,moved:false,cur:p}; svg.setPointerCapture(e.pointerId); e.preventDefault(); return;}
|
| 468 |
+
if(!e.target.closest('.seg')){ if(sel){selectPlayer(null);} }});
|
| 469 |
+
svg.addEventListener('pointermove',e=>{
|
| 470 |
+
if(drawing){const q=toSvg(e), l=drawing.pts[drawing.pts.length-1]; if(Math.hypot(q[0]-l[0],q[1]-l[1])>.3){drawing.pts.push(q); drawPreview();} return;}
|
| 471 |
+
if(bodyDrag){const q=toSvg(e); if(!bodyDrag.moved&&Math.hypot(q[0]-bodyDrag.start[0],q[1]-bodyDrag.start[1])<.6) return;
|
| 472 |
+
if(!bodyDrag.moved){bodyDrag.moved=true; playing=false; $('#bplay').innerHTML='▶';}
|
| 473 |
+
bodyDrag.cur=[q[0]+bodyDrag.off[0],q[1]+bodyDrag.off[1]]; drawPreview(); return;}
|
| 474 |
+
if(!dragH) return; const [mx,my]=toSvg(e), p=ownPath(sel), k=dragH.k; p[k][1]=+clamp(mx,.5,119.5).toFixed(2); p[k][2]=+clamp(my,.5,W-.5).toFixed(2); renderEdit();
|
| 475 |
const row=document.querySelector(`table.wp tr[data-k="${k}"]`); if(row){const c=row.children; c[2].textContent=(p[k][1]-bx>=0?'+':'')+f1(p[k][1]-bx); c[3].textContent=f1(p[k][2]);}});
|
| 476 |
+
function endDrag(){
|
| 477 |
+
if(drawing){const d=drawing; drawing=null; if(d.pts.length>1&&setRoute(sel,strokeToRoute(sel,d.pts))){afterEdit(); toast('Route drawn. Scrub or play to watch him run it, then Run what-if.');} else renderEdit(); return;}
|
| 478 |
+
if(bodyDrag){const b=bodyDrag; bodyDrag=null; if(b.moved){pushHist(); placeAt(b.id,t,b.cur[0],b.cur[1]); afterEdit();} else renderEdit(); return;}
|
| 479 |
+
if(!dragH) return; dragH=null; afterEdit();}
|
| 480 |
svg.addEventListener('pointerup',endDrag); svg.addEventListener('pointercancel',endDrag);
|
| 481 |
svg.addEventListener('dblclick',e=>{const sg=e.target.closest('.seg'); if(!sg||!sel) return; const k=+sg.dataset.k, p=ownPath(sel), [mx,my]=toSvg(e);
|
| 482 |
const a=p[k-1], b=p[k], dx=b[1]-a[1], dy=b[2]-a[2], L2=dx*dx+dy*dy||1e-9, f=clamp(((mx-a[1])*dx+(my-a[2])*dy)/L2,.1,.9);
|
| 483 |
+
pushHist(); p.splice(k,0,[+(a[0]+(b[0]-a[0])*f).toFixed(2),+(a[1]+dx*f).toFixed(2),+(a[2]+dy*f).toFixed(2)]); hsel=k; afterEdit();});
|
| 484 |
svg.addEventListener('contextmenu',e=>{const hd=e.target.closest('.hd'); if(hd){e.preventDefault(); removePt(+hd.dataset.k);}});
|
| 485 |
window.addEventListener('keydown',e=>{
|
| 486 |
+
if(e.target&&/SELECT|INPUT|TEXTAREA/.test(e.target.tagName)) return;
|
| 487 |
+
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='z'){e.preventDefault(); e.shiftKey?redo():undo(); return;}
|
| 488 |
+
if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()==='y'){e.preventDefault(); redo(); return;}
|
| 489 |
+
if(e.key==='d'||e.key==='D'){tool='draw'; tbState(); return;} if(e.key==='v'||e.key==='V'){tool='move'; tbState(); return;} if(e.key==='m'||e.key==='M'){mirror(); return;}
|
| 490 |
if(e.key==='['){retime(-.1);} else if(e.key===']'){retime(.1);} else if((e.key==='Delete'||e.key==='Backspace')&&hsel){removePt(hsel);} else if(e.key==='Escape'){sel=null;hsel=null;renderPanel();renderDynamic();status();post('sel');}
|
| 491 |
else if(e.key===' '){e.preventDefault(); togglePlay();}});
|
| 492 |
|
|
|
|
| 505 |
function togglePlay(){if(!playing&&t>=TMAX-.05) t=0; playing=!playing; $('#bplay').innerHTML=playing?'❚❚':'▶';}
|
| 506 |
$('#bplay').onclick=togglePlay; $('#brest').onclick=()=>{t=0; playing=true; $('#bplay').innerHTML='❚❚'; renderDynamic(); renderCharts();};
|
| 507 |
$('#bspd').onchange=e=>{speed=+e.target.value;};
|
| 508 |
+
$('#brun').onclick=()=>{post('run');}; $('#breset').onclick=()=>{pushHist(); edits={}; reacts={}; hsel=null; afterEdit();};
|
| 509 |
$('#bexp').onclick=()=>{const o={level:C.levelShort,offense:C.offPlay,defense:C.defCall,ball:[bx,by],original:base,edits:changed(),reaction_changes:reactsChanged()};
|
| 510 |
const a=document.createElement('a'); a.href=URL.createObjectURL(new Blob([JSON.stringify(o,null,2)],{type:'application/json'})); a.download='hawk_one_paths.json'; a.click();};
|
| 511 |
let last=performance.now();
|
| 512 |
function loop(now){const dt=Math.min(.1,(now-last)/1000); last=now; if(playing){t+=dt*speed; if(t>=TMAX){t=TMAX; playing=false; $('#bplay').innerHTML='▶';} renderDynamic(); renderCharts();} requestAnimationFrame(loop);}
|
| 513 |
+
$('#tmove').onclick=()=>{tool='move'; tbState();}; $('#tdraw').onclick=()=>{tool='draw'; tbState();};
|
| 514 |
+
$('#bundo').onclick=undo; $('#bredo').onclick=redo; $('#bmir').onclick=mirror; $('#pace').onchange=e=>{pace=e.target.value;};
|
| 515 |
window.addEventListener('resize',setView);
|
| 516 |
// test hooks (used by the automated checks)
|
| 517 |
+
window.__film={get tool(){return tool;},get hist(){return hist.length;},get t0(){return t;},get sel(){return sel;},get edits(){return changed();},set t(v){t=v; renderDynamic(); renderCharts();},get mode(){return mode;}};
|
| 518 |
+
drawField(); drawOver(); drawMode(); bug(); renderPanel(); renderDynamic(); status(); tbState(); $('#bghost').className=ghostHash?'on':'';
|
| 519 |
setTimeout(()=>{setView(); if(C.autoplay){playing=true; $('#bplay').innerHTML='❚❚';}},50);
|
| 520 |
requestAnimationFrame(n=>{last=n; loop(n);});
|
| 521 |
})();
|
|
|
|
| 550 |
def build_film_doc(*a, **k) -> str:
|
| 551 |
"""The bare document (for headless checks)."""
|
| 552 |
h = build_film_html(*a, **k)
|
| 553 |
+
return html.unescape(h.split('srcdoc="', 1)[1].rsplit('" sandbox', 1)[0])
|