summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-12-05 15:13:01 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2024-12-05 15:13:01 +0000
commitd8b6a685d2cc63160d32c184c4a24a515132f9ee (patch)
tree4c3ed873ba1a2b7cd8d8ad2701c13a948dcca97b /play.js
parent7b56c444ed12ec421286ddb754576c6cbe6354c5 (diff)
download1989-dawn-of-freedom-d8b6a685d2cc63160d32c184c4a24a515132f9ee.tar.gz
Add boxed events
Diffstat (limited to 'play.js')
-rw-r--r--play.js64
1 files changed, 62 insertions, 2 deletions
diff --git a/play.js b/play.js
index 07538a7..2eefe26 100644
--- a/play.js
+++ b/play.js
@@ -197,6 +197,9 @@ const C_KREMLIN_COUP = 109
const C_MALTA_SUMMIT = 110
// END CONST }}}
+
+const scoring_cards = [22, 23, 42, 43, 55, 95]
+
// BEGIN LAYOUT {{{
var LAYOUT = {
"Babes-Bolyai University": [958,1529,127,75],
@@ -828,6 +831,10 @@ function on_update() {
// =========================== LOG FUNCTIONS ==============================================
+let log_event = 0
+let event_n = 0
+let event_side = null
+
function sub_card_name(_match, p1) {
let x = p1 | 0
return `<span class="card_name" onmouseenter="on_focus_card_tip(${x})" onmouseleave="on_blur_card_tip()">${cards[x].name.replace("*", "")}</span>`
@@ -862,14 +869,27 @@ const die = {
D6: '<span class="die white d6"></span>',
}
-function on_log(text) {
+function on_log(text, ix) {
let p = document.createElement("div")
+ console.log('text', text)
+ let event_string = text.match(/^C(\d+)/)
+ console.log('event_string', event_string)
+ if (event_string)
+ event_n = parseInt(event_string[1])
+ console.log('event_n', event_n)
+
+ if (text.match(/^>>/)) {
+ text = text.substring(2)
+ p.className = "ii"
+ }
if (text.match(/^>/)) {
text = text.substring(1)
p.className = "i"
}
+
+
text = text.replace(/_/g, " ")
text = text.replace(/C(\d+)/g, sub_card_name)
text = text.replace(/P(\d+)/g, sub_power_card_name)
@@ -877,21 +897,61 @@ function on_log(text) {
text = text.replace(/%(\d+)/g, sub_space_name)
text = text.replace(/D[1-6]/g, sub_die)
+ console.log('text', text)
if (text.match(/^\.h1/)) {
text = text.substring(4)
p.className = "h1"
+ log_event = 0
} else if (text.match(/^\.h2/)) {
text = text.substring(4)
p.className = "h2"
+ log_event = 0
} else if (text.match(/^\.d/)) {
text = "Democrat"
p.className = "h2 dem"
- } else if (text.match(/^\.c/)) {
+ log_event = 0
+ } /*else if (text.match(/\.D$/)) {
+ p.classList.add("dem")
+ } */ else if (text.match(/^\.c/)) {
text = "Communist"
p.className = "h2 com"
+ log_event = 0
} else if (text.match(/^\.h3/)) {
text = text.substring(4)
p.className = "h3"
+ log_event = 0
+ }
+
+//Group events
+console.log('text', text, 'ix', ix, 'log_event', log_event, 'event_side', event_side)
+ // Reset group box counters (when log is rewound)
+ if (ix <= log_event) log_event = 0
+
+ if (!scoring_cards.includes(event_n)) {
+ console.log('applying group')
+ if (text.match(/^.E:/)) {
+ p.classList.add("h2")
+ log_event = ix
+ text = text.replace(".E:", "")
+ }
+ if (text.match(/\.D$/)) {
+ event_side = "dem"
+ text = text.replace(".D", "")
+ } else if (text.match(/\.C$/)) {
+ event_side = "com"
+ text = text.replace(".C", "")
+ } else if (text.match(/\.N$/)) {
+ event_side = "both"
+ text = text.replace(".N", "")
+ }
+
+ if (log_event && text === "") {
+ log_event = 0
+ event_side = null
+ }
+
+ if (log_event)
+ p.classList.add("group", "event", event_side)
}
p.innerHTML = text