feat(ui): thinking timer replaces pv text
Compact 'agent_name думает m:ss' indicator with a pulsing dot, tabular nums, lives in the same slot the stockfish PV used to occupy. Resets on new_game (white starts thinking), flips to the opponent on every move, clears on game_over / when scrubbing history. Tickers tick 1 Hz. Drops the now-unused PV stringification in applyEvalForFen.
This commit is contained in:
+53
-5
@@ -200,12 +200,11 @@ function storeEval(e) {
|
||||
|
||||
function applyEvalForFen(fen) {
|
||||
const e = STATE.evalByFen.get(fenKey(fen));
|
||||
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text"), pv = $("sf-pv");
|
||||
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text");
|
||||
if (!e) {
|
||||
txt.textContent = "—";
|
||||
pv.textContent = "";
|
||||
bar.style.height = "50%";
|
||||
col.classList.remove("advantage-black");
|
||||
col.classList.remove("advantage-black", "advantage-white");
|
||||
return;
|
||||
}
|
||||
let pct = 50;
|
||||
@@ -222,9 +221,44 @@ function applyEvalForFen(fen) {
|
||||
bar.style.height = `${pct}%`;
|
||||
col.classList.toggle("advantage-black", pct < 50);
|
||||
col.classList.toggle("advantage-white", pct > 50);
|
||||
pv.textContent = e.pv && e.pv.length ? "pv: " + e.pv.slice(0, 6).join(" ") : "";
|
||||
}
|
||||
|
||||
// ---------- thinking timer ----------
|
||||
const THINK = {
|
||||
startedAt: null, // ms timestamp when current side started thinking
|
||||
side: null, // "white" | "black" | null
|
||||
lastMs: { white: 0, black: 0 },
|
||||
};
|
||||
|
||||
function fmtMmSs(ms) {
|
||||
if (ms == null || ms < 0) return "0:00";
|
||||
const s = Math.floor(ms / 1000);
|
||||
return `${Math.floor(s / 60)}:${(s % 60).toString().padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
function renderThinking() {
|
||||
const el = $("think-meter");
|
||||
if (!el) return;
|
||||
// No live thinking while viewing history or after game-over.
|
||||
const live = STATE.viewPly === null && THINK.side && !STATE.game?.status?.result;
|
||||
if (!live) {
|
||||
// Show last completed move's think time when in live + game-over,
|
||||
// otherwise stay quiet.
|
||||
if (STATE.game?.status?.result) {
|
||||
el.innerHTML = "";
|
||||
} else if (STATE.viewPly !== null) {
|
||||
el.innerHTML = "";
|
||||
} else {
|
||||
el.innerHTML = "";
|
||||
}
|
||||
return;
|
||||
}
|
||||
const elapsed = Date.now() - (THINK.startedAt || Date.now());
|
||||
const who = agentDisplay(THINK.side);
|
||||
el.innerHTML = `<span class="think-dot"></span><span class="think-who">${who}</span> думает <span class="think-time">${fmtMmSs(elapsed)}</span>`;
|
||||
}
|
||||
setInterval(renderThinking, 1000);
|
||||
|
||||
function applyEval(e) {
|
||||
storeEval(e);
|
||||
// If we're currently looking at this fen, refresh the visuals.
|
||||
@@ -262,7 +296,12 @@ function connect() {
|
||||
if (ev.type === "new_game") {
|
||||
STATE.game = ev.game;
|
||||
STATE.viewPly = null;
|
||||
THINK.startedAt = Date.now();
|
||||
THINK.side = "white";
|
||||
THINK.lastMs = { white: 0, black: 0 };
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||
refreshGamesLink();
|
||||
renderThinking();
|
||||
log(`new game: ${ev.game?.id || "?"}`);
|
||||
return;
|
||||
}
|
||||
@@ -274,8 +313,14 @@ function connect() {
|
||||
if (!ev.status?.result) {
|
||||
STATE.game.side_to_move = ev.side === "white" ? "black" : "white";
|
||||
}
|
||||
// think timer: mover finished, opponent starts
|
||||
if (THINK.startedAt != null && THINK.side === ev.side) {
|
||||
THINK.lastMs[ev.side] = Date.now() - THINK.startedAt;
|
||||
}
|
||||
THINK.startedAt = ev.status?.result ? null : Date.now();
|
||||
THINK.side = ev.status?.result ? null : (ev.side === "white" ? "black" : "white");
|
||||
// stay live unless user clicked back
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||
renderBoard(); renderChat(); renderHistory(); renderStatus(); renderThinking();
|
||||
log(`${ev.side} ${ev.san} «${ev.comment || ""}»`);
|
||||
return;
|
||||
}
|
||||
@@ -285,7 +330,10 @@ function connect() {
|
||||
STATE.game.status.result = ev.result;
|
||||
STATE.game.status.termination = ev.termination;
|
||||
}
|
||||
THINK.startedAt = null;
|
||||
THINK.side = null;
|
||||
renderStatus();
|
||||
renderThinking();
|
||||
refreshGamesLink();
|
||||
// unlock the setup dialog if it was open and waiting
|
||||
try { refreshSetupGate(); } catch (e) {}
|
||||
|
||||
Reference in New Issue
Block a user