summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js132
1 files changed, 86 insertions, 46 deletions
diff --git a/play.js b/play.js
index daf430c..3d8235d 100644
--- a/play.js
+++ b/play.js
@@ -18,6 +18,10 @@ function toggle_pieces() {
}
}
+function toggle_shift() {
+ document.body.classList.toggle("shift")
+}
+
/* DATA */
const P_FRANCE = 0
@@ -108,12 +112,12 @@ const piece_name = [
"BatthyƔny",
"Neipperg",
"Arenberg",
- "supply train", "supply train",
- "supply train",
- "supply train", "supply train",
- "supply train",
- "supply train",
- "supply train", "supply train", "supply train",
+ "French ST", "French ST",
+ "Bavarian ST",
+ "Prussian ST", "Prussian ST",
+ "Saxon ST",
+ "Pragmatic Army ST",
+ "Austrian ST", "Austrian ST", "Austrian ST",
"hussars", "hussars",
]
@@ -160,7 +164,6 @@ function make_road(c1, c2, type) {
document.getElementById("roads").appendChild(e)
}
-
/* PANEL ORDER */
const panel_order = [ P_FRANCE, P_BAVARIA, P_PRUSSIA, P_SAXONY, P_PRAGMATIC, P_AUSTRIA, P_AUSTRIA+1 ]
@@ -234,6 +237,12 @@ const ui = {
pieces_element: document.getElementById("pieces"),
markers_element: document.getElementById("markers"),
political_display: document.getElementById("political_display"),
+ discard: [
+ document.getElementById("discard_1"),
+ document.getElementById("discard_2"),
+ document.getElementById("discard_3"),
+ document.getElementById("discard_4"),
+ ],
power_panel_list: document.getElementById("power_panel_list"),
power_header: [
document.getElementById("hand_france_header"),
@@ -334,6 +343,16 @@ function make_tc_deck_back(n) {
return list
}
+function make_tc_deck_discard(n) {
+ let list = []
+ for (let i = 0; i < 10; ++i) {
+ let e = document.createElement("div")
+ e.className = "card tc pile reverse " + n
+ list.push(e)
+ }
+ return list
+}
+
function make_political_card(fc) {
let e = document.createElement("div")
if (fc === 0)
@@ -427,6 +446,13 @@ function on_init() {
make_tc_deck_back("deck_4"),
]
+ ui.tc_discard = [
+ make_tc_deck_discard("deck_1"),
+ make_tc_deck_discard("deck_2"),
+ make_tc_deck_discard("deck_3"),
+ make_tc_deck_discard("deck_4"),
+ ]
+
ui.combat = document.createElement("div")
ui.combat.id = "combat"
ui.combat.style.zIndex = 2000
@@ -552,7 +578,11 @@ function on_blur_city() {
}
function on_focus_piece(evt) {
- ui.status.textContent = piece_name[evt.target.my_id]
+ let p = evt.target.my_id
+ if (p < 20 && view.troops[p] > 0)
+ ui.status.textContent = piece_name[evt.target.my_id] + " (" + view.troops[p] + " troops)"
+ else
+ ui.status.textContent = piece_name[evt.target.my_id]
}
function on_blur_piece() {
@@ -609,16 +639,15 @@ function get_cylinder_power(id) {
}
function layout_general(id, s) {
- let e = ui.pieces[id]
let x, y, n
if (s === REMOVED) {
- if (e.parentElement === ui.pieces_element)
+ if (ui.pieces[id].parentElement === ui.pieces_element)
+ e.remove()
+ if (ui.troops[id].parentElement === ui.pieces_element)
e.remove()
return
}
- if (e.parentElement !== ui.pieces_element)
- ui.pieces_element.appendChild(e)
if (s === ELIMINATED) {
n = layout_general_offset_elim(id)
@@ -632,6 +661,9 @@ function layout_general(id, s) {
let selected = set_has(view.selected, id)
+ let e = ui.pieces[id]
+ if (e.parentElement !== ui.pieces_element)
+ ui.pieces_element.appendChild(e)
e.style.left = (x - 21) + "px"
e.style.top = (y - 29 - 15 * n) + "px"
e.style.zIndex = y + n
@@ -639,10 +671,9 @@ function layout_general(id, s) {
e.classList.toggle("oos", (view.oos & (1 <<id)) !== 0)
e = ui.troops[id]
- // e.style.left = (x + 21 + 1) + "px"
- // e.style.top = (y - 7 - 14 * n) + "px"
+ if (e.parentElement !== ui.pieces_element)
+ ui.pieces_element.appendChild(e)
e.style.left = (x - 7) + "px"
- // e.style.top = (y + 7 - 15 * n) + "px"
e.style.top = (y + 2 - 15 * n) + "px"
e.style.zIndex = y + n + 1
e.className = power_class[piece_power[id]] + " piece number n" + view.troops[id]
@@ -717,9 +748,10 @@ function create_conquest(style, s) {
function update_favicon() {
let favicon = document.querySelector('link[rel="icon"]')
switch (params.role) {
+ case "Louis XV": favicon.href = "favicon/louis.png"; break
case "Frederick": favicon.href = "favicon/fritz.png"; break
+ default:
case "Maria Theresa": favicon.href = "favicon/maria.png"; break
- case "Louis XV": favicon.href = "favicon/louis.png"; break
}
}
@@ -735,28 +767,29 @@ const colorize_H = '<span class="suit hearts">\u2665</span>'
const colorize_D = '<span class="suit diamonds">\u2666</span>'
const colorize_R = '$1<span class="suit reserve">R</span>'
-const suit_text = [
- '<span class="suit spades">\u2660</span>',
- '<span class="suit clubs">\u2663</span>',
- '<span class="suit hearts">\u2665</span>',
- '<span class="suit diamonds">\u2666</span>',
- '<span class="suit reserve">R</span>'
-]
+const colorize_1 = '<span class="value deck_1">$1</span>'
+const colorize_2 = '<span class="value deck_2">$1</span>'
+const colorize_3 = '<span class="value deck_3">$1</span>'
+const colorize_4 = '<span class="value deck_4">$1</span>'
function colorize(text) {
+ text = text.replace(/1\^(\d+)/g, colorize_1)
+ text = text.replace(/2\^(\d+)/g, colorize_2)
+ text = text.replace(/3\^(\d+)/g, colorize_3)
+ text = text.replace(/4\^(\d+)/g, colorize_4)
+ text = text.replace(/(\d+)R/g, colorize_R)
text = text.replaceAll("\u2660", colorize_S)
text = text.replaceAll("\u2663", colorize_C)
text = text.replaceAll("\u2665", colorize_H)
text = text.replaceAll("\u2666", colorize_D)
- text = text.replace(/(\d+)R/g, colorize_R)
return text
}
-function on_update() {
-// let text = colorize(view.prompt)
-// if (text !== view.prompt)
-// ui.prompt.innerHTML = text
+function on_prompt(text) {
+ return colorize(view.prompt)
+}
+function on_update() {
ui.header.classList.toggle("france", view.power === P_FRANCE)
ui.header.classList.toggle("bavaria", view.power === P_BAVARIA)
ui.header.classList.toggle("prussia", view.power === P_PRUSSIA)
@@ -791,6 +824,7 @@ function on_update() {
ui.hand[pow].replaceChildren()
view.hand[pow].sort(cmp_tc)
for (let c of view.hand[pow]) {
+ console.log("C", c, c&15)
if ((c & 15) === 0)
ui.hand[pow].appendChild(ui.tc_back[c>>7][back[c>>7]++])
else
@@ -816,6 +850,12 @@ function on_update() {
ui.political_display.appendChild(ui.fate[c])
*/
+ for (let deck = 0; deck < 4; ++deck) {
+ ui.discard[deck].replaceChildren()
+ for (let i = 0; i < view.discard[deck]; ++i)
+ ui.discard[deck].appendChild(ui.tc_discard[deck][i])
+ }
+
ui.markers_element.replaceChildren()
/*
for (let s of view.conquest)
@@ -833,7 +873,7 @@ function on_update() {
action_button_with_argument("value", v, v)
for (let p = 0; p < 20; ++p) {
- action_button_with_argument("detach", p, "Detach " + piece_abbr[p])
+ action_button_with_argument("unstack", p, "Unstack " + piece_abbr[p])
action_button_with_argument("promote", p, "Promote " + piece_abbr[p])
action_button_with_argument("demote", p, "Demote " + piece_abbr[p])
}
@@ -879,8 +919,13 @@ function sub_space(match, p1) {
return `<span class="city_tip" onclick="on_click_city_tip(${x})" onmouseenter="on_focus_city_tip(${x})" onmouseleave="on_blur_city_tip(${x})">${n}</span>`
}
-function sub_tc(match, p1) {
- return value + suit_text[suit]
+function sub_path(pieces_and_spaces) {
+ let ps = pieces_and_spaces[0].split(",")
+ let ss = pieces_and_spaces[1].split(",")
+ let x = ss[ss.length-1]
+ let ps_name = ps.map(p => piece_name[p]).join(" and ")
+ let ss_name = data.cities.name[x]
+ return `<span onclick="on_click_city_tip(${x})" onmouseenter="on_focus_path_tip([${ps.join(",")}],[${ss.join(",")}])" onmouseleave="on_blur_path_tip()">${ps_name} to ${ss_name}.</span>`
}
function on_log(text) {
@@ -905,29 +950,24 @@ function on_log(text) {
text = text.replace(/</g, "&lt;")
text = text.replace(/>/g, "&gt;")
+ text = text.replaceAll(" 1 troops", " 1 troop")
+
+ text = colorize(text)
text = text.replace(/S(\d+)/g, sub_space)
text = text.replace(/P(\d+)/g, sub_piece)
- text = colorize(text)
- if (text.match(/^\$(\d+)/)) {
- let fx = parseInt(text.substring(1))
- if (fx < 48 + 6)
- text = `<div class="q">${fate_flavor_text[fx]}</div><div></div><div>${fate_effect_text[fx]}</div><div></div>`
- else
- text = `<div class="q">${fate_flavor_text[fx]}</div><div></div>`
- }
- else if (text.match(/^# /)) {
- p.className = "h fate"
+ if (text.startsWith("#")) {
+ p.className = "h turn"
text = text.substring(2)
}
- else if (text.match(/^\.s1/))
- text = the_war_in_the_west_text
- else if (text.match(/^\.s2/))
- text = the_austrian_theater_text
- else if (text.match(/^=\d/)) {
+ else if (text.startsWith("=")) {
p.className = "h " + power_class[text[1]]
text = power_name[text[1]]
}
+ else if (text.startsWith("@")) {
+ p.className = "move_tip"
+ text = sub_path(text.substring(1).split(";"))
+ }
p.innerHTML = text
return p