diff --git a/install.sh b/install.sh index 0dd5813..5f36775 100755 --- a/install.sh +++ b/install.sh @@ -181,10 +181,19 @@ copy_lib() { # copy_lib warn "no se pudo copiar: $3 ($1)" fi } -copy_lib node_modules/butterchurn/dist/butterchurn.min.js \ - lib/butterchurn.min.js "Butterchurn" -copy_lib node_modules/butterchurn-presets/dist/base.min.js \ - lib/butterchurn-presets.min.js "Presets de Butterchurn" +# Busca un fichero por nombre dentro de un paquete y lo copia. Es robusto a +# que el paquete cambie de carpeta (dist/, lib/, build/) entre versiones. +find_copy() { # find_copy + local f + f="$(find "node_modules/$1" -name "$2" -type f 2>/dev/null | head -n1)" + if [ -n "$f" ] && cp "$f" "$3" 2>/dev/null && [ -s "$3" ]; then + log_ok "$4" + else + warn "no se encontro $4 ($2 dentro de node_modules/$1)" + fi +} +find_copy butterchurn butterchurn.min.js lib/butterchurn.min.js "Butterchurn" +find_copy butterchurn-presets butterchurnPresets.min.js lib/butterchurn-presets.min.js "Presets de Butterchurn" copy_lib node_modules/socket.io-client/dist/socket.io.min.js \ lib/socket.io.min.js "Socket.IO" copy_lib node_modules/qrcode-generator/qrcode.js \ diff --git a/web/stage/stage.js b/web/stage/stage.js index e0142f8..1c73c95 100644 --- a/web/stage/stage.js +++ b/web/stage/stage.js @@ -521,6 +521,7 @@ function applyState(next) { if (hydra) hydra.hush(); if (shaderEngine) shaderEngine.stop(); mixerSig = ""; + if (!bcViz) { show(null); return; } show(bcCanvas); startButterchurn(); const wanted = state.butterchurn.preset; @@ -532,6 +533,7 @@ function applyState(next) { stopButterchurn(); if (shaderEngine) shaderEngine.stop(); mixerSig = ""; + if (!hydra) { show(null); return; } show(hydraCanvas); if (state.hydra.code !== hydraCode) runHydraCode(state.hydra.code); @@ -539,6 +541,7 @@ function applyState(next) { stopButterchurn(); if (hydra) hydra.hush(); mixerSig = ""; + if (!shaderEngine) { show(null); return; } show(shaderCanvas); if (shaderEngine && state.shaders.code !== shaderCode) { if (shaderEngine.load(state.shaders.code)) shaderCode = state.shaders.code; @@ -548,6 +551,7 @@ function applyState(next) { } else if (state.engine === "mixer") { stopButterchurn(); if (shaderEngine) shaderEngine.stop(); + if (!hydra) { show(null); return; } show(hydraCanvas); applyMixer(state.mixer); } @@ -579,24 +583,30 @@ window.addEventListener("resize", () => { // Arranque // ========================================================================== async function boot() { + // El audio es la base de todo: si falla, no se puede continuar. try { - if (typeof Hydra === "undefined" || typeof butterchurn === "undefined") { - report("error", "Faltan librerias de visuales. Ejecuta install.sh " - + "de nuevo en la Raspberry."); - msgEl.textContent = "ERROR: faltan librerias"; - return; - } await initAudio(); - initButterchurn(); - initHydra(); - shaderEngine = new ShaderEngine(shaderCanvas, analyser); beatLoop(); - msgEl.textContent = "FOSFENO listo"; } catch (err) { - report("error", "Fallo al arrancar el escenario: " + err.message - + ". Si menciona el microfono, comprueba que esta conectado."); - msgEl.textContent = "ERROR: " + err.message; + report("error", "No se pudo iniciar el audio: " + err.message + + ". Comprueba el microfono y recarga la pagina."); + msgEl.textContent = "ERROR: audio (" + err.message + ")"; + return; } + // Cada motor se inicia por separado: si una libreria falta o falla, los + // demas motores siguen funcionando igual. + try { + if (typeof butterchurn !== "undefined") initButterchurn(); + else report("warn", "Butterchurn no esta disponible (libreria no copiada)."); + } catch (e) { report("error", "Butterchurn fallo al iniciar: " + e.message); } + try { + if (typeof Hydra !== "undefined") initHydra(); + else report("error", "Hydra no esta disponible (libreria no copiada)."); + } catch (e) { report("error", "Hydra fallo al iniciar: " + e.message); } + try { + shaderEngine = new ShaderEngine(shaderCanvas, analyser); + } catch (e) { report("error", "El motor de shaders fallo: " + e.message); } + msgEl.textContent = "FOSFENO listo"; } boot();