diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 84 |
1 files changed, 52 insertions, 32 deletions
@@ -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) { |