summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js86
1 files changed, 71 insertions, 15 deletions
diff --git a/play.js b/play.js
index e012337..f34d5f6 100644
--- a/play.js
+++ b/play.js
@@ -59,6 +59,7 @@ const F_EMPEROR_AUSTRIA = 2
const F_ITALY_FRANCE = 4
const F_ITALY_AUSTRIA = 8
const F_SILESIA_ANNEXED = 16
+const F_IMPERIAL_ELECTION = 32
const SPADES = 0
const CLUBS = 1
@@ -71,6 +72,7 @@ const IMPERIAL_ELECTION = 25
const ELIMINATED = data.cities.name.length
const all_powers = [ 0, 1, 2, 3, 4, 5 ]
+const all_major_powers = [ 0, 1, 2, 3 ]
const all_power_generals = [
[ 0, 1, 2, 3, 4 ],
@@ -358,7 +360,15 @@ const ui = {
spaces_element: document.getElementById("spaces"),
pieces_element: document.getElementById("pieces"),
markers_element: document.getElementById("markers"),
- political_display: document.getElementById("political_display"),
+ pol_tracks: document.getElementById("pol_tracks"),
+ pc_deck: document.getElementById("pc_deck"),
+ pc_show: document.getElementById("pc_show"),
+ pc_display: [
+ document.getElementById("display_france"),
+ document.getElementById("display_prussia"),
+ document.getElementById("display_pragmatic"),
+ document.getElementById("display_austria"),
+ ],
discard: [
document.getElementById("discard_1"),
document.getElementById("discard_2"),
@@ -486,12 +496,18 @@ function make_tc_deck_hand(n) {
return list
}
-function make_political_card(fc) {
+function make_political_card(pc) {
let e = document.createElement("div")
- if (fc === 0)
- e.className = "card political reverse"
+ if (pc === 0)
+ e.className = "card polcard reverse"
else
- e.className = "card political c" + fc
+ e.className = "card polcard c" + pc
+ return e
+}
+
+function make_political_back(deck) {
+ let e = document.createElement("div")
+ e.className = "pile card polcard reverse deck_" + deck
return e
}
@@ -612,8 +628,16 @@ function on_init() {
ui.italy.className = "marker political_marker_italy"
ui.political = []
- for (let fc = 0; fc <= 18; ++fc)
- ui.political[fc] = make_political_card(fc)
+ for (let pc = 1; pc <= 25; ++pc)
+ ui.political[pc] = make_political_card(pc)
+
+ ui.political_back = [
+ [],
+ [ make_political_back(4), make_political_back(3), make_political_back(2), make_political_back(1) ],
+ [ make_political_back(4), make_political_back(3), make_political_back(2) ],
+ [ make_political_back(4), make_political_back(3) ],
+ [ make_political_back(4) ],
+ ]
for (let a = 0; a <= last_city; ++a) {
let e = (ui.cities[a] = document.createElement("div"))
@@ -908,7 +932,7 @@ function layout_political_marker(e, col, row) {
let y = 72 + row * 86 + 16
e.style.left = (x - 16) + "px"
e.style.top = (y - 16) + "px"
- ui.political_display.appendChild(e)
+ ui.pol_tracks.appendChild(e)
}
function layout_retro(s, pow) {
@@ -997,6 +1021,14 @@ function on_prompt(text) {
return colorize(text)
}
+let back = [ 0, 0, 0, 0 ]
+
+function show_tc(c) {
+ if ((c & 15) === 0)
+ return ui.tc_back[c>>7][back[c>>7]++]
+ return ui.tc[c]
+}
+
function on_update() {
ui.header.classList.toggle("france", view.power === P_FRANCE)
ui.header.classList.toggle("bavaria", view.power === P_BAVARIA)
@@ -1009,6 +1041,8 @@ function on_update() {
used_elector.fill(0)
used_retro.fill(0)
+ back.fill(0)
+
sort_power_panel(true)
for (let p = 0; p < 20; ++p)
@@ -1018,8 +1052,6 @@ function on_update() {
for (let p = 30; p < 32; ++p)
layout_hussar(p, view.pos[p])
- let back = [ 0, 0, 0, 0 ]
-
for (let pow of all_powers) {
/*
let banner = `${power_name[pow]} \u2014 ${view.pt[pow]} troops`
@@ -1040,10 +1072,7 @@ function on_update() {
} else {
view.hand[pow].sort(cmp_tc)
for (let c of view.hand[pow]) {
- if ((c & 15) === 0)
- ui.hand[pow].appendChild(ui.tc_back[c>>7][back[c>>7]++])
- else
- ui.hand[pow].appendChild(ui.tc[c])
+ ui.hand[pow].appendChild(show_tc(c))
}
}
}
@@ -1056,11 +1085,31 @@ function on_update() {
ui.hand[view.power].appendChild(ui.tc[c])
}
- ui.political_display.replaceChildren()
+ ui.pol_tracks.replaceChildren()
layout_political_marker(ui.saxony, view.saxony, 0)
layout_political_marker(ui.russia, view.russia, 1)
layout_political_marker(ui.italy, view.italy, 2)
+ ui.pc_deck.replaceChildren()
+ for (let e of ui.political_back[view.pol_deck])
+ ui.pc_deck.appendChild(e)
+ if (view.flags & F_IMPERIAL_ELECTION)
+ ui.pc_deck.appendChild(ui.political[25])
+
+ for (let pow of all_major_powers) {
+ ui.pc_display[pow].replaceChildren()
+ for (let tc of view.saved[pow])
+ ui.pc_display[pow].appendChild(show_tc(tc))
+ if (view.display[pow] >= 0)
+ ui.pc_display[pow].appendChild(show_tc(view.display[pow]))
+ }
+
+ ui.pc_show.replaceChildren()
+ if (view.political) {
+ for (let pc of view.political)
+ ui.pc_show.appendChild(ui.political[pc])
+ }
+
for (let deck = 0; deck < 4; ++deck) {
ui.discard[deck].replaceChildren()
for (let i = 0; i < view.discard[deck]; ++i)
@@ -1164,6 +1213,12 @@ function on_update() {
/* LOG */
+function sub_political(match, p1) {
+ let x = p1 | 0
+ let n = political_name[x]
+ return `<span class="political_tip ${p}" onmouseenter="on_focus_political_tip(${x})" onmouseleave="on_blur_political_tip(${x})">${n}</span>`
+}
+
function sub_piece(match, p1) {
let x = p1 | 0
let n = piece_log_name[x]
@@ -1213,6 +1268,7 @@ function on_log(text) {
text = colorize(text)
text = text.replace(/S(\d+)/g, sub_space)
text = text.replace(/P(\d+)/g, sub_piece)
+ text = text.replace(/C(\d+)/g, sub_political)
if (text.startsWith("#")) {
p.className = "h turn"