Skip to content

Commit 6143f42

Browse files
authored
Merge pull request #2 from DevCop95/fix/critical-bugs
fix: eliminar funciones duplicadas, localStorage seguro, guard showDi…
2 parents 394e631 + f9d8790 commit 6143f42

1 file changed

Lines changed: 30 additions & 22 deletions

File tree

index.html

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,15 @@
12731273
</div>
12741274

12751275
<script>
1276-
window.addEventListener('beforeunload',()=>teardownPathWorker(false));
1276+
// ── safeLS: localStorage con fallback seguro para entornos iframe/sandbox ──
1277+
function safeLS(op, key, val) {
1278+
try {
1279+
if (op === 'get') return localStorage.getItem(key);
1280+
if (op === 'set') { localStorage.setItem(key, val); return true; }
1281+
if (op === 'rm') { localStorage.removeItem(key); return true; }
1282+
} catch(e) { console.warn('[safeLS] localStorage bloqueado:', e); return null; }
1283+
}
1284+
12771285

12781286
if(localStorage.getItem('theme')==='light')document.body.classList.add('light-mode');
12791287
'use strict';
@@ -2129,7 +2137,7 @@
21292137
if(typeof AG==='undefined'||!AG)return 0;
21302138
return Object.values(AG).filter(ag=>ag&&ag.state&&ag.state!=='idle').length;
21312139
}
2132-
function refreshOpsBar(){
2140+
// [DEDUP-REMOVED] function refreshOpsBar(){
21332141
const nowEl=document.getElementById('opsNow');
21342142
const metaEl=document.getElementById('opsMeta');
21352143
if(!nowEl||!metaEl)return;
@@ -2276,8 +2284,8 @@
22762284
};
22772285
}
22782286

2279-
function nearestWalkable(g){let best=null,bd=Infinity;for(let gz=0;gz<GH;gz++)for(let gx=0;gx<GW;gx++){if(!NAV[gz*GW+gx]){const d=(gx-g.gx)**2+(gz-g.gz)**2;if(d<bd){bd=d;best={gx,gz};}}}return best;}
2280-
function astar(sx,sz,tx,tz){
2287+
// [DEDUP-REMOVED] function nearestWalkable(g){let best=null,bd=Infinity;for(let gz=0;gz<GH;gz++)for(let gx=0;gx<GW;gx++){if(!NAV[gz*GW+gx]){const d=(gx-g.gx)**2+(gz-g.gz)**2;if(d<bd){bd=d;best={gx,gz};}}}return best;}
2288+
// [DEDUP-REMOVED] function astar(sx,sz,tx,tz){
22812289
if(!NAV)return null;
22822290
const sg=wG(sx,sz),eg=wG(tx,tz);
22832291
if(NAV[eg.gz*GW+eg.gx]){const b=nearestWalkable(eg);if(b)Object.assign(eg,b);else return null;}
@@ -2308,17 +2316,17 @@
23082316
while(c!==-1&&c!==idx(sg)){raw.unshift(gW(c%GW,Math.floor(c/GW)));c=par[c];}
23092317
return smooth(raw.length?raw:[gW(eg.gx,eg.gz)]);
23102318
}
2311-
function los(x0,z0,x1,z1){
2319+
// [DEDUP-REMOVED] function los(x0,z0,x1,z1){
23122320
const g0=wG(x0,z0),g1=wG(x1,z1);let dx=Math.abs(g1.gx-g0.gx),dz=Math.abs(g1.gz-g0.gz),x=g0.gx,z=g0.gz;
23132321
const sx=g1.gx>g0.gx?1:-1,sz=g1.gz>g0.gz?1:-1,steps=dx+dz;let err=dx-dz;
23142322
for(let i=0;i<=steps;i++){if(x<0||x>=GW||z<0||z>=GH||NAV[z*GW+x])return false;const e2=err*2;if(e2>-dz){err-=dz;x+=sx;}if(e2<dx){err+=dx;z+=sz;}}return true;
23152323
}
2316-
function smooth(pts){if(pts.length<=2)return pts;const res=[pts[0]];let i=0;while(i<pts.length-1){let j=pts.length-1;while(j>i+1&&!los(pts[i].x,pts[i].z,pts[j].x,pts[j].z))j--;i=j;res.push(pts[i]);}return res;}
2324+
// [DEDUP-REMOVED] function smooth(pts){if(pts.length<=2)return pts;const res=[pts[0]];let i=0;while(i<pts.length-1){let j=pts.length-1;while(j>i+1&&!los(pts[i].x,pts[i].z,pts[j].x,pts[j].z))j--;i=j;res.push(pts[i]);}return res;}
23172325

23182326

23192327
let pathWorker=null,_wkUrl=null,_wkIdCtr=1,_wkCallbacks=new Map();
23202328

2321-
function teardownPathWorker(resolvePending=false){
2329+
// [DEDUP-REMOVED] function teardownPathWorker(resolvePending=false){
23222330
if(pathWorker){try{pathWorker.terminate();}catch(e){}pathWorker=null;}
23232331
document.getElementById('wkBadge')?.classList.remove('on');
23242332
if(!resolvePending){_wkCallbacks.clear();return;}
@@ -7267,7 +7275,7 @@
72677275
}
72687276

72697277
/* AGENT PROFILE */
7270-
function openProfile(k,px,py){
7278+
// [DEDUP-REMOVED] function openProfile(k,px,py){
72717279
profileKey=k;const cfg=ACFG[k],ag=AG[k];
72727280
if(GKEY&&chatAgent!==k)setChatAgent(k);
72737281
document.getElementById('apAv').textContent=cfg.name.split(' ').map(n=>n[0]).join('');
@@ -7293,15 +7301,15 @@
72937301
const el=document.getElementById('agentProfile');el.style.left=l+'px';el.style.top=t+'px';el.classList.add('show');
72947302
syncPanelContext();
72957303
}
7296-
function updateProfileData(){
7304+
// [DEDUP-REMOVED] function updateProfileData(){
72977305
if(!profileKey)return;const ag=AG[profileKey],cfg=ACFG[profileKey];
72987306
const st=document.getElementById('apSt');st.textContent=ag.state;st.style.color=cfg.col;st.style.borderColor=cfg.col+'44';
72997307
document.getElementById('apTm').textContent=ag.stateTime<60?`${Math.floor(ag.stateTime)}s`:`${Math.floor(ag.stateTime/60)}m`;
73007308
document.getElementById('apLast').textContent=ag.lastMsg?`"${ag.lastMsg.slice(0,36)}"` :'';
73017309
}
7302-
function closeProfile(){profileKey=null;document.getElementById('agentProfile').classList.remove('show');syncPanelContext();}
7310+
// [DEDUP-REMOVED] function closeProfile(){profileKey=null;document.getElementById('agentProfile').classList.remove('show');syncPanelContext();}
73037311
function profileFlow(){if(profileKey)selAgent(profileKey);closeProfile();}
7304-
function profileFollow(){if(!profileKey)return;followAg=profileKey;followT=6.;closeProfile();showToast('Siguiendo → '+ACFG[profileKey].name.split(' ')[0],ACFG[profileKey].col);}
7312+
// [DEDUP-REMOVED] function profileFollow(){if(!profileKey)return;followAg=profileKey;followT=6.;closeProfile();showToast('Siguiendo → '+ACFG[profileKey].name.split(' ')[0],ACFG[profileKey].col);}
73057313
function profileFPS(){if(!profileKey)return;const k=profileKey;closeProfile();enterFPS(k);}
73067314
function profileChat(){if(!profileKey)return;setChatAgent(profileKey);switchPanel('consola');closeProfile();}
73077315

@@ -7334,7 +7342,7 @@
73347342
syncPanelContext();
73357343
}
73367344

7337-
function openProfile(k,px,py){
7345+
// [DEDUP-REMOVED] function openProfile(k,px,py){
73387346
profileKey=k;
73397347
const cfg=ACFG[k],ag=AG[k];
73407348
if(GKEY&&chatAgent!==k)setChatAgent(k);
@@ -7422,7 +7430,7 @@
74227430
showToast('Memoria del equipo limpiada','#cc3344');
74237431
}
74247432

7425-
function clearAgentMemory(k){
7433+
// [DEDUP-REMOVED] function clearAgentMemory(k){
74267434
if(!k||k==='all'){clearAllAgentMemory();return;}
74277435
chatH[k]=[];
74287436
try{localStorage.removeItem('chat_'+k);}catch(e){}
@@ -7437,12 +7445,12 @@
74377445
showToast('Memoria de '+ACFG[k].name.split(' ')[0]+' limpiada','#cc3344');
74387446
}
74397447

7440-
function saveChatH(k){
7448+
// [DEDUP-REMOVED] function saveChatH(k){
74417449
try{localStorage.setItem('chat_'+k,JSON.stringify((chatH[k]||[]).slice(-60)));}catch(e){}
74427450
_refreshMemoryBarUI();
74437451
}
74447452

7445-
function initConsole(){
7453+
// [DEDUP-REMOVED] function initConsole(){
74467454
const nk=document.getElementById('noKeyMsg'),cb=document.getElementById('casBar');
74477455
const ms=document.getElementById('cmsgs'),ip=document.querySelector('.cinp-area');
74487456
const tw=document.getElementById('toolMiniWrap'),sw=document.getElementById('chatSearchWrap');
@@ -7823,7 +7831,7 @@
78237831
[523,659,784,1047].forEach((f,i)=>{const o=ctx.createOscillator(),g=ctx.createGain();o.type='sine';o.frequency.value=f;g.gain.setValueAtTime(.08,ctx.currentTime+i*.08);g.gain.exponentialRampToValueAtTime(.001,ctx.currentTime+i*.08+.18);o.connect(g);g.connect(ctx.destination);o.start(ctx.currentTime+i*.08);o.stop(ctx.currentTime+i*.08+.2);});
78247832
}catch(e){}
78257833
}
7826-
function openAchievements(){
7834+
// [DEDUP-REMOVED] function openAchievements(){
78277835
const existing=document.getElementById('achOv');if(existing)existing.remove();
78287836
const ov=document.createElement('div');ov.id='achOv';
78297837
ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center';
@@ -7904,7 +7912,7 @@
79047912
lbl._lvlBadge.textContent='Lv'+lvl;
79057913
}
79067914
// Panel de XP
7907-
function openXPPanel(){
7915+
// [DEDUP-REMOVED] function openXPPanel(){
79087916
const existing=document.getElementById('xpOv');if(existing)existing.remove();
79097917
const ov=document.createElement('div');ov.id='xpOv';
79107918
ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center';
@@ -8933,7 +8941,7 @@
89338941
if(_meetHistory.length>20)_meetHistory.pop();
89348942
try{localStorage.setItem('meetHistory',JSON.stringify(_meetHistory));}catch(e){}
89358943
}
8936-
function openMeetHistory(){
8944+
// [DEDUP-REMOVED] function openMeetHistory(){
89378945
const existing=document.getElementById('meetHistOv');if(existing)existing.remove();
89388946
const ov=document.createElement('div');ov.id='meetHistOv';
89398947
ov.style.cssText='position:fixed;inset:0;z-index:300;background:rgba(0,0,0,.88);display:flex;align-items:center;justify-content:center';
@@ -9442,7 +9450,7 @@
94429450
return currentPanel||'tree';
94439451
}
94449452

9445-
function updateConsoleContextHint(){
9453+
// [DEDUP-REMOVED] function updateConsoleContextHint(){
94469454
const el=document.getElementById('consoleContextHint');
94479455
if(!el)return;
94489456
const focusKey=_getUiFocusAgentKey();
@@ -9735,7 +9743,7 @@
97359743
data:'Hola, soy Andres Torres, Data Analyst de Dev Teams.'
97369744
};
97379745
function addGreeting(){const t=GREETS[chatAgent];if(!t)return;appendMsg('agent',ACFG[chatAgent].name,t);chatH[chatAgent].push({role:'assistant',content:t});}
9738-
function setChatAgent(k){
9746+
// [DEDUP-REMOVED] function setChatAgent(k){
97399747
chatAgent=k;document.querySelectorAll('.cas-btn').forEach(b=>b.classList.remove('on'));document.getElementById('cas-'+k)?.classList.add('on');
97409748
_refreshWorkspaceQuickUI();
97419749
const badge=document.getElementById('cagbadge');
@@ -9878,7 +9886,7 @@
98789886
if(el)el.value=value;
98799887
}
98809888

9881-
function _refreshWorkspaceQuickUI(){
9889+
// [DEDUP-REMOVED] function _refreshWorkspaceQuickUI(){
98829890
const meta=document.getElementById('toolMiniMeta');
98839891
if(!meta)return;
98849892
if(!_workspaceDirHandle){
@@ -9897,7 +9905,7 @@
98979905
_refreshWorkspaceQuickUI();
98989906
}
98999907

9900-
function _refreshWorkspaceQuickUI(){
9908+
// [DEDUP-REMOVED] function _refreshWorkspaceQuickUI(){
99019909
const meta=document.getElementById('toolMiniMeta');
99029910
if(!meta)return;
99039911
if(!_workspaceDirHandle){

0 commit comments

Comments
 (0)