summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.editorconfig7
-rw-r--r--play.js217
2 files changed, 114 insertions, 110 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..5f2605e
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,7 @@
+root = true
+
+[*.js]
+indent_style = tab
+insert_final_newline = true
+trim_trailing_whitespace = true
+end_of_line = lf
diff --git a/play.js b/play.js
index f94a7db..dcbc928 100644
--- a/play.js
+++ b/play.js
@@ -2,6 +2,9 @@
// vim:set foldmethod=marker:
+/* global view, roles, send_action, action_button, scroll_into_view */
+/* global spaces, cards, power_cards */
+
// BEGIN CONST {{{
// SPACES
@@ -328,9 +331,30 @@ const last_space = 74
const last_card = 110
const last_power_card = 54
-const countries = [ "Poland", "Hungary", "East_Germany", "Bulgaria", "Czechoslovakia", "Romania" ]
-const board_events = [ 2, 9, 69, 97 ]
-const box_events = [ 15, 24, 26, 39, 48, 49, 53, 58, 59, 65, 70, 73, 100, 101, 104 ]
+const board_events = [
+ C_SOLIDARITY_LEGALIZED,
+ C_THE_WALL,
+ C_SYSTEMATIZATION,
+ C_THE_TYRANT_IS_GONE
+]
+
+const box_events = [
+ C_HONECKER,
+ C_ST_NICHOLAS_CHURCH,
+ C_HELSINKI_FINAL_ACT,
+ C_ECO_GLASNOST,
+ C_WE_ARE_THE_PEOPLE,
+ C_FOREIGN_CURRENCY_DEBT_BURDEN,
+ C_LI_PENG,
+ C_AUSTRIA_HUNGARY_BORDER_REOPENED,
+ C_GRENZTRUPPEN,
+ C_PRESIDENTIAL_VISIT,
+ C_SECURITATE,
+ C_LASZLO_TOKES,
+ C_STAND_FAST,
+ C_ELENA,
+ C_NEW_YEARS_EVE_PARTY,
+]
const ui = {
favicon: document.getElementById("favicon"),
@@ -381,8 +405,8 @@ function create_ui() {
for (let s = 1; s <= last_space; ++s) {
let info = spaces[s]
let [ x, y, w, h ] = LAYOUT[info.ascii_name]
- let xc = Math.round( x + w / 2 )
- let yc = Math.round( y + h / 2 )
+ let xc = Math.round(x + w / 2)
+ let yc = Math.round(y + h / 2)
x -= 6
y -= 6
w += 12
@@ -401,14 +425,14 @@ function create_ui() {
let com_e = document.createElement("div")
com_e.className = "marker comInfl hide"
- com_e.style.left = (xc + 32 - 25) + "px"
- com_e.style.top = (yc + 12 - 25) + "px"
+ com_e.style.left = xc + 32 - 25 + "px"
+ com_e.style.top = yc + 12 - 25 + "px"
ui.com_inf[s] = com_e
let dem_e = document.createElement("div")
dem_e.className = "marker demInfl hide"
- dem_e.style.left = (xc - 32 - 25) + "px"
- dem_e.style.top = (yc + 12 - 25) + "px"
+ dem_e.style.left = xc - 32 - 25 + "px"
+ dem_e.style.top = yc + 12 - 25 + "px"
ui.dem_inf[s] = dem_e
document.getElementById("spaces").append(space_e)
@@ -416,7 +440,6 @@ function create_ui() {
document.getElementById("markers").appendChild(dem_e)
}
-
ui.cards = []
for (let c = 1; c <= last_card; ++c) {
const card_e = document.createElement("div")
@@ -455,76 +478,20 @@ function create_ui() {
create_country(5, "country_romania")
}
-// SUPPORTING FUNCTIONS
-
-function on_click_space(evt) {
- if (evt.button === 0) {
- const space = evt.target.my_space
- //console.log('on_click_space_called with space:', space);
- if (send_action("space", space)) {
- console.log('send_action with space:', space);
- evt.stopPropagation()
- } else if (send_action("sc", space)) {
- //console.log('send_action with sc:', space);
- evt.stopPropagation()
- } else {
- // console.log('send_action failed for space:', space);
- }
- }
- //hide_popup_menu();
-}
-
-function on_log(text) {
- // eslint-disable-line no-unused-vars
-
- let p = document.createElement("div")
-
- 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)
- text = text.replace(/V(\d+)/g, sub_power_card_value)
- text = text.replace(/%(\d+)/g, sub_space_name)
- text = text.replace(/D[1-6]/g, sub_die)
-
- if (text.match(/^\.h1/)) {
- text = text.substring(4)
- p.className = "h1"
- } else if (text.match(/^\.h2d/)) {
- text = text.substring(5)
- p.className = "h2 dem"
- } else if (text.match(/^\.h2c/)) {
- text = text.substring(5)
- p.className = "h2 com"
- } else if (text.match(/^\.h2/)) {
- text = text.substring(4)
- p.className = "h2"
- } else if (text.match(/^\.h3/)) {
- text = text.substring(4)
- p.className = "h3"
- }
-
- p.innerHTML = text
- return p
-}
-
function layout_turn_marker() {
let x = 654 + 24 + (view.turn - 1) * 53
let y = 80 + 24
- ui.turn.style.left = (x - 25) + "px"
- ui.turn.style.top = (y - 25) + "px"
+ ui.turn.style.left = x - 25 + "px"
+ ui.turn.style.top = y - 25 + "px"
}
function layout_round_marker() {
let x = 709 + 24 + (view.turn - 1) * 53
let y = 142 + 24
- ui.round.style.left = (x - 25) + "px"
- ui.round.style.top = (y - 25) + "px"
- if (view.round_player === "Democrat") // TODO: bit flag?
+ ui.round.style.left = x - 25 + "px"
+ ui.round.style.top = y - 25 + "px"
+ if (view.round_player === "Democrat")
+ // TODO: bit flag?
ui.round.className = "marker dem"
else
ui.round.className = "marker com"
@@ -533,18 +500,18 @@ function layout_round_marker() {
function layout_stability_marker() {
let x = 24 + 1381
let y = 24 + 1081 + view.stability * 54
- ui.stability.style.left = (x - 25) + "px"
- ui.stability.style.top = (y - 25) + "px"
+ ui.stability.style.left = x - 25 + "px"
+ ui.stability.style.top = y - 25 + "px"
}
-let TST_X = [ 53, 53+69, 53+69*2, 53+69*3, 53+69*4, 53+69*5, 53+69*6, 556 ]
+let TST_X = [ 53, 53 + 69, 53 + 69 * 2, 53 + 69 * 3, 53 + 69 * 4, 53 + 69 * 5, 53 + 69 * 6, 556 ]
let TST_Y = [ 2128, 2257 ]
function layout_tst_marker(e, v, top) {
let x = TST_X[v] + 24
let y = TST_Y[top] + 24
- e.style.left = (x - 25) + "px"
- e.style.top = (y - 25) + "px"
+ e.style.left = x - 25 + "px"
+ e.style.top = y - 25 + "px"
}
function layout_vp_marker() {
@@ -552,27 +519,25 @@ function layout_vp_marker() {
if (view.vp === 0) {
y = 2425 + 25
x = 843 + 28
- }
- else if (view.vp < 0) {
+ } else if (view.vp < 0) {
if (view.vp & 1) {
y = 2456 + 25
- x = 803 + 28 - (-view.vp - 1)/2 * 62
+ x = 803 + 28 - ((-view.vp - 1) / 2) * 62
} else {
y = 2395 + 25
- x = 772 + 28 - (-view.vp - 2)/2 * 62
+ x = 772 + 28 - ((-view.vp - 2) / 2) * 62
}
- }
- else if (view.vp > 0) {
+ } else if (view.vp > 0) {
if (view.vp & 1) {
y = 2396 + 25
- x = 883 + 28 + (view.vp - 1)/2 * 62
+ x = 883 + 28 + ((view.vp - 1) / 2) * 62
} else {
y = 2455 + 25
- x = 913 + 28 + (view.vp - 2)/2 * 62
+ x = 913 + 28 + ((view.vp - 2) / 2) * 62
}
}
- ui.vp.style.left = (x - 25) + "px"
- ui.vp.style.top = (y - 25) + "px"
+ ui.vp.style.left = x - 25 + "px"
+ ui.vp.style.top = y - 25 + "px"
}
function layout_country(id) {
@@ -614,30 +579,30 @@ function on_update() {
// UPDATE EVENT MARKERS ON THE BOARD
- if (view.persistent_events.includes(2))
- ui.events[2].style.display = "block"
+ if (view.persistent_events.includes(C_SOLIDARITY_LEGALIZED))
+ ui.events[C_SOLIDARITY_LEGALIZED].style.display = "block"
else
- ui.events[2].style.display = "none"
+ ui.events[C_SOLIDARITY_LEGALIZED].style.display = "none"
- if (view.persistent_events.includes(9))
- ui.events[9].style.display = "block"
+ if (view.persistent_events.includes(C_THE_WALL))
+ ui.events[C_THE_WALL].style.display = "block"
else
- ui.events[9].style.display = "none"
+ ui.events[C_THE_WALL].style.display = "none"
if (view.persistent_events.includes(69)) {
- ui.events[69].style.display = "block"
- ui.events[69].style.left = ui.layout_xy[view.systematization][0] - 25 + "px"
- ui.events[69].style.top = ui.layout_xy[view.systematization][1] - 25 + "px"
+ ui.events[C_SYSTEMATIZATION].style.display = "block"
+ ui.events[C_SYSTEMATIZATION].style.left = ui.layout_xy[view.systematization][0] - 25 + "px"
+ ui.events[C_SYSTEMATIZATION].style.top = ui.layout_xy[view.systematization][1] - 25 + "px"
} else {
- ui.events[69].style.display = "none"
+ ui.events[C_SYSTEMATIZATION].style.display = "none"
}
- if (view.persistent_events.includes(97)) {
- ui.events[97].style.display = "block"
- ui.events[97].style.left = ui.layout_xy[view.the_tyrant_is_gone][0] - 25 + "px"
- ui.events[97].style.top = ui.layout_xy[view.the_tyrant_is_gone][1] - 25 + "px"
+ if (view.persistent_events.includes(C_THE_TYRANT_IS_GONE)) {
+ ui.events[C_THE_TYRANT_IS_GONE].style.display = "block"
+ ui.events[C_THE_TYRANT_IS_GONE].style.left = ui.layout_xy[view.the_tyrant_is_gone][0] - 25 + "px"
+ ui.events[C_THE_TYRANT_IS_GONE].style.top = ui.layout_xy[view.the_tyrant_is_gone][1] - 25 + "px"
} else {
- ui.events[97].style.display = "none"
+ ui.events[C_THE_TYRANT_IS_GONE].style.display = "none"
}
// EVENT REMINDER LIST
@@ -775,22 +740,22 @@ function on_update() {
// =========================== LOG FUNCTIONS ==============================================
-function sub_card_name(match, p1) {
+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}</span>`
}
-function sub_power_card_name(match, p1) {
+function sub_power_card_name(_match, p1) {
let x = p1 | 0
return `<span class="card_name" onmouseenter="on_focus_power_card_tip(${x})" onmouseleave="on_blur_power_card_tip()">${power_cards[x].name}</span>`
}
-function sub_power_card_value(match, p1) {
+function sub_power_card_value(_match, p1) {
let x = p1 | 0
return `<span class="card_name">${x}</span>`
}
-function sub_space_name(match, p1) {
+function sub_space_name(_match, p1) {
let id = p1 | 0
let name = spaces[id].name_unique
return `<span class="space_tip" onmouseenter="on_focus_space_tip(${id})" onmouseleave="on_blur_space_tip(${id})" onclick="on_click_space_tip(${id})">${name}</span>`
@@ -809,6 +774,42 @@ const die = {
D6: '<span class="die white d6"></span>',
}
+function on_log(text) {
+ let p = document.createElement("div")
+
+ 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)
+ text = text.replace(/V(\d+)/g, sub_power_card_value)
+ text = text.replace(/%(\d+)/g, sub_space_name)
+ text = text.replace(/D[1-6]/g, sub_die)
+
+ if (text.match(/^\.h1/)) {
+ text = text.substring(4)
+ p.className = "h1"
+ } else if (text.match(/^\.h2d/)) {
+ text = text.substring(5)
+ p.className = "h2 dem"
+ } else if (text.match(/^\.h2c/)) {
+ text = text.substring(5)
+ p.className = "h2 com"
+ } else if (text.match(/^\.h2/)) {
+ text = text.substring(4)
+ p.className = "h2"
+ } else if (text.match(/^\.h3/)) {
+ text = text.substring(4)
+ p.className = "h3"
+ }
+
+ p.innerHTML = text
+ return p
+}
+
// =========================== VISUAL FUNCTIONS ==========================================#
function on_focus_card_tip(card_number) {
@@ -846,7 +847,3 @@ function toggle_discard() {
function toggle_removed() {
document.getElementById("removed_panel").classList.toggle("hide")
}
-
-function find_country_index(country) {
- return countries.indexOf(country)
-}