summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-12-10 19:44:39 +0100
committerTor Andersson <tor@ccxvii.net>2023-12-10 19:44:39 +0100
commit9a256e2e5ba2b266dfdf0aa0bc7da6496b2b0a70 (patch)
tree211d09fe265368dbac2d9c69116b2e7cbf9514df
parentd9a7e1e6415a8af10628230335369610cec98f44 (diff)
downloadtime-of-crisis-9a256e2e5ba2b266dfdf0aa0bc7da6496b2b0a70.tar.gz
Fix log box grouping bug when undoing back past the start.
-rw-r--r--play.js32
1 files 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 `<span class="tip ${match[0]}" onmouseenter="on_focus_influence_tip(${x})" onmouseleave="on_blur_tip()">${p1} ${p2}</span>`
}
-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")