From ae23306223d129ce2d6685926b89e7e721ea87d8 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sat, 1 Jun 2024 23:58:08 +0200 Subject: show who controls which power in player list --- images/hanover.png | Bin 0 -> 693 bytes play.css | 45 +++++++++++++++++------ play.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 images/hanover.png diff --git a/images/hanover.png b/images/hanover.png new file mode 100644 index 0000000..d81fd21 Binary files /dev/null and b/images/hanover.png differ diff --git a/play.css b/play.css index 40d03ef..98236ee 100644 --- a/play.css +++ b/play.css @@ -71,6 +71,8 @@ #role_Maria_Theresa { background-color: var(--color-role-austria) } #role_Pompadour { background-color: var(--color-role-france) } +.role.active span { text-decoration: dotted underline; } + #prompt { font-family: "Suit Symbols", var(--font-widget); font-variant-numeric: tabular-nums; @@ -227,18 +229,37 @@ span.suit.reserve { color: var(--color-reserve); font-weight: bold; font-family: border: 1px solid black; } -.marker.conquest.austria { background-image: url(images/conquest_austria.2x.png) } -.marker.conquest.france { background-image: url(images/conquest_france.2x.png) } -.marker.conquest.imperial { background-image: url(images/conquest_imperial.2x.png) } -.marker.conquest.prussia { background-image: url(images/conquest_prussia.2x.png) } -.marker.conquest.russia { background-image: url(images/conquest_russia.2x.png) } -.marker.conquest.sweden { background-image: url(images/conquest_sweden.2x.png) } -.marker.retroactive.austria { background-image: url(images/retroactive_austria.2x.png) } -.marker.retroactive.france { background-image: url(images/retroactive_france.2x.png) } -.marker.retroactive.imperial { background-image: url(images/retroactive_imperial.2x.png) } -.marker.retroactive.prussia { background-image: url(images/retroactive_prussia.2x.png) } -.marker.retroactive.russia { background-image: url(images/retroactive_russia.2x.png) } -.marker.retroactive.sweden { background-image: url(images/retroactive_sweden.2x.png) } +.role_stat { + display: flex; + flex-wrap: wrap; + align-items: start; + gap: 4px; + padding-right: 3px; +} + +.role_marker { + display: inline-block; + width: 30px; + height: 22px; + background-size: 30px 30px; + background-position: center; + border: 1px solid black; +} + +.conquest.hanover { background-image: url(images/hanover.png) } + +.conquest.austria { background-image: url(images/conquest_austria.2x.png) } +.conquest.france { background-image: url(images/conquest_france.2x.png) } +.conquest.imperial { background-image: url(images/conquest_imperial.2x.png) } +.conquest.prussia { background-image: url(images/conquest_prussia.2x.png) } +.conquest.russia { background-image: url(images/conquest_russia.2x.png) } +.conquest.sweden { background-image: url(images/conquest_sweden.2x.png) } +.retroactive.austria { background-image: url(images/retroactive_austria.2x.png) } +.retroactive.france { background-image: url(images/retroactive_france.2x.png) } +.retroactive.imperial { background-image: url(images/retroactive_imperial.2x.png) } +.retroactive.prussia { background-image: url(images/retroactive_prussia.2x.png) } +.retroactive.russia { background-image: url(images/retroactive_russia.2x.png) } +.retroactive.sweden { background-image: url(images/retroactive_sweden.2x.png) } .marker.turn { background-image: url(images/turn.2x.png) } diff --git a/play.js b/play.js index 22fead5..4088a83 100644 --- a/play.js +++ b/play.js @@ -20,6 +20,11 @@ function toggle_pieces() { /* DATA */ +const R_FREDERICK = "Frederick" +const R_ELISABETH = "Elisabeth" +const R_MARIA_THERESA = "Maria Theresa" +const R_POMPADOUR = "Pompadour" + const P_PRUSSIA = 0 const P_HANOVER = 1 const P_RUSSIA = 2 @@ -70,8 +75,23 @@ for (let s of data.type.objective1_imperial) set_add(objective1[P_IMPERIAL], s) for (let s of data.type.objective2_imperial) set_add(objective2[P_IMPERIAL], s) for (let s of data.type.objective_france) set_add(objective1[P_FRANCE], s) +function make_badge(power) { + let e = document.createElement("div") + e.className = "role_marker conquest " + power + return e +} + const power_class = [ "prussia", "hanover", "russia", "sweden", "austria", "imperial", "france", "imaginary" ] const power_name = [ "Prussia", "Hanover", "Russia", "Sweden", "Austria", "Imperial Army", "France", "Imaginary Player" ] +const power_badge = [ + make_badge("prussia"), + make_badge("hanover"), + make_badge("russia"), + make_badge("sweden"), + make_badge("austria"), + make_badge("imperial"), + make_badge("france"), +] const GENERAL_POWER = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6 ] @@ -139,6 +159,19 @@ function has_imperial_army_switched_players() { return (has_russia_dropped_out() && has_sweden_dropped_out()) || has_france_dropped_out() } +function has_power_dropped_out(pow) { + if (is_war_in_the_west()) + return pow !== P_PRUSSIA && pow !== P_HANOVER && pow !== P_FRANCE + if (is_austrian_theatre()) + return pow !== P_PRUSSIA && pow !== P_AUSTRIA && pow !== P_IMPERIAL + switch (pow) { + case P_RUSSIA: return has_russia_dropped_out() + case P_SWEDEN: return has_sweden_dropped_out() + case P_FRANCE: return has_france_dropped_out() + } + return false +} + function has_eased_victory(power) { if (power === P_SWEDEN) return has_russia_dropped_out() @@ -153,15 +186,23 @@ function is_war_in_the_west() { return !roles["Elisabeth"] && !roles["Maria Theresa"] } -function is_4p_scenario() { +function is_austrian_theatre() { + return !roles["Pompadour"] && !roles["Elisabeth"] +} + +function is_34p_scenario() { return !!roles["Frederick"] && !!roles["Elisabeth"] && !!roles["Maria Theresa"] } +function is_3p_scenario() { + return !!roles["Frederick"] && !!roles["Elisabeth"] && !!roles["Maria Theresa"] && !roles["Pompadour"] +} + function count_total_objectives(pow) { let n = objective1[pow].length if (!has_eased_victory(pow)) n += objective2[pow].length - if (pow === P_PRUSSIA && is_4p_scenario()) { + if (pow === P_PRUSSIA && is_34p_scenario()) { if (view.oo === 0) n = 0 if (view.oo < 0 && set_has(view.fate, FC_POEMS) && set_has(view.fate, FC_LORD_BUTE)) @@ -894,6 +935,56 @@ function colorize(text) { return text } +function player_from_power(pow) { + let role = null + + if (is_austrian_theatre() && pow === P_IMPERIAL) + return R_MARIA_THERESA + + switch (pow) { + case P_PRUSSIA: + case P_HANOVER: + role = R_FREDERICK + break + case P_RUSSIA: + case P_SWEDEN: + role = R_ELISABETH + break + case P_AUSTRIA: + role = R_MARIA_THERESA + break + case P_IMPERIAL: + if (has_russia_dropped_out() && has_sweden_dropped_out()) + role = R_ELISABETH + else if (has_france_dropped_out()) + role = R_POMPADOUR + else + role = R_MARIA_THERESA + break + case P_FRANCE: + role = R_POMPADOUR + break + } + + if (is_3p_scenario() && role === R_POMPADOUR) + role = R_ELISABETH + return role +} + +function update_player_power_list(role, powers) { + if (roles[role]) { + roles[role].stat.replaceChildren() + for (let pow of all_powers) + if (!has_power_dropped_out(pow) && player_from_power(pow) === role && power_badge[pow]) + roles[role].stat.appendChild(power_badge[pow]) + } +} + +function update_player_active(name) { + if (roles[name]) + roles[name].element.classList.toggle("active", player_from_power(view.power) === name) +} + function on_update() { let text = colorize(view.prompt) if (text !== view.prompt) @@ -907,6 +998,16 @@ function on_update() { ui.header.classList.toggle("imperial", view.power === P_IMPERIAL) ui.header.classList.toggle("france", view.power === P_FRANCE) + update_player_power_list("Frederick") + update_player_power_list("Elisabeth") + update_player_power_list("Maria Theresa") + update_player_power_list("Pompadour") + + update_player_active("Frederick") + update_player_active("Elisabeth") + update_player_active("Maria Theresa") + update_player_active("Pompadour") + sort_power_panel(true) for (let g = 0; g <= 23; ++g) -- cgit v1.2.3