From 9efe183658c9779f2883f7c7e533840604c3a800 Mon Sep 17 00:00:00 2001 From: Ugo Finnendahl Date: Sun, 3 Nov 2024 15:26:21 +0100 Subject: [PATCH] add breaks to end dialog --- assets/js/views/xoi/logic.js | 19 +++++++++++++++++++ assets/js/views/xoi/main.js | 6 +++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/assets/js/views/xoi/logic.js b/assets/js/views/xoi/logic.js index 6ab2a95..8d215d0 100644 --- a/assets/js/views/xoi/logic.js +++ b/assets/js/views/xoi/logic.js @@ -113,6 +113,25 @@ export function getGameProps(page, current_set, current_leg) { }); ret.current_player = current_player; + const breaks = computed(() => { + let b = [0,0]; + for (const j in page.game.sets) { + const set = page.game.sets[j]; + for (const i in set.legs) { + const l = set.legs[i]; + if (l.visits[l.visits.length-1].toGo === undefined) { + return b; + } + if (l.visits[l.visits.length-1].toGo[0] == 0 && i%2 == 1) + b[0] += 1; + else if (l.visits[l.visits.length-1].toGo[1] == 0 && i%2 == 0) + b[1] += 1; + } + } + return b; + }); + ret.breaks = breaks; + const getVal = (tr) => { const val = tr.trim(); if (val == "") { diff --git a/assets/js/views/xoi/main.js b/assets/js/views/xoi/main.js index b5a3481..3d11aae 100644 --- a/assets/js/views/xoi/main.js +++ b/assets/js/views/xoi/main.js @@ -454,11 +454,11 @@ const impossibleDialog = (sum) => { }]} } -const gameOverDialog = (winner, points) => { +const gameOverDialog = (winner, points, breaks) => { return { "withshortkey": true, "title": `Game Over`, - "text": `${winner != "DRAW" ? "The winner is": ""} ${winner} with ${points[0]}-${points[1]}`, + "text": `${winner != "DRAW" ? "The winner is": ""} ${winner} with ${points[0]}-${points[1]} (Breaks: ${breaks[0]}-${breaks[1]})`, "buttons": [ { "component": "d-plainElem", @@ -650,7 +650,7 @@ const gameStateMachine = (gamestack, stack, page, computedProps) => { if (winner != -2){ name = page.players[winner].forename; } - const [answer, error] = await overlayAndPop("d-dialog", gameOverDialog(name, points[1]), stack); + const [answer, error] = await overlayAndPop("d-dialog", gameOverDialog(name, points[1], computedProps.breaks.value), stack); if (answer == "end") { saveGame(page); return [undefined, page.stats.winner];