3:00
@@ -571,9 +578,10 @@
root: p,
time: p.querySelector("[data-time]"),
moves: p.querySelector("[data-moves]"),
- score: p.querySelector("[data-score]"),
+ you: p.querySelector("[data-you]"),
+ them: p.querySelector("[data-them]"),
target: p.querySelector("[data-target]"),
- scoreLine: p.querySelector(".score"),
+ scoreLines: [].slice.call(p.querySelectorAll(".line:not(.line--moves)")),
delay: p.querySelector("[data-delay]"),
fill: p.querySelector("[data-fill]"),
dnum: p.querySelector("[data-dnum]")
@@ -691,7 +699,8 @@
el[i].time.textContent = fmt(main);
el[i].moves.textContent = st.moves[i];
- el[i].score.textContent = st.score[i] + " - " + st.score[1 - i];
+ el[i].you.textContent = st.score[i]; // each panel is "You" to its own player
+ el[i].them.textContent = st.score[1 - i];
el[i].target.textContent = cfg.points;
var showDelay = live && cfg.delay > 0 && dLeft > 0;
@@ -753,18 +762,19 @@
saveGame();
}
- function togglePause(){
- if(st.phase === RUN){
- pauseNow();
- return;
- }else if(st.phase === PAUSE){
- st.turnAt = performance.now() - st.held;
- st.phase = RUN;
- }else return;
+ function resumeNow(){
+ if(st.phase !== PAUSE) return;
+ st.turnAt = performance.now() - st.held; // pick the turn up where it stopped
+ st.phase = RUN;
paintPlay();
saveGame();
}
+ function togglePause(){
+ if(st.phase === RUN) pauseNow();
+ else resumeNow();
+ }
+
/* SVG elements aren't HTMLElements, so they have no .hidden property —
setting it only makes a JS expando. The attribute has to be set by hand. */
function showIcon(btn, name, on){
@@ -902,7 +912,7 @@
if(many) node.removeAttribute("hidden"); else node.setAttribute("hidden", "");
}
show(btnScore);
- el.forEach(function(e){ show(e.scoreLine); });
+ el.forEach(function(e){ e.scoreLines.forEach(show); });
}
function clock(ms){ // m:ss, for copy rather than the big readout
@@ -1003,12 +1013,23 @@
document.getElementById("done").addEventListener("click", closeSheet);
// tapping outside the score sheet discards the staged edits rather than
// committing them — a stray tap must never restart a game
- scrim.addEventListener("click", closeSheet);
+ scrim.addEventListener("click", function(){
+ if(openNode === scoreSheet) closeScore(); else closeSheet();
+ });
/* ============ score sheet ============ */
// Edits are staged here and only reach `st` on Done, so opening the sheet,
// fiddling and tapping away changes nothing.
- var edit = null, before = null;
+ var edit = null, before = null, resumeOnClose = false;
+
+ // leaving the sheet with the turn still live carries straight on. After a score
+ // change there is no turn to resume — newGame() has already moved us to IDLE,
+ // which the PAUSE check below quietly skips.
+ function closeScore(){
+ if(resumeOnClose) resumeNow();
+ resumeOnClose = false;
+ closeSheet();
+ }
function paintScore(){
document.getElementById("v-you").textContent = edit.score[1];
@@ -1021,6 +1042,9 @@
}
function openScore(){
+ // only the sheet's own pause gets undone on the way out; a pause the players
+ // set themselves survives
+ resumeOnClose = (st.phase === RUN);
pauseNow();
disarm();
// seed from what the panels are showing, not from the banked reserve — for
@@ -1074,7 +1098,7 @@
document.getElementById("score").addEventListener("click", openScore);
document.getElementById("score-done").addEventListener("click", function(){
applyScore();
- closeSheet();
+ closeScore();
});
btnReset.addEventListener("click", armReset);
diff --git a/public_html/sw.js b/public_html/sw.js
index 33dd73b..47e4768 100644
--- a/public_html/sw.js
+++ b/public_html/sw.js
@@ -1,5 +1,5 @@
/* Cache-first: once installed the clock never touches the network again. */
-const CACHE = "bgclock-v5";
+const CACHE = "bgclock-v6";
const FILES = [
"./",
"./index.html",