| 1 | // Interfaz HTML: árbol lateral, buscador, botones de vista, ruta y stats. |
| 2 | // createUI se llama una sola vez; setModel() reconstruye el árbol cuando se |
| 3 | // carga otra carpeta raíz. |
| 4 | import { THEMES } from './themes.js'; |
| 5 | |
| 6 | function fmtSize(b) { |
| 7 | if (b < 1024) return `${b}`; |
| 8 | if (b < 1024 * 1024) return `${(b / 1024).toFixed(1)}k`; |
| 9 | return `${(b / 1024 / 1024).toFixed(1)}M`; |
| 10 | } |
| 11 | |
| 12 | export function createUI(cb) { |
| 13 | const $ = id => document.getElementById(id); |
| 14 | const treeEl = $('tree'); |
| 15 | const pathEl = $('pathbar'); |
| 16 | const statsEl = $('stats'); |
| 17 | const resultsEl = $('search-results'); |
| 18 | const searchEl = $('search-input'); |
| 19 | |
| 20 | let model = null; |
| 21 | const fileRows = new Map(); // fileId → fila DOM |
| 22 | const nodeRows = new Map(); // nodeId → fila DOM |
| 23 | let selectedRow = null; |
| 24 | let selectedNodeRow = null; |
| 25 | |
| 26 | // ── árbol lateral (perezoso: los hijos se montan al expandir) ─────── |
| 27 | // imprescindible en monorepos: cientos de miles de filas no caben en DOM |
| 28 | const dirEntries = new Map(); // nodeId → { row, kids, depth, rendered } |
| 29 | |
| 30 | const rowFile = new WeakMap(); // fila DOM → fichero (navegación por teclado) |
| 31 | const rowNode = new WeakMap(); // fila DOM → nodo dir |
| 32 | |
| 33 | function addFileRow(container, f, depth, basement) { |
| 34 | const row = document.createElement('div'); |
| 35 | rowFile.set(row, f); |
| 36 | row.className = 'row file' + (basement ? ' basement' : ''); |
| 37 | row.style.paddingLeft = `${depth * 14 + 8}px`; |
| 38 | // stats e icono de estado git (visibles solo en modo git) |
| 39 | let gitHtml = ''; |
| 40 | if (f.git) { |
| 41 | const stats = (f.git.a || f.git.d) |
| 42 | ? `<span class="gadd">+${f.git.a}</span><span class="gdel">−${f.git.d}</span>` : ''; |
| 43 | gitHtml = `<span class="gwrap">${stats}<span class="gicon g${f.git.st}">${f.git.st}</span></span>`; |
| 44 | } |
| 45 | row.innerHTML = `<span class="name">${f.name}</span>${gitHtml}<span class="meta">${fmtSize(f.size)}</span>`; |
| 46 | row.addEventListener('click', () => cb.onSelectFile?.(f)); |
| 47 | fileRows.set(f.id, row); |
| 48 | container.appendChild(row); |
| 49 | } |
| 50 | |
| 51 | function addDirRow(container, node, depth) { |
| 52 | const row = document.createElement('div'); |
| 53 | rowNode.set(row, node); |
| 54 | const label = node.isBasement ? `${node.name} · sótano` : node.name; |
| 55 | row.className = 'row dir' + (node.isBasement ? ' basement' : ''); |
| 56 | row.style.paddingLeft = `${depth * 14 + 8}px`; |
| 57 | row.innerHTML = `<span class="caret"></span><span class="name">${label}</span><span class="meta">${node.fileIds.length + node.children.length || ''}</span>`; |
| 58 | const kids = document.createElement('div'); |
| 59 | kids.style.display = 'none'; |
| 60 | dirEntries.set(node.id, { row, kids, depth, rendered: false }); |
| 61 | nodeRows.set(node.id, row); |
| 62 | row.addEventListener('click', () => { |
| 63 | const open = row.classList.toggle('open'); |
| 64 | if (open) renderChildren(node); |
| 65 | kids.style.display = open ? '' : 'none'; |
| 66 | cb.onSelectNode?.(node); |
| 67 | }); |
| 68 | container.append(row, kids); |
| 69 | } |
| 70 | |
| 71 | function renderChildren(node) { |
| 72 | const ent = dirEntries.get(node.id); |
| 73 | if (!ent || ent.rendered) return; |
| 74 | ent.rendered = true; |
| 75 | for (const c of node.children) addDirRow(ent.kids, c, ent.depth + 1); |
| 76 | const basement = node.isBasement || node.building?.isBasement; |
| 77 | for (const fid of node.fileIds) { |
| 78 | addFileRow(ent.kids, model.files[fid], ent.depth + 1, basement); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // pliega/despliega una carpeta sin disparar la selección (teclado) |
| 83 | function toggleDir(node, open) { |
| 84 | const ent = dirEntries.get(node.id); |
| 85 | if (!ent) return; |
| 86 | if (open) renderChildren(node); |
| 87 | ent.row.classList.toggle('open', open); |
| 88 | ent.kids.style.display = open ? '' : 'none'; |
| 89 | } |
| 90 | |
| 91 | // ── navegación por teclado en el árbol ────────────────────────────── |
| 92 | treeEl.tabIndex = 0; |
| 93 | treeEl.addEventListener('pointerdown', () => treeEl.focus()); |
| 94 | let cursorRow = null; |
| 95 | |
| 96 | function setCursor(row, scroll = true) { |
| 97 | cursorRow?.classList.remove('cursor'); |
| 98 | cursorRow = row ?? null; |
| 99 | if (cursorRow) { |
| 100 | cursorRow.classList.add('cursor'); |
| 101 | if (scroll) cursorRow.scrollIntoView({ block: 'nearest' }); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | function visibleRows() { |
| 106 | return [...treeEl.querySelectorAll('.row')].filter(r => r.offsetParent !== null); |
| 107 | } |
| 108 | |
| 109 | treeEl.addEventListener('keydown', (e) => { |
| 110 | const rows = visibleRows(); |
| 111 | if (!rows.length) return; |
| 112 | const current = cursorRow && rows.includes(cursorRow) |
| 113 | ? cursorRow |
| 114 | : (selectedRow && rows.includes(selectedRow) ? selectedRow : rows[0]); |
| 115 | const idx = rows.indexOf(current); |
| 116 | const page = Math.max(3, Math.floor(treeEl.clientHeight / 24) - 2); |
| 117 | const node = rowNode.get(current); |
| 118 | const file = rowFile.get(current); |
| 119 | |
| 120 | switch (e.key) { |
| 121 | case 'ArrowDown': |
| 122 | setCursor(rows[Math.min(idx + 1, rows.length - 1)]); |
| 123 | break; |
| 124 | case 'ArrowUp': |
| 125 | setCursor(rows[Math.max(idx - 1, 0)]); |
| 126 | break; |
| 127 | case 'ArrowRight': |
| 128 | if (node) { |
| 129 | if (!current.classList.contains('open')) { toggleDir(node, true); setCursor(current); } |
| 130 | else setCursor(visibleRows()[idx + 1] ?? current); // entra al primer hijo |
| 131 | } |
| 132 | break; |
| 133 | case 'ArrowLeft': { |
| 134 | if (node && current.classList.contains('open')) { toggleDir(node, false); break; } |
| 135 | const parent = node ? node.parent : file?.node; |
| 136 | const pRow = parent && parent.role !== 'ciudad' ? nodeRows.get(parent.id) : null; |
| 137 | if (pRow) setCursor(pRow); |
| 138 | break; |
| 139 | } |
| 140 | case 'PageDown': |
| 141 | setCursor(rows[Math.min(idx + page, rows.length - 1)]); |
| 142 | break; |
| 143 | case 'PageUp': |
| 144 | setCursor(rows[Math.max(idx - page, 0)]); |
| 145 | break; |
| 146 | case 'Enter': |
| 147 | case ' ': |
| 148 | if (file) cb.onSelectFile?.(file, { fly: true }); |
| 149 | else if (node) { toggleDir(node, !current.classList.contains('open')); cb.onSelectNode?.(node); } |
| 150 | break; |
| 151 | default: |
| 152 | return; // no consumir otras teclas (F vuelo, etc.) |
| 153 | } |
| 154 | e.preventDefault(); |
| 155 | e.stopPropagation(); |
| 156 | }); |
| 157 | |
| 158 | // monta y abre la cadena de contenedores hasta `node` (incluido) |
| 159 | function ensureVisible(node) { |
| 160 | const chain = []; |
| 161 | for (let n = node; n && n.role !== 'ciudad'; n = n.parent) chain.push(n); |
| 162 | for (let i = chain.length - 1; i >= 0; i--) { |
| 163 | const ent = dirEntries.get(chain[i].id); |
| 164 | if (!ent) return; |
| 165 | renderChildren(chain[i]); |
| 166 | ent.row.classList.add('open'); |
| 167 | ent.kids.style.display = ''; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | function setModel(m) { |
| 172 | model = m; |
| 173 | fileRows.clear(); |
| 174 | nodeRows.clear(); |
| 175 | dirEntries.clear(); |
| 176 | selectedRow = null; |
| 177 | selectedNodeRow = null; |
| 178 | treeEl.innerHTML = ''; |
| 179 | for (const c of model.city.children) addDirRow(treeEl, c, 1); |
| 180 | for (const fid of model.city.fileIds) addFileRow(treeEl, model.files[fid], 1, false); |
| 181 | baseFileCount = model.files.filter(f => !f.node.building?.isBasement).length; |
| 182 | setPath(null); |
| 183 | setStats(0); |
| 184 | searchEl.value = ''; |
| 185 | hideResults(); |
| 186 | } |
| 187 | |
| 188 | function markFile(file) { |
| 189 | selectedRow?.classList.remove('selected'); |
| 190 | selectedRow = null; |
| 191 | if (file) { |
| 192 | ensureVisible(file.node); |
| 193 | selectedRow = fileRows.get(file.id) ?? null; |
| 194 | } |
| 195 | if (selectedRow) { |
| 196 | selectedRow.classList.add('selected'); |
| 197 | selectedRow.scrollIntoView({ block: 'center', behavior: 'smooth' }); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // marca una carpeta/nivel (selección sincronizada ciudad ↔ árbol) |
| 202 | function markNode(node) { |
| 203 | selectedNodeRow?.classList.remove('selected'); |
| 204 | selectedNodeRow = null; |
| 205 | if (node) { |
| 206 | ensureVisible(node); |
| 207 | selectedNodeRow = nodeRows.get(node.id) ?? null; |
| 208 | } |
| 209 | if (selectedNodeRow) { |
| 210 | selectedNodeRow.classList.add('selected'); |
| 211 | selectedNodeRow.scrollIntoView({ block: 'center', behavior: 'smooth' }); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | // ── buscador (con wildcards: * dentro de segmento, ** cruza carpetas) ── |
| 216 | function termMatcher(t) { |
| 217 | if (!t.includes('*') && !t.includes('?')) { |
| 218 | return (f) => f.path.toLowerCase().includes(t); |
| 219 | } |
| 220 | const globstar = '__DOUBLE_STAR__'; |
| 221 | const body = t |
| 222 | .replace(/[.+^${}()|[\]\\]/g, '\\$&') |
| 223 | .replace(/\*\*/g, globstar) |
| 224 | .replace(/\*/g, '[^/]*') |
| 225 | .replace(new RegExp(globstar, 'g'), '.*') |
| 226 | .replace(/\?/g, '[^/]'); |
| 227 | // ancla a final de nombre/ruta y a límite de segmento: «*.js» casa con |
| 228 | // cualquier fichero .js, «src/*.css» con los css directos de un src/ |
| 229 | const re = new RegExp(`(^|/)${body}$`, 'i'); |
| 230 | return (f) => re.test(f.name) || re.test(f.path); |
| 231 | } |
| 232 | |
| 233 | let results = []; |
| 234 | function runSearch(q) { |
| 235 | resultsEl.innerHTML = ''; |
| 236 | results = []; |
| 237 | const terms = q.trim().toLowerCase().split(/\s+/).filter(Boolean); |
| 238 | if (!terms.length) { |
| 239 | resultsEl.classList.remove('show'); |
| 240 | cb.onSuggest?.([]); |
| 241 | return; |
| 242 | } |
| 243 | const matchers = terms.map(termMatcher); |
| 244 | results = model.files |
| 245 | .filter(f => matchers.every(m => m(f))) |
| 246 | .slice(0, 30); |
| 247 | for (const f of results) { |
| 248 | const div = document.createElement('div'); |
| 249 | div.className = 'result'; |
| 250 | const dir = f.path.slice(0, f.path.length - f.name.length); |
| 251 | div.innerHTML = `<span class="rname">${f.name}</span><span class="rpath">${dir}</span>`; |
| 252 | div.addEventListener('click', () => { cb.onSelectFile?.(f, { fly: true }); hideResults(); }); |
| 253 | resultsEl.appendChild(div); |
| 254 | } |
| 255 | resultsEl.classList.toggle('show', results.length > 0); |
| 256 | cb.onSuggest?.(results); |
| 257 | } |
| 258 | function hideResults() { |
| 259 | resultsEl.classList.remove('show'); |
| 260 | cb.onSuggest?.([]); |
| 261 | } |
| 262 | searchEl.addEventListener('input', () => runSearch(searchEl.value)); |
| 263 | searchEl.addEventListener('keydown', (e) => { |
| 264 | if (e.key === 'Enter' && results.length) { |
| 265 | cb.onSelectFile?.(results[0], { fly: true }); |
| 266 | hideResults(); |
| 267 | searchEl.blur(); |
| 268 | } |
| 269 | if (e.key === 'Escape') { searchEl.value = ''; hideResults(); searchEl.blur(); } |
| 270 | e.stopPropagation(); |
| 271 | }); |
| 272 | document.addEventListener('click', (e) => { |
| 273 | if (!e.target.closest('#search-panel')) resultsEl.classList.remove('show'); |
| 274 | }); |
| 275 | |
| 276 | // ── ruta inferior ─────────────────────────────────────────────────── |
| 277 | function setPathParts(names) { |
| 278 | if (!names?.length) { pathEl.innerHTML = '<span class="dim">— sin selección · clic en un edificio o busca un fichero —</span>'; return; } |
| 279 | const sep = '<span class="sep">/</span>'; |
| 280 | const head = names.slice(0, -1).map(n => `<span class="seg">${n}</span>`).join(sep); |
| 281 | const last = `<span class="seg last">${names[names.length - 1]}</span>`; |
| 282 | pathEl.innerHTML = head ? head + sep + last : last; |
| 283 | } |
| 284 | function setPath(file, chainNames) { |
| 285 | setPathParts(file ? [...chainNames, file.name] : null); |
| 286 | } |
| 287 | |
| 288 | // ── botones ───────────────────────────────────────────────────────── |
| 289 | $('btn-aerial').addEventListener('click', () => cb.onView?.('aerial')); |
| 290 | $('btn-skyline').addEventListener('click', () => cb.onView?.('skyline')); |
| 291 | $('btn-reset').addEventListener('click', () => cb.onView?.('reset')); |
| 292 | $('btn-settings').addEventListener('click', () => openSettings()); |
| 293 | const legendBtn = $('btn-legend'); |
| 294 | let legendOn = true; |
| 295 | legendBtn.addEventListener('click', () => { |
| 296 | legendOn = !legendOn; |
| 297 | legendBtn.classList.toggle('off', !legendOn); |
| 298 | cb.onToggleLegend?.(legendOn); |
| 299 | }); |
| 300 | const groundBtn = $('btn-ground'); |
| 301 | let groundSolid = false; |
| 302 | groundBtn.classList.add('off'); |
| 303 | groundBtn.addEventListener('click', () => { |
| 304 | groundSolid = !groundSolid; |
| 305 | groundBtn.classList.toggle('off', !groundSolid); |
| 306 | cb.onToggleGround?.(groundSolid); |
| 307 | }); |
| 308 | const folderBtn = $('btn-folder'); |
| 309 | folderBtn.addEventListener('click', () => cb.onPickFolder?.()); |
| 310 | const reopenBtn = $('btn-reopen'); |
| 311 | reopenBtn.addEventListener('click', () => cb.onReopenFolder?.()); |
| 312 | function setReopen(name) { |
| 313 | reopenBtn.style.display = name ? '' : 'none'; |
| 314 | if (name) reopenBtn.textContent = `Reabrir ${name}`; |
| 315 | } |
| 316 | |
| 317 | // ── selector de tema ──────────────────────────────────────────────── |
| 318 | const themeSel = $('theme-select'); |
| 319 | for (const [key, t] of Object.entries(THEMES)) { |
| 320 | const opt = document.createElement('option'); |
| 321 | opt.value = key; |
| 322 | opt.textContent = `Tema · ${t.label}`; |
| 323 | themeSel.appendChild(opt); |
| 324 | } |
| 325 | themeSel.addEventListener('change', () => { cb.onTheme?.(themeSel.value); themeSel.blur(); }); |
| 326 | |
| 327 | // ── panel de ajustes visuales ────────────────────────────────────── |
| 328 | const settingsModal = $('settings-modal'); |
| 329 | const settingsControls = $('settings-controls'); |
| 330 | const settingsPresets = $('settings-presets'); |
| 331 | const bloomBox = $('setting-bloom'); |
| 332 | const settingsClose = $('settings-close'); |
| 333 | const settingsReset = $('settings-reset'); |
| 334 | const sliderDefs = [ |
| 335 | ['exposure', 'Exposición', 0.65, 1.8, 0.01], |
| 336 | ['brightness', 'Brillo', 0.75, 1.45, 0.01], |
| 337 | ['contrast', 'Contraste', 0.8, 1.8, 0.01], |
| 338 | ['saturate', 'Saturación', 0.6, 2.4, 0.01], |
| 339 | ['lines', 'Aristas', 0.45, 2.2, 0.01], |
| 340 | ['files', 'Celdas', 0.45, 2.4, 0.01], |
| 341 | ['glass', 'Cristal', 0.35, 2.2, 0.01], |
| 342 | ['facades', 'Fachadas', 0.2, 1.8, 0.01], |
| 343 | ['labels', 'Rótulos', 0.2, 2.4, 0.01], |
| 344 | ['ground', 'Suelo', 0.25, 1.5, 0.01], |
| 345 | ['fog', 'Niebla', 0.35, 1.8, 0.01], |
| 346 | ]; |
| 347 | const presets = { |
| 348 | Seguro: null, |
| 349 | Neón: { exposure: 1.24, brightness: 1.08, contrast: 1.28, saturate: 1.65, lines: 1.22, files: 1.35, glass: 1.16, facades: 1.12, labels: 1.45, ground: 1.08, fog: 0.92 }, |
| 350 | Cine: { exposure: 1.12, brightness: 0.98, contrast: 1.45, saturate: 1.28, lines: 1.05, files: 1.18, glass: 0.95, facades: 1.05, labels: 1.25, ground: 0.82, fog: 1.22 }, |
| 351 | Intenso: { exposure: 1.34, brightness: 1.12, contrast: 1.55, saturate: 2.0, lines: 1.55, files: 1.75, glass: 1.35, facades: 1.35, labels: 1.85, ground: 1.18, fog: 0.78 }, |
| 352 | }; |
| 353 | const settingInputs = new Map(); |
| 354 | |
| 355 | function syncSettings(v) { |
| 356 | for (const [key] of sliderDefs) { |
| 357 | const input = settingInputs.get(key); |
| 358 | const value = v?.[key]; |
| 359 | if (input && value !== undefined) { |
| 360 | input.value = value; |
| 361 | input.nextElementSibling.textContent = Number(value).toFixed(2); |
| 362 | } |
| 363 | } |
| 364 | bloomBox.checked = cb.isBloomEnabled?.() ?? false; |
| 365 | } |
| 366 | |
| 367 | for (const [name, values] of Object.entries(presets)) { |
| 368 | const btn = document.createElement('button'); |
| 369 | btn.type = 'button'; |
| 370 | btn.textContent = name; |
| 371 | btn.addEventListener('click', () => { |
| 372 | const next = cb.onVisualPreset?.(values); |
| 373 | syncSettings(next); |
| 374 | }); |
| 375 | settingsPresets.appendChild(btn); |
| 376 | } |
| 377 | |
| 378 | for (const [key, label, min, max, step] of sliderDefs) { |
| 379 | const row = document.createElement('label'); |
| 380 | row.className = 'setting-row'; |
| 381 | row.innerHTML = `<span>${label}</span><input type="range" min="${min}" max="${max}" step="${step}"><output></output>`; |
| 382 | const input = row.querySelector('input'); |
| 383 | const output = row.querySelector('output'); |
| 384 | input.addEventListener('input', () => { |
| 385 | output.textContent = Number(input.value).toFixed(2); |
| 386 | cb.onVisualSettings?.({ [key]: Number(input.value) }); |
| 387 | }); |
| 388 | settingInputs.set(key, input); |
| 389 | settingsControls.appendChild(row); |
| 390 | } |
| 391 | bloomBox.addEventListener('change', () => cb.onBloomMode?.(bloomBox.checked)); |
| 392 | settingsReset.addEventListener('click', () => syncSettings(cb.onVisualPreset?.(null))); |
| 393 | settingsClose.addEventListener('click', closeSettings); |
| 394 | settingsModal.addEventListener('click', (e) => { if (e.target === settingsModal) closeSettings(); }); |
| 395 | document.addEventListener('keydown', (e) => { |
| 396 | if (e.key === 'Escape' && settingsModal.classList.contains('show')) closeSettings(); |
| 397 | }); |
| 398 | function openSettings() { |
| 399 | syncSettings(cb.getVisualSettings?.()); |
| 400 | settingsModal.classList.add('show'); |
| 401 | settingsModal.setAttribute('aria-hidden', 'false'); |
| 402 | } |
| 403 | function closeSettings() { |
| 404 | settingsModal.classList.remove('show'); |
| 405 | settingsModal.setAttribute('aria-hidden', 'true'); |
| 406 | } |
| 407 | window.VCCOpenSettings = openSettings; |
| 408 | window.VCCCloseSettings = closeSettings; |
| 409 | |
| 410 | // ── selector de modo de coloreado ─────────────────────────────────── |
| 411 | const modeBtns = [...document.querySelectorAll('#mode-switch button')]; |
| 412 | for (const btn of modeBtns) { |
| 413 | btn.addEventListener('click', () => { |
| 414 | btn.blur(); // el foco residual se confundía con el estado activo |
| 415 | if (!btn.disabled) cb.onMode?.(btn.dataset.mode); |
| 416 | }); |
| 417 | } |
| 418 | function setActiveMode(mode) { |
| 419 | for (const btn of modeBtns) btn.classList.toggle('active', btn.dataset.mode === mode); |
| 420 | } |
| 421 | function setModeAvailable(mode, ok) { |
| 422 | const btn = modeBtns.find(b => b.dataset.mode === mode); |
| 423 | if (btn) { |
| 424 | btn.disabled = !ok; |
| 425 | const why = { |
| 426 | git: 'sin datos git (ni .git/index legible)', |
| 427 | ownership: 'sin reglas de code ownership', |
| 428 | blast: 'sin relaciones de código detectadas', |
| 429 | }; |
| 430 | btn.title = ok ? '' : (why[mode] ?? ''); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | // leyenda de colores (sobre el panel de navegación) |
| 435 | const legendEl = $('color-legend'); |
| 436 | function setColorLegend(entries) { |
| 437 | legendEl.innerHTML = ''; |
| 438 | legendEl.classList.toggle('show', !!entries?.length); |
| 439 | for (const e of entries ?? []) { |
| 440 | const div = document.createElement('div'); |
| 441 | div.className = 'entry'; |
| 442 | const [r, g, b] = e.color.map(c => Math.round(Math.min(1, c) * 255)); |
| 443 | div.innerHTML = `<span class="swatch" style="background:rgb(${r},${g},${b});color:rgb(${r},${g},${b})"></span><span>${e.label}</span>`; |
| 444 | legendEl.appendChild(div); |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | function setFolderSupported(ok) { folderBtn.style.display = ok ? '' : 'none'; } |
| 449 | function setLoading(msg) { |
| 450 | folderBtn.disabled = !!msg; |
| 451 | reopenBtn.disabled = !!msg; |
| 452 | folderBtn.textContent = msg || 'Abrir Carpeta…'; |
| 453 | } |
| 454 | |
| 455 | // ── stats / modo vuelo ────────────────────────────────────────────── |
| 456 | let baseFileCount = 0; |
| 457 | let gpuLabel = ''; |
| 458 | function setGpu(gpu) { |
| 459 | if (!gpu) { gpuLabel = ''; return; } |
| 460 | const mode = gpu.bloom ? `bloom ×${gpu.msaaSamples}` : 'render directo'; |
| 461 | if (gpu.tier === 'software') gpuLabel = ` · render software · ${mode}`; |
| 462 | else if (gpu.tier === 'alta') gpuLabel = ` · GPU ${gpu.brand || 'discreta'} · ${mode}`; |
| 463 | else gpuLabel = ` · ${mode}`; |
| 464 | } |
| 465 | // progreso del análisis perezoso del modo Blast (lotes en segundo plano) |
| 466 | let analysisLabel = ''; |
| 467 | function setAnalysis(msg) { analysisLabel = msg ? ` · ${msg}` : ''; } |
| 468 | function setStats(fps) { |
| 469 | const urbs = model.urbs?.length ? ` · ${model.urbs.length} urbanizaciones` : ''; |
| 470 | statsEl.textContent = |
| 471 | `${baseFileCount} ficheros + ${model.files.length - baseFileCount} ignorados · ${model.buildings.length} edificios${urbs} · ${model.districts.length} distritos · ${fps} fps${gpuLabel}${analysisLabel}`; |
| 472 | } |
| 473 | |
| 474 | function setFlyMode(on) { |
| 475 | document.body.classList.toggle('flying', on); |
| 476 | } |
| 477 | |
| 478 | return { |
| 479 | setModel, markFile, markNode, setPath, setPathParts, setStats, setGpu, setAnalysis, setFlyMode, hideResults, |
| 480 | setFolderSupported, setLoading, setActiveMode, setModeAvailable, setColorLegend, setReopen, |
| 481 | }; |
| 482 | } |