mirror of
https://git.j0bot.ch/admin_j0bot/ploxion-simulation.git
synced 2026-11-29 07:15:05 +00:00
synchro du labo (0bf0da65) : app.blade.php, README.md
This commit is contained in:
parent
3fed14950a
commit
e4f61d6d3b
22
README.md
22
README.md
@ -1,3 +1,21 @@
|
|||||||
# ploxion-simulation
|
# 🎮 Simulation
|
||||||
|
|
||||||
PLOXION · La simulation du xerboxion : des agents-humains parcourent le site comme des humains (idée → objet) et tu les regardes se balader en live — leurs curseurs, leurs pages, leurs actions, et les frictions qu'ils trouvent. · fournit: simulation, agents, live, audit
|
La simulation du xerboxion : des agents-humains parcourent le site comme des humains (idée → objet) et tu les regardes se balader en live — leurs curseurs, leurs pages, leurs actions, et les frictions qu'ils trouvent.
|
||||||
|
|
||||||
|
| | |
|
||||||
|
| --- | --- |
|
||||||
|
| id | `simulation` |
|
||||||
|
| fournit | `simulation` `agents` `live` `audit` |
|
||||||
|
| bions qu'il nomme | `jOSApps` |
|
||||||
|
| fichiers | `app.blade.php` |
|
||||||
|
| dans le labo | `resources/views/ploxions/simulation/` (dépôt `my_website2`) |
|
||||||
|
|
||||||
|
## Contribuer
|
||||||
|
|
||||||
|
- **Dans le xer** : https://labo.j0bot.ch/px/atelier?ploxion=simulation — prends-le, modifie-le, vois-le tourner, « ⧗ envoyer le tsoin ».
|
||||||
|
- **Dans VS Code** : `xb prendre simulation` (ou l'extension xerboxion › ⇩ Prendre), puis ⧗ Envoyer.
|
||||||
|
- Le chemin complet : https://labo.j0bot.ch/px/contribuer
|
||||||
|
|
||||||
|
Ce dépôt est un **miroir** du labo (synchronisé par `bin/ploxions-forge.mjs`, depuis le commit `0bf0da65`) : une modif se propose par un tsoin ou une branche du labo, pas directement ici.
|
||||||
|
|
||||||
|
© 2026 chill-tekk · ne pas nuire
|
||||||
|
|||||||
273
app.blade.php
Normal file
273
app.blade.php
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
{{-- PL0XI0N simulation — LA SIMULATION DU XERBOXION (RS-7 : « plein d'agents qui naviguent
|
||||||
|
comme des humains, je veux les voir se balader, leur curseur, tout »). Les agents-humains
|
||||||
|
(drivers CDP) émettent leurs battements sur POST /px/sim/beat ; on les regarde en LIVE
|
||||||
|
(mini-écran/agent : curseur+traînée+page+étape), + le flux d'actions et les FRICTIONS.
|
||||||
|
v3 (backlog critique) : REPLAY d'un parcours = un TSOIN (choisir un run passé → scrubber
|
||||||
|
play/pause+slider, les curseurs rejouent leur tape) · friction→fichier (typée page+ploxion,
|
||||||
|
↗ ouvre la page, clic = seek le replay sur la friction) · HISTORIQUE des runs.
|
||||||
|
Poll /px/sim/state.json (live) · /px/sim/runs.json (liste) · /px/sim/run/<id>.json (tape). --}}
|
||||||
|
<style>
|
||||||
|
.sm{display:flex;flex-direction:column;height:100%;background:var(--xr-bg,#101408);color:var(--xr-text,#e8e4d2);font-family:ui-rounded,ui-sans-serif,system-ui,sans-serif;font-size:.84rem;overflow:hidden}
|
||||||
|
.sm__top{flex:0 0 auto;display:flex;align-items:center;gap:10px;padding:10px 14px;border-bottom:1px solid rgba(232,228,210,.14);flex-wrap:wrap}
|
||||||
|
.sm__top b{color:var(--xr-accent,#c2c98a)}
|
||||||
|
.sm__live{width:9px;height:9px;border-radius:50%;background:#8fae77;animation:smpulse 1.6s ease-in-out infinite;box-shadow:0 0 8px #8fae77}
|
||||||
|
.sm.replay .sm__live{background:#e8b06a;box-shadow:0 0 8px #e8b06a;animation:none}
|
||||||
|
@keyframes smpulse{0%,100%{opacity:.4}50%{opacity:1}}
|
||||||
|
.sm__runs{margin-left:auto;display:flex;align-items:center;gap:6px}
|
||||||
|
.sm__runs select,.sm__btn{background:var(--xr-surface,#1c220f);color:var(--xr-text,#e8e4d2);border:1px solid rgba(232,228,210,.2);border-radius:8px;padding:4px 8px;font-size:.72rem;cursor:pointer}
|
||||||
|
.sm__btn:hover{border-color:var(--xr-accent,#c2c98a)}
|
||||||
|
.sm__transport{flex:0 0 auto;display:none;align-items:center;gap:10px;padding:7px 14px;border-bottom:1px solid rgba(232,228,210,.14);background:var(--xr-surface,#141a0b)}
|
||||||
|
.sm.replay .sm__transport{display:flex}
|
||||||
|
.sm__transport input[type=range]{flex:1;accent-color:#e8b06a}
|
||||||
|
.sm__tt{font-family:ui-monospace,monospace;font-size:.7rem;color:var(--xr-accent,#c2c98a);min-width:78px}
|
||||||
|
.sm__body{flex:1;min-height:0;display:flex;overflow:hidden}
|
||||||
|
.sm__grid{flex:1;min-width:0;overflow:auto;padding:12px;display:grid;grid-template-columns:repeat(auto-fill,minmax(230px,1fr));gap:12px;align-content:start}
|
||||||
|
.sm__ag{border:1px solid rgba(232,228,210,.16);border-left:4px solid var(--agc,#8fae77);border-radius:12px;background:var(--xr-surface,#171c0d);overflow:hidden;transition:opacity .5s ease}
|
||||||
|
.sm__ag.done{opacity:.6} .sm__ag.stale{opacity:.32;filter:grayscale(.6)}
|
||||||
|
.sm__agh{display:flex;align-items:center;gap:7px;padding:7px 10px;font-size:.76rem;border-bottom:1px solid rgba(232,228,210,.1)}
|
||||||
|
.sm__agh b{color:#fff;flex:0 1 auto;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.sm__q{flex:0 0 auto;font-size:.6rem;padding:2px 6px;border-radius:20px;background:var(--agc,#8fae77);color:#0c0f07;font-weight:700;max-width:52%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.sm__age{flex:0 0 auto;margin-left:auto;font-size:.58rem;color:var(--xr-muted,#8a9370);font-family:ui-monospace,monospace}
|
||||||
|
.sm__cv{display:block;width:100%;background:#0c0f07}
|
||||||
|
.sm__pg{padding:3px 10px 0;font-size:.6rem;color:var(--xr-muted,#a8b878);font-family:ui-monospace,monospace;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||||
|
.sm__step{padding:3px 10px 7px;font-size:.68rem;color:var(--xr-accent,#c2c98a);min-height:1.3em;line-height:1.35}
|
||||||
|
.sm__side{flex:0 0 300px;border-left:1px solid rgba(232,228,210,.14);display:flex;flex-direction:column;min-height:0}
|
||||||
|
.sm__sh{flex:0 0 auto;padding:9px 12px;font-size:.7rem;font-weight:700;color:var(--xr-accent,#c2c98a);text-transform:uppercase;letter-spacing:.06em}
|
||||||
|
.sm__log{flex:1;min-height:0;overflow:auto;padding:0 12px 10px;font:.7rem ui-monospace,monospace;line-height:1.65;color:rgba(232,228,210,.75)}
|
||||||
|
.sm__log .ag{font-weight:700}
|
||||||
|
.sm__fr{flex:0 0 auto;max-height:42%;overflow:auto;border-top:1px solid rgba(232,228,210,.14);padding:0 12px 10px;font-size:.72rem;line-height:1.5}
|
||||||
|
.sm__fr li{margin:6px 0;list-style:none}
|
||||||
|
.sm__fr .fq{color:#e8b06a;cursor:pointer} .sm__fr .fq:hover{text-decoration:underline}
|
||||||
|
.sm__fr .fmeta{display:block;font-size:.62rem;color:var(--xr-muted,#8a9370);font-family:ui-monospace,monospace;margin-top:1px}
|
||||||
|
.sm__fr .fmeta a{color:#7d9fe8;text-decoration:none;margin-right:8px} .sm__fr .fmeta a:hover{text-decoration:underline}
|
||||||
|
.sm__empty{margin:auto;text-align:center;color:rgba(232,228,210,.45);line-height:1.7;padding:30px}
|
||||||
|
@media (max-width:640px){
|
||||||
|
.sm__body{flex-direction:column}
|
||||||
|
.sm__grid{grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:9px;padding:9px}
|
||||||
|
.sm__side{flex:0 0 auto;width:100%;max-height:42%;border-left:0;border-top:1px solid rgba(232,228,210,.14)}
|
||||||
|
.sm__top .sm__hint{display:none}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
'use strict';
|
||||||
|
var ID='simulation';
|
||||||
|
var COLS=['#8fae77','#e8b06a','#7d9fe8','#d98ad1','#6fc7c0','#e87d7d','#c2c98a','#a58ae8'];
|
||||||
|
var STALE=90;
|
||||||
|
function esc(s) { return window.jOSb.esc(s); }
|
||||||
|
function color(name){var h=0;for(var i=0;i<name.length;i++)h=(h*31+name.charCodeAt(i))>>>0;return COLS[h%COLS.length];}
|
||||||
|
function now(){return Date.now()/1000;}
|
||||||
|
function fmt(s){s=Math.max(0,Math.round(s));return Math.floor(s/60)+':'+('0'+(s%60)).slice(-2);}
|
||||||
|
// page -> id de ploxion (best effort) pour le lien friction->fichier
|
||||||
|
function ploxIdOf(fr){ if(fr.ploxion)return fr.ploxion; var p=fr.page||''; var m=p.match(/\/px\/([a-z0-9-]+)/i)||p.match(/\/\/([a-z0-9-]+)\.j0bot\.ch/i); return m?m[1]:null; }
|
||||||
|
|
||||||
|
var LIVE=null; // posé au mount : {count:function(),mode:function()}
|
||||||
|
function describe(){
|
||||||
|
var n = LIVE ? LIVE.count() : 0, m = LIVE ? LIVE.mode() : 'live';
|
||||||
|
return { v:1, id:ID, title:'Simulation', icon:'🎮', items:[
|
||||||
|
{ p:1, kind:'stat', label:'agents visibles', value:n },
|
||||||
|
{ p:2, kind:'stat', label:'mode', value:m }
|
||||||
|
]};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mount(container){
|
||||||
|
var alive=true, tiles={}, raf=null, mode='live';
|
||||||
|
LIVE = { count: function () { return Object.keys(tiles).length; }, mode: function () { return mode; } };
|
||||||
|
var replay={run:null,agents:null,t0:0,t1:0,playT:0,playing:false,speed:1,last:0,frictions:[]};
|
||||||
|
container.innerHTML='<div class="sm">'
|
||||||
|
+'<div class="sm__top"><span class="sm__live"></span><b>simulation du xerboxion</b><span style="font-size:.7rem;opacity:.6" data-n>en attente d\'agents…</span>'
|
||||||
|
+'<span class="sm__hint" style="font-size:.64rem;opacity:.45">idée→objet (map du cahier rs-7)</span>'
|
||||||
|
+'<span class="sm__runs"><select data-runs><option value="">▶ live</option></select></span></div>'
|
||||||
|
+'<div class="sm__transport"><button class="sm__btn" data-play>▶</button><span class="sm__tt" data-tt>0:00 / 0:00</span><input type="range" data-seek min="0" max="1000" value="0"><button class="sm__btn" data-exit>✕ live</button></div>'
|
||||||
|
+'<div class="sm__body"><div class="sm__grid" data-grid><div class="sm__empty">🎮 Aucun agent en balade.<br>La flotte lance les personas — leurs curseurs apparaîtront ici.<br><span style="font-size:.7rem">choisis un run passé dans le menu ▾ pour rejouer un parcours (tsoin).</span></div></div>'
|
||||||
|
+'<div class="sm__side"><div class="sm__sh">flux des actions</div><div class="sm__log" data-log></div>'
|
||||||
|
+'<div class="sm__sh" style="border-top:1px solid rgba(232,228,210,.14)">⚠ frictions trouvées</div><ul class="sm__fr" data-fr></ul></div></div></div>';
|
||||||
|
var root=container.querySelector('.sm'), grid=container.querySelector('[data-grid]'), logEl=container.querySelector('[data-log]'),
|
||||||
|
frEl=container.querySelector('[data-fr]'), nEl=container.querySelector('[data-n]'), runsSel=container.querySelector('[data-runs]'),
|
||||||
|
playBtn=container.querySelector('[data-play]'), ttEl=container.querySelector('[data-tt]'), seekEl=container.querySelector('[data-seek]');
|
||||||
|
var lastLogKey='';
|
||||||
|
|
||||||
|
function cleanStep(a){
|
||||||
|
var s=(a.step||'').trim();
|
||||||
|
if(s===a.agent||s===a.quest) s='';
|
||||||
|
if(a.done){ s=s.replace(/^\s*(quête\s+)?terminée?\s*[:—-]?\s*/i,''); return '✓ '+(s||'terminé'); }
|
||||||
|
if(!s){ var pg=(a.page||'').replace(/^https?:\/\/[^/]+/,'')||'/'; return 'sur '+pg; }
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
function ensureTile(a){
|
||||||
|
var t=tiles[a.agent], col=color(a.agent);
|
||||||
|
if(!t){
|
||||||
|
var el=document.createElement('div');el.className='sm__ag';el.style.setProperty('--agc',col);
|
||||||
|
el.innerHTML='<div class="sm__agh"><span>'+esc(a.emoji||'🤖')+'</span><b>'+esc(a.agent)+'</b>'
|
||||||
|
+'<span class="sm__q" hidden></span><span class="sm__age"></span></div>'
|
||||||
|
+'<canvas class="sm__cv" width="230" height="130"></canvas>'
|
||||||
|
+'<div class="sm__pg"></div><div class="sm__step"></div>';
|
||||||
|
grid.appendChild(el);
|
||||||
|
var e0=grid.querySelector('.sm__empty'); if(e0)e0.remove();
|
||||||
|
t=tiles[a.agent]={el:el,cv:el.querySelector('canvas'),q:el.querySelector('.sm__q'),age:el.querySelector('.sm__age'),
|
||||||
|
pg:el.querySelector('.sm__pg'),st:el.querySelector('.sm__step'),cx:null,cy:null,tx:0,ty:0,data:a};
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
function clearTiles(){ Object.keys(tiles).forEach(function(k){ tiles[k].el.remove(); }); tiles={}; }
|
||||||
|
|
||||||
|
// ---------- LIVE ----------
|
||||||
|
function liveTile(a){
|
||||||
|
var t=ensureTile(a);
|
||||||
|
t.data=a;
|
||||||
|
var age=now()-(a.t||0), stale=age>STALE;
|
||||||
|
t.el.classList.toggle('done',!!a.done); t.el.classList.toggle('stale',stale);
|
||||||
|
if(a.quest){ t.q.hidden=false; t.q.textContent='🗺️ '+a.quest; } else t.q.hidden=true;
|
||||||
|
t.age.textContent = stale?'figé':(age<3?'live':('il y a '+Math.round(age)+'s'));
|
||||||
|
t.pg.textContent=(a.page||'').replace(/^https?:\/\/[^/]+/,'')||'/';
|
||||||
|
t.st.textContent=cleanStep(a);
|
||||||
|
var vw=a.vw||1200, vh=a.vh||800, W=t.cv.width, H=t.cv.height;
|
||||||
|
if(typeof a.x==='number'){ t.tx=a.x/vw*W; t.ty=a.y/vh*H; if(t.cx===null){t.cx=t.tx;t.cy=t.ty;} }
|
||||||
|
t.trailPts=(a.trail||[]).map(function(pt){return [pt[0]/vw*W,pt[1]/vh*H];});
|
||||||
|
}
|
||||||
|
function poll(){
|
||||||
|
if(!alive)return;
|
||||||
|
fetch('/px/sim/state.json',{cache:'no-store'}).then(function(r){return r.json();}).then(function(st){
|
||||||
|
if(!alive||mode!=='live')return;
|
||||||
|
var agents=Object.values(st||{});
|
||||||
|
var active=agents.filter(function(a){return !a.done && (now()-(a.t||0))<STALE;}).length;
|
||||||
|
var frozen=agents.filter(function(a){return (now()-(a.t||0))>=STALE;}).length;
|
||||||
|
nEl.textContent=agents.length? (active+' en balade · '+agents.length+' au total'+(frozen?' · '+frozen+' figé'+(frozen>1?'s':''):'')) : 'en attente d\'agents…';
|
||||||
|
agents.sort(function(a,b){return (b.t||0)-(a.t||0);});
|
||||||
|
var seen={}; agents.forEach(function(a){seen[a.agent]=1;liveTile(a);});
|
||||||
|
Object.keys(tiles).forEach(function(k){if(!seen[k]){tiles[k].el.remove();delete tiles[k];}});
|
||||||
|
var rows=[];agents.forEach(function(a){(a.log||[]).slice(-8).forEach(function(l){rows.push({t:l[0],ag:a.agent,em:a.emoji||'',tx:l[1],c:color(a.agent)});});});
|
||||||
|
rows.sort(function(a,b){return a.t<b.t?1:-1;});rows=rows.slice(0,50);
|
||||||
|
var key=rows.length?(rows[0].t+rows[0].ag+rows[0].tx):'';
|
||||||
|
if(key!==lastLogKey){lastLogKey=key;
|
||||||
|
logEl.innerHTML=rows.map(function(r){return '<div>'+r.t+' <span class="ag" style="color:'+r.c+'">'+esc(r.em+' '+r.ag)+'</span> '+esc(r.tx)+'</div>';}).join('');}
|
||||||
|
var frs=[];agents.forEach(function(a){(a.frictions||[]).forEach(function(f){frs.push(normFr(f,a));});});
|
||||||
|
renderFrictions(frs,false);
|
||||||
|
}).catch(function(){});
|
||||||
|
if(alive) setTimeout(poll, 700);
|
||||||
|
}
|
||||||
|
function normFr(f,a){ if(typeof f==='string')f={quoi:f,page:a?a.page:''}; return {quoi:f.quoi,page:f.page||'',ploxion:f.ploxion,t:f.t,agent:a?a.agent:(f.agent||'?'),emoji:a?a.emoji:(f.emoji||''),c:color(a?a.agent:(f.agent||'x'))}; }
|
||||||
|
function renderFrictions(frs,isReplay){
|
||||||
|
if(!frs.length){ frEl.innerHTML='<li style="color:rgba(232,228,210,.4)">aucune pour l\'instant</li>'; return; }
|
||||||
|
frEl.innerHTML=frs.map(function(f,i){
|
||||||
|
var pid=ploxIdOf(f);
|
||||||
|
var openUrl=f.page? (/^https?:/.test(f.page)?f.page:('https://labo.j0bot.ch'+f.page)) : (pid?'/home?open='+pid:null);
|
||||||
|
var links=[];
|
||||||
|
if(openUrl) links.push('<a href="'+esc(openUrl)+'" target="_blank" rel="noopener">↗ ouvrir</a>');
|
||||||
|
if(pid) links.push('<span title="le fichier du ploxion">📄 ploxions/'+esc(pid)+'/app.blade.php</span>');
|
||||||
|
if(isReplay && f.t) links.push('<a href="#" data-seekfr="'+f.t+'">⏱ rejouer ce moment</a>');
|
||||||
|
return '<li><span class="fq"'+(isReplay&&f.t?' data-seekfr="'+f.t+'"':'')+' style="color:'+f.c+'">'+esc((f.emoji||'')+' '+f.agent+' : '+f.quoi)+'</span>'
|
||||||
|
+'<span class="fmeta">'+links.join(' · ')+'</span></li>';
|
||||||
|
}).join('');
|
||||||
|
frEl.querySelectorAll('[data-seekfr]').forEach(function(el){ el.onclick=function(ev){ ev.preventDefault(); seekTo(+el.getAttribute('data-seekfr')); }; });
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- REPLAY (tsoin) ----------
|
||||||
|
function loadRuns(){
|
||||||
|
fetch('/px/sim/runs.json',{cache:'no-store'}).then(function(r){return r.json();}).then(function(runs){
|
||||||
|
if(!alive)return;
|
||||||
|
var cur=runsSel.value;
|
||||||
|
runsSel.innerHTML='<option value="">▶ live</option><option disabled>— tsoins du xion —</option>'+runs.map(function(r){
|
||||||
|
var dur=fmt((r.ended||0)-(r.started||0));
|
||||||
|
var name=r.title||r.id;
|
||||||
|
return '<option value="'+esc(r.id)+'">⧗ '+esc(name)+(r.dim?' ['+esc(r.dim)+']':'')+' · '+r.agents.length+'👤 · '+dur+(r.frictions?' · '+r.frictions+'⚠':'')+'</option>';
|
||||||
|
}).join('');
|
||||||
|
runsSel.value=cur;
|
||||||
|
}).catch(function(){});
|
||||||
|
}
|
||||||
|
function enterReplay(id){
|
||||||
|
fetch('/px/sim/run/'+encodeURIComponent(id)+'.json',{cache:'no-store'}).then(function(r){return r.json();}).then(function(run){
|
||||||
|
if(!alive)return;
|
||||||
|
mode='replay'; root.classList.add('replay'); clearTiles();
|
||||||
|
var ags=run.agents||{}, t0=1e18,t1=0, frs=[];
|
||||||
|
Object.keys(ags).forEach(function(name){ var g=ags[name]; (g.tape||[]).forEach(function(e){ if(e.t<t0)t0=e.t; if(e.t>t1)t1=e.t; });
|
||||||
|
(g.frictions||[]).forEach(function(f){ frs.push(normFr(f,{agent:name,emoji:g.emoji})); }); });
|
||||||
|
if(t0>t1){t0=run.started||0;t1=run.ended||t0;}
|
||||||
|
replay={run:run,agents:ags,t0:t0,t1:t1,playT:0,playing:true,speed:1,last:now(),frictions:frs};
|
||||||
|
seekEl.max=Math.max(1,Math.round((t1-t0)));
|
||||||
|
nEl.textContent='🎬 replay : '+id+' · '+Object.keys(ags).length+' agents';
|
||||||
|
// tuiles + flux d'actions du run
|
||||||
|
Object.keys(ags).forEach(function(name){ var g=ags[name]; ensureTile({agent:name,emoji:g.emoji,quest:g.quest,vw:g.vw,vh:g.vh}); });
|
||||||
|
var rows=[]; Object.keys(ags).forEach(function(name){ (ags[name].tape||[]).forEach(function(e){ if(e.a) rows.push({t:e.t,ag:name,em:ags[name].emoji||'',a:e.a}); }); });
|
||||||
|
rows.sort(function(a,b){return a.t-b.t;});
|
||||||
|
replay.rows=rows;
|
||||||
|
renderFrictions(frs,true);
|
||||||
|
playBtn.textContent='⏸';
|
||||||
|
}).catch(function(){ nEl.textContent='run introuvable'; });
|
||||||
|
}
|
||||||
|
function exitReplay(){ mode='live'; root.classList.remove('replay'); replay.playing=false; clearTiles(); runsSel.value=''; lastLogKey=''; }
|
||||||
|
function seekTo(absT){ if(mode!=='replay')return; replay.playT=Math.max(0,Math.min(replay.t1-replay.t0,absT-replay.t0)); replay.playing=false; playBtn.textContent='▶'; }
|
||||||
|
// position d'un agent à un temps donné (interpolation dans la tape)
|
||||||
|
function posAt(tape,at){ // at = t0+playT (absolu)
|
||||||
|
var pts=tape.filter(function(e){return typeof e.x==='number';});
|
||||||
|
if(!pts.length)return null;
|
||||||
|
if(at<=pts[0].t)return {x:pts[0].x,y:pts[0].y};
|
||||||
|
for(var i=1;i<pts.length;i++){ if(pts[i].t>=at){ var a=pts[i-1],b=pts[i],k=(at-a.t)/((b.t-a.t)||1); return {x:a.x+(b.x-a.x)*k,y:a.y+(b.y-a.y)*k}; } }
|
||||||
|
var L=pts[pts.length-1]; return {x:L.x,y:L.y};
|
||||||
|
}
|
||||||
|
function curStep(tape,at){ var s='',last=null; for(var i=0;i<tape.length;i++){ if(tape[i].t<=at){ if(tape[i].a)last=tape[i].a; if(tape[i].s)s=tape[i].s; } } return {step:s,action:last}; }
|
||||||
|
|
||||||
|
// ---------- rAF commun ----------
|
||||||
|
function drawTile(t,pos,trailPts,col,dim){
|
||||||
|
var c=t.cv.getContext('2d'),W=t.cv.width,H=t.cv.height;
|
||||||
|
c.fillStyle='#0c0f07';c.fillRect(0,0,W,H);
|
||||||
|
c.strokeStyle='rgba(232,228,210,.06)';c.lineWidth=1;
|
||||||
|
for(var gx=0;gx<W;gx+=15){c.beginPath();c.moveTo(gx,0);c.lineTo(gx,H);c.stroke();}
|
||||||
|
for(var gy=0;gy<H;gy+=15){c.beginPath();c.moveTo(0,gy);c.lineTo(W,gy);c.stroke();}
|
||||||
|
if(trailPts&&trailPts.length>1){
|
||||||
|
for(var i=1;i<trailPts.length;i++){ var p0=trailPts[i-1],p1=trailPts[i];
|
||||||
|
c.beginPath();c.moveTo(p0[0],p0[1]);var mx=(p0[0]+p1[0])/2,my=(p0[1]+p1[1])/2;c.quadraticCurveTo(p0[0],p0[1],mx,my);c.lineTo(p1[0],p1[1]);
|
||||||
|
c.strokeStyle=col+Math.round(30+140*(i/trailPts.length)).toString(16).padStart(2,'0');c.lineWidth=2.4;c.lineCap='round';c.stroke(); }
|
||||||
|
}
|
||||||
|
if(t.cx!==null){
|
||||||
|
c.globalAlpha=dim?0.4:1;
|
||||||
|
if(!dim){ var pulse=6+2*Math.sin(Date.now()/300); c.beginPath();c.arc(t.cx,t.cy,pulse,0,7);c.fillStyle=col+'22';c.fill(); }
|
||||||
|
c.beginPath();c.moveTo(t.cx,t.cy);c.lineTo(t.cx+11,t.cy+15);c.lineTo(t.cx+4.5,t.cy+14);c.lineTo(t.cx+7.5,t.cy+21);c.lineTo(t.cx+5,t.cy+22);c.lineTo(t.cx+2,t.cy+15.5);c.lineTo(t.cx-2,t.cy+19);c.closePath();
|
||||||
|
c.fillStyle=dim?'#6b7358':col;c.fill();c.strokeStyle='#0c0f07';c.lineWidth=1.3;c.stroke();
|
||||||
|
var nm=t.el.querySelector('b').textContent;
|
||||||
|
c.font='700 9px ui-rounded,sans-serif';var lx=Math.min(t.cx+13,W-4-c.measureText(nm).width),ly=Math.min(t.cy+30,H-4);
|
||||||
|
c.fillStyle='rgba(12,15,7,.75)';c.fillRect(lx-2,ly-9,c.measureText(nm).width+4,12);c.fillStyle=col;c.fillText(nm,lx,ly);
|
||||||
|
c.globalAlpha=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function frame(){
|
||||||
|
if(!alive)return;
|
||||||
|
if(mode==='live'){
|
||||||
|
Object.keys(tiles).forEach(function(name){ var t=tiles[name],a=t.data,col=color(name);
|
||||||
|
if(t.cx!==null){ t.cx+=(t.tx-t.cx)*0.18; t.cy+=(t.ty-t.cy)*0.18; }
|
||||||
|
drawTile(t,null,t.trailPts,col,!!a.done||(now()-(a.t||0))>STALE); });
|
||||||
|
} else {
|
||||||
|
// avance le temps de replay
|
||||||
|
var dt=now()-replay.last; replay.last=now();
|
||||||
|
if(replay.playing){ replay.playT+=dt*replay.speed; if(replay.playT>=replay.t1-replay.t0){ replay.playT=replay.t1-replay.t0; replay.playing=false; playBtn.textContent='▶'; } }
|
||||||
|
var at=replay.t0+replay.playT;
|
||||||
|
seekEl.value=Math.round(replay.playT); ttEl.textContent=fmt(replay.playT)+' / '+fmt(replay.t1-replay.t0);
|
||||||
|
Object.keys(tiles).forEach(function(name){ var t=tiles[name],g=replay.agents[name]; if(!g)return; var col=color(name);
|
||||||
|
var vw=g.vw||1200,vh=g.vh||800,W=t.cv.width,H=t.cv.height;
|
||||||
|
var p=posAt(g.tape||[],at);
|
||||||
|
if(p){ t.tx=p.x/vw*W; t.ty=p.y/vh*H; if(t.cx===null){t.cx=t.tx;t.cy=t.ty;} t.cx+=(t.tx-t.cx)*0.25; t.cy+=(t.ty-t.cy)*0.25; }
|
||||||
|
var tp=(g.tape||[]).filter(function(e){return typeof e.x==='number'&&e.t<=at;}).slice(-40).map(function(e){return [e.x/vw*W,e.y/vh*H];});
|
||||||
|
var cs=curStep(g.tape||[],at);
|
||||||
|
t.pg.textContent=''; t.st.textContent=(cs.action?cs.action:(cs.step||'—')); if(g.quest){t.q.hidden=false;t.q.textContent='🗺️ '+g.quest;}
|
||||||
|
t.age.textContent='🎬';
|
||||||
|
drawTile(t,p,tp,col,false); });
|
||||||
|
// flux d'actions jusqu'au temps courant
|
||||||
|
var rows=(replay.rows||[]).filter(function(r){return r.t<=at;}).slice(-40).reverse();
|
||||||
|
logEl.innerHTML=rows.map(function(r){return '<div><span class="ag" style="color:'+color(r.ag)+'">'+esc(r.em+' '+r.ag)+'</span> '+esc(r.a)+'</div>';}).join('');
|
||||||
|
}
|
||||||
|
raf=requestAnimationFrame(frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
runsSel.onchange=function(){ var v=runsSel.value; if(v)enterReplay(v); else exitReplay(); };
|
||||||
|
playBtn.onclick=function(){ replay.playing=!replay.playing; playBtn.textContent=replay.playing?'⏸':'▶'; replay.last=now(); };
|
||||||
|
seekEl.oninput=function(){ replay.playT=+seekEl.value; replay.playing=false; playBtn.textContent='▶'; };
|
||||||
|
container.querySelector('[data-exit]').onclick=exitReplay;
|
||||||
|
|
||||||
|
poll(); loadRuns(); var runsIv=setInterval(function(){ if(mode==='live')loadRuns(); },5000);
|
||||||
|
raf=requestAnimationFrame(frame);
|
||||||
|
return {unmount:function(){alive=false; LIVE=null;if(raf)cancelAnimationFrame(raf);clearInterval(runsIv);container.innerHTML='';}};
|
||||||
|
}
|
||||||
|
window.jOSApps=window.jOSApps||{};
|
||||||
|
window.jOSApps[ID]={manifest:{id:ID,name:'Simulation',icon:'🎮'},mount:mount,describe:describe};
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
Loading…
Reference in New Issue
Block a user