From 7a6bdfefcca400e40a7a1067bed52e983a17be65 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 5 Dec 2024 20:55:49 +0100 Subject: Cycle supply line overlay between axis/allied/both/none. Also update colors. --- play.css | 28 ++------------------- play.html | 21 ++++++++++++++++ play.js | 84 +++++++++++++++++++++++++++++++++++++++------------------------ 3 files changed, 75 insertions(+), 58 deletions(-) diff --git a/play.css b/play.css index b6b6c52..80bb750 100644 --- a/play.css +++ b/play.css @@ -360,32 +360,8 @@ svg #lines line { stroke-linecap: round; } -svg .hex.axis_supply { - fill: forestgreen; - fill-opacity: 0.4; -} - -svg .hex.allied_supply { - fill: firebrick; - fill-opacity: 0.4; -} - -svg .hex.axis_supply.allied_supply { - fill: blue; - fill-opacity: 0.4; -} - -svg #lines line.axis_supply { - stroke: darkgreen; -} - -svg #lines line.allied_supply { - stroke: darkred; -} - -svg #lines line.axis_supply.allied_supply { - stroke: navy; -} +svg .hex.axis_supply { fill-opacity: 0.4; } +svg .hex.allied_supply { fill-opacity: 0.4; } /* UNITS */ diff --git a/play.html b/play.html index 1f0753f..20dfe9a 100644 --- a/play.html +++ b/play.html @@ -96,9 +96,30 @@ + + + + + + + + + + + + + + + diff --git a/play.js b/play.js index c7fefdd..daae5d4 100644 --- a/play.js +++ b/play.js @@ -226,10 +226,6 @@ function is_hex_forced_march_action(hex) { return !!(view.actions && view.actions.forced_march && view.actions.forced_march.includes(hex)) } -function is_hex_axis_supply(hex) { - return view.axis_supply[hex] > 0 -} - function is_hex_axis_controlled(hex) { return set_has(view.axis_hexes, hex) } @@ -246,16 +242,20 @@ function is_side_allied_controlled(side) { return set_has(view.allied_sides, side) } -function is_side_axis_supply_line(side) { - return view.axis_supply_line[side] > 0 +function is_hex_axis_supply(hex) { + return supply.axis_supply[hex] > 0 } function is_hex_allied_supply(hex) { - return view.allied_supply[hex] > 0 + return supply.allied_supply[hex] > 0 +} + +function is_side_axis_supply_line(side) { + return supply.axis_supply_line[side] > 0 } function is_side_allied_supply_line(side) { - return view.allied_supply_line[side] > 0 + return supply.allied_supply_line[side] > 0 } function is_hex_selected(hex) { @@ -423,43 +423,59 @@ function toggle_units() { document.getElementById("units").classList.toggle("hide") } -let showing_supply = false +let supply_show = 0 +let supply = null function toggle_supply() { - if (!showing_supply) + if (supply_show === 0) + supply_show = (player === AXIS) ? 1 : 2 + else if (supply_show === 1) + supply_show = (player === AXIS) ? 2 : 3 + else if (supply_show === 2) + supply_show = (player === AXIS) ? 3 : 1 + else if (supply_show === 3) + supply_show = 0 + if (!supply) send_query('supply') else - hide_supply() + update_supply() } -function show_supply(reply) { - showing_supply = true - view.axis_supply = reply.axis_supply - view.axis_supply_line = reply.axis_supply_line - view.allied_supply = reply.allied_supply - view.allied_supply_line = reply.allied_supply_line +function hide_supply() { + supply_show = 0 + update_supply() +} + +function fetch_supply() { + if (supply) { + supply = null + send_query('supply') + } +} + +function update_supply() { for (let x of all_hexes) { - ui.hexes[x].classList.toggle("axis_supply", is_hex_axis_supply(x)) - ui.hexes[x].classList.toggle("allied_supply", is_hex_allied_supply(x)) + ui.hexes[x].classList.toggle("axis_supply", false) + ui.hexes[x].classList.toggle("allied_supply", false) for (let s = 0; s < 3; ++s) { if (ui.lines[x*3+s]) { - ui.lines[x*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(x*3+s)) - ui.lines[x*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(x*3+s)) + ui.lines[x*3+s].classList.toggle("axis_supply", false) + ui.lines[x*3+s].classList.toggle("allied_supply", false) } } } -} - -function hide_supply() { - if (showing_supply) { - showing_supply = false + if (supply) { for (let x of all_hexes) { - ui.hexes[x].classList.toggle("axis_supply", false) - ui.hexes[x].classList.toggle("allied_supply", false) + if (supply_show & 1) + ui.hexes[x].classList.toggle("axis_supply", is_hex_axis_supply(x)) + if (supply_show & 2) + ui.hexes[x].classList.toggle("allied_supply", is_hex_allied_supply(x)) for (let s = 0; s < 3; ++s) { if (ui.lines[x*3+s]) { - ui.lines[x*3+s].classList.toggle("axis_supply", false) - ui.lines[x*3+s].classList.toggle("allied_supply", false) + if (supply_show & 1) + ui.lines[x*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(x*3+s)) + if (supply_show & 2) + ui.lines[x*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(x*3+s)) } } } @@ -1026,6 +1042,8 @@ function on_update() { return setTimeout(on_update, 500) } + fetch_supply() + update_map() update_cards() @@ -1102,8 +1120,10 @@ function on_update() { } function on_reply(q, params) { - if (q === 'supply') - show_supply(params) + if (q === 'supply') { + supply = params + update_supply() + } } function on_focus_hex_tip(x) { -- cgit v1.2.3