From 9a256e2e5ba2b266dfdf0aa0bc7da6496b2b0a70 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 10 Dec 2023 19:44:39 +0100 Subject: Fix log box grouping bug when undoing back past the start. --- play.js | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/play.js b/play.js index f58fbe9..75a6fa2 100644 --- a/play.js +++ b/play.js @@ -1608,11 +1608,12 @@ function sub_card_x(match, p1, p2) { return `${p1} ${p2}` } -var log_combat = 0 +var log_combat2 = 0 +var log_combat1 = 0 var log_place = 0 var log_pretender = 0 -function on_log(text) { +function on_log(text, ix) { let p = document.createElement("div") if (text.match(/^>/)) { @@ -1667,14 +1668,20 @@ function on_log(text) { p.className = "h3" } + // Reset group box counters (when log is rewound) + if (ix <= log_combat2) log_combat2 = 0 + if (ix <= log_combat1) log_combat1 = 0 + if (ix <= log_place) log_place = 0 + if (ix <= log_pretender) log_pretender = 0 + // Group pretender messages if (text.match(/^Pretender\.$/) || text.match(/^Occupied /)) { - log_pretender = 1 + log_pretender = ix p.classList.add("h2") text = text.replace(".", "") } - if (log_pretender === 1 && text === "") + if (log_pretender && text === "") log_pretender = 0 if (log_pretender) p.classList.add("group", "populace") @@ -1683,9 +1690,10 @@ function on_log(text) { if (text.match(/^Battle in /)) { p.classList.add("h2") - log_combat = 2 + log_combat2 = ix + log_combat1 = ix } - if (log_combat > 0) { + if (log_combat1) { if ( text === "DEFENDER" || text === "ATTACKER" || @@ -1695,21 +1703,21 @@ function on_log(text) { ) p.classList.add("h3") if (text === "RESULT") - log_combat = 1 + log_combat2 = 0 } - if (log_combat === 1 && text === "") - log_combat = 0 - if (log_combat) + if (log_combat1 && !log_combat2 && text === "") + log_combat1 = 0 + if (log_combat1) p.classList.add("group", "military") // Group place governor if (text.match(/^Place Governor in /) || text.match(/^Praetorian Guard in /)) { - log_place = 1 + log_place = ix p.classList.add("h2") text = text.replace(".", "") } - if (log_place === 1 && text === "") + if (log_place && text === "") log_place = 0 if (log_place) p.classList.add("group", "senate") -- cgit v1.2.3