From b9f53c30064066e39e18b35697a1e4be21472c15 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 6 Jun 2024 13:45:08 +0200 Subject: x --- play.js | 132 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 86 insertions(+), 46 deletions(-) (limited to 'play.js') 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 <\u2660', - '\u2663', - '\u2665', - '\u2666', - 'R' -] +const colorize_1 = '$1' +const colorize_2 = '$1' +const colorize_3 = '$1' +const colorize_4 = '$1' 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 `${n}` } -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 `${ps_name} to ${ss_name}.` } function on_log(text) { @@ -905,29 +950,24 @@ function on_log(text) { text = text.replace(//g, ">") + 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 = `
${fate_flavor_text[fx]}
${fate_effect_text[fx]}
` - else - text = `
${fate_flavor_text[fx]}
` - } - 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 -- cgit v1.2.3