diff --git a/src/html/advanced.html b/src/html/advanced.html index 62112087..2c476525 100644 --- a/src/html/advanced.html +++ b/src/html/advanced.html @@ -3863,7 +3863,7 @@ const App = () => { let stockfish = null; let stockfish_state = "INIT"; // 'READY', 'FAILED' - let output2 = ""; + let engineoutput = ""; let first_engine_output = ""; let second_engine_output = ""; let analysis_engine_output = ""; @@ -5086,11 +5086,11 @@ //console.log("WHITE: go " + wargs); } } else if (!black_engine_ponder_and_human_white) { - output2 = ""; + engineoutput = ""; stockfish.postMessage(`go ${args}`); } } else if (!black_engine_ponder_and_human_white) { - output2 = ""; + engineoutput = ""; stockfish.postMessage(`go ${args}`); } if (fge.second_engine) { @@ -5178,11 +5178,11 @@ //console.log("BLACK: go " + bargs); } } else if (!white_engine_ponder_and_human_black) { - output2 = ""; + engineoutput = ""; stockfish.postMessage(`go ${args}`); } } else if (!white_engine_ponder_and_human_black) { - output2 = ""; + engineoutput = ""; stockfish.postMessage(`go ${args}`); } if (fge.first_engine) { @@ -5217,7 +5217,7 @@ } } } else { - output2 = ""; + engineoutput = ""; stockfish.postMessage(`go ${args}`); } }; @@ -6057,8 +6057,9 @@ }; const scrollOutput = () => { - $("#output2").scrollTo({ - top: $("#output2").scrollHeight, + //Modern browsers will automatically create a variable for an element that has ID, with its name the same as the ID + output2.scrollTo({ + top: output2.scrollHeight, behavior: "smooth", }); }; @@ -6204,7 +6205,7 @@ $("#move").value += " " + line.split(" ")[1]; $("#set").click(); } - output2 += line + "\n"; + engineoutput += line + "\n"; if (fge.analysis_engine) { if (!fge.analysis_engine.IsUsing) { $("#engineoutputline").value = line; @@ -7228,10 +7229,9 @@ hidden: true, onclick: () => { if (fge.first_engine) { + const target = document.getElementById("whiteengineoutput"); const OutputUpdateThrottleFunction = Throttle(() => { - document.getElementById( - "whiteengineoutput", - ).textContent += first_engine_output; + target.textContent += first_engine_output; first_engine_output = ""; scrollOutput(); }, throttle_threshold); @@ -7250,10 +7250,9 @@ }; } if (fge.second_engine) { + const target = document.getElementById("blackengineoutput"); const OutputUpdateThrottleFunction = Throttle(() => { - document.getElementById( - "blackengineoutput", - ).textContent += second_engine_output; + target.textContent += second_engine_output; second_engine_output = ""; scrollOutput(); }, throttle_threshold); @@ -7272,10 +7271,13 @@ }; } if (fge.analysis_engine) { + const target = document.getElementById( + "analysisengineoutput", + ); + const outputline = + document.getElementById("engineoutputline"); const OutputUpdateThrottleFunction = Throttle(() => { - document.getElementById( - "analysisengineoutput", - ).textContent += analysis_engine_output; + target.textContent += analysis_engine_output; analysis_engine_output = ""; scrollOutput(); }, throttle_threshold); @@ -7284,8 +7286,8 @@ OutputUpdateThrottleFunction(); }; fge.analysis_engine.EvaluationUpdateCallBack = (msg) => { - document.getElementById("engineoutputline").value = msg; - document.getElementById("engineoutputline").click(); + outputline.value = msg; + outputline.click(); }; fge.analysis_engine.SendMessageCallBack = (msg) => { analysis_engine_output += "\n▶▶ " + msg + "\n\n"; @@ -8747,7 +8749,7 @@ m("p#currentboardfen"), m("p#label-pgn.ripple"), m("div#output2", { onupdate: scrollOutput }, [ - m("pre#fsfoutput", output2), + m("pre#fsfoutput", engineoutput), m( "pre#whiteengineoutput", { hidden: true }, diff --git a/src/js/BinaryEngineFeature.js b/src/js/BinaryEngineFeature.js index f4bf29f6..6468ad5e 100644 --- a/src/js/BinaryEngineFeature.js +++ b/src/js/BinaryEngineFeature.js @@ -1154,8 +1154,10 @@ class Engine { this.IsLoading = false; this.IsLoaded = false; this.IsUsing = false; + console.error( + `Engine ID ${this.ID} Color ${this.Color} exited unexpectedly.`, + ); if (typeof this.LoadFailureCallBack == "function") { - console.error("Engine exited unexpectedly."); this.LoadFailureCallBack("Engine exited unexpectedly."); } } else if ( @@ -2776,21 +2778,30 @@ function ShowEngineManagementUI(EngineList, ws) { engineinfodiv.style.marginBottom = "5px"; engineinfodiv.style.flexDirection = "column"; let whiteengineinfo = document.createElement("p"); - if (window.fairyground.BinaryEngineFeature.first_engine) { + if ( + window.fairyground.BinaryEngineFeature.first_engine && + window.fairyground.BinaryEngineFeature.first_engine.IsLoaded + ) { whiteengineinfo.innerText = `First Engine (WHITE) → ID: ${window.fairyground.BinaryEngineFeature.first_engine.ID} Name: ${window.fairyground.BinaryEngineFeature.first_engine.Name} Author: ${window.fairyground.BinaryEngineFeature.first_engine.Author}`; } else { whiteengineinfo.innerText = "First Engine (WHITE) → (Not Loaded)"; } engineinfodiv.appendChild(whiteengineinfo); let blackengineinfo = document.createElement("p"); - if (window.fairyground.BinaryEngineFeature.second_engine) { + if ( + window.fairyground.BinaryEngineFeature.second_engine && + window.fairyground.BinaryEngineFeature.second_engine.IsLoaded + ) { blackengineinfo.innerText = `Second Engine (BLACK) → ID: ${window.fairyground.BinaryEngineFeature.second_engine.ID} Name: ${window.fairyground.BinaryEngineFeature.second_engine.Name} Author: ${window.fairyground.BinaryEngineFeature.second_engine.Author}`; } else { blackengineinfo.innerText = "Second Engine (BLACK) → (Not Loaded)"; } engineinfodiv.appendChild(blackengineinfo); let analysisengineinfo = document.createElement("p"); - if (window.fairyground.BinaryEngineFeature.analysis_engine) { + if ( + window.fairyground.BinaryEngineFeature.analysis_engine && + window.fairyground.BinaryEngineFeature.analysis_engine.IsLoaded + ) { analysisengineinfo.innerText = `Analysis Engine (ANALYSIS) → ID: ${window.fairyground.BinaryEngineFeature.analysis_engine.ID} Name: ${window.fairyground.BinaryEngineFeature.analysis_engine.Name} Author: ${window.fairyground.BinaryEngineFeature.analysis_engine.Author}`; } else { analysisengineinfo.innerText = "Analysis Engine (ANALYSIS) → (Not Loaded)"; @@ -2912,6 +2923,9 @@ function ShowEngineManagementUI(EngineList, ws) { }, (err) => { whiteengineinfo.innerText = `First Engine (WHITE) → (Not Loaded) (Error: ${err})`; + document.getElementById("whiteengineoutput").textContent += + "\n[Error] ❌ " + err + "\n\n"; + window.alert("Engine WHITE Error: " + err); }, ); }; @@ -2952,6 +2966,9 @@ function ShowEngineManagementUI(EngineList, ws) { }, (err) => { blackengineinfo.innerText = `Second Engine (BLACK) → (Not Loaded) (Error: ${err})`; + document.getElementById("blackengineoutput").textContent += + "\n[Error] ❌ " + err + "\n\n"; + window.alert("Engine BLACK Error: " + err); }, ); }; @@ -2992,6 +3009,9 @@ function ShowEngineManagementUI(EngineList, ws) { }, (err) => { analysisengineinfo.innerText = `Analysis Engine (ANALYSIS) → (Not Loaded) (Error: ${err})`; + document.getElementById("analysisengineoutput").textContent += + "\n[Error] ❌ " + err + "\n\n"; + window.alert("Engine ANALYSIS Error: " + err); }, ); };