feat(ui): abort-game button next to new-game
Shows only while a game is in progress (hidden otherwise), red-tinted to distinguish from new-game. Hits POST /api/abort-game after a small confirm prompt. Game-over event hides it again.
This commit is contained in:
+11
-2
@@ -349,8 +349,10 @@ function isGameInProgress() {
|
|||||||
|
|
||||||
function refreshGamesLink() {
|
function refreshGamesLink() {
|
||||||
const link = $("games-link");
|
const link = $("games-link");
|
||||||
if (!link) return;
|
const abortBtn = $("abort-game");
|
||||||
if (isGameInProgress()) {
|
const inProgress = isGameInProgress();
|
||||||
|
if (link) {
|
||||||
|
if (inProgress) {
|
||||||
link.classList.add("disabled");
|
link.classList.add("disabled");
|
||||||
link.title = "finish or abort the current game to open games & stats";
|
link.title = "finish or abort the current game to open games & stats";
|
||||||
link.removeAttribute("href");
|
link.removeAttribute("href");
|
||||||
@@ -360,6 +362,8 @@ function refreshGamesLink() {
|
|||||||
link.setAttribute("href", "/games");
|
link.setAttribute("href", "/games");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (abortBtn) abortBtn.hidden = !inProgress;
|
||||||
|
}
|
||||||
|
|
||||||
function refreshSetupGate() {
|
function refreshSetupGate() {
|
||||||
const blocked = isGameInProgress();
|
const blocked = isGameInProgress();
|
||||||
@@ -405,6 +409,11 @@ document.addEventListener("click", (e) => {
|
|||||||
|
|
||||||
$("new-game").addEventListener("click", () => openSetupDialog());
|
$("new-game").addEventListener("click", () => openSetupDialog());
|
||||||
|
|
||||||
|
$("abort-game").addEventListener("click", async () => {
|
||||||
|
if (!confirm("Прервать текущую партию?")) return;
|
||||||
|
await fetch("/api/abort-game", { method: "POST" });
|
||||||
|
});
|
||||||
|
|
||||||
// Agent change → repopulate models
|
// Agent change → repopulate models
|
||||||
for (const side of ["white", "black"]) {
|
for (const side of ["white", "black"]) {
|
||||||
document.querySelector(`[name="${side}-agent"]`).addEventListener("change", () => {
|
document.querySelector(`[name="${side}-agent"]`).addEventListener("change", () => {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
<span id="sf-pv"></span>
|
<span id="sf-pv"></span>
|
||||||
<button id="live-btn" hidden>live</button>
|
<button id="live-btn" hidden>live</button>
|
||||||
<a id="games-link" href="/games">games & stats</a>
|
<a id="games-link" href="/games">games & stats</a>
|
||||||
|
<button id="abort-game" hidden>abort game</button>
|
||||||
<button id="new-game">new game</button>
|
<button id="new-game">new game</button>
|
||||||
<button id="settings-btn" title="settings">⚙</button>
|
<button id="settings-btn" title="settings">⚙</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -162,6 +162,8 @@ button {
|
|||||||
}
|
}
|
||||||
button:hover { background: #2e2e36; }
|
button:hover { background: #2e2e36; }
|
||||||
#live-btn { background: #3d342a; color: #f0d090; }
|
#live-btn { background: #3d342a; color: #f0d090; }
|
||||||
|
#abort-game { background: #3a2222; color: #e09080; border-color: #5a3030; }
|
||||||
|
#abort-game:hover { background: #4a2a2a; }
|
||||||
|
|
||||||
dialog {
|
dialog {
|
||||||
background: #15151a; color: #e7e5e4; border: 1px solid #2a2a30;
|
background: #15151a; color: #e7e5e4; border: 1px solid #2a2a30;
|
||||||
|
|||||||
Reference in New Issue
Block a user