diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 49 |
1 files changed, 48 insertions, 1 deletions
@@ -6,6 +6,26 @@ const svgNS = "http://www.w3.org/2000/svg" const round = Math.round const sqrt = Math.sqrt +function set_index(set, item) { + let a = 0 + let b = set.length - 1 + while (a <= b) { + let m = (a + b) >> 1 + let x = set[m] + if (item < x) + b = m - 1 + else if (item > x) + a = m + 1 + else + return m + } + return -1 +} + +function set_has(set, item) { + return set_index(set, item) >= 0 +} + let ui = { hexes: [], sides: [], @@ -52,6 +72,22 @@ 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) +} + +function is_hex_allied_controlled(hex) { + return set_has(view.allied_hexes, hex) +} + +function is_side_axis_controlled(side) { + return set_has(view.axis_sides, side) +} + +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 } @@ -236,7 +272,7 @@ function build_hexes() { for (let month = 1; month <= 20; ++month) { ui.hex_y[map_w * map_h + month] = 24 + 37 - ui.hex_x[map_w * map_h + month] = 1000 + 37 + (month-1) * 81 + ui.hex_x[map_w * map_h + month] = 1840 + 37 + (month-1) * 81 } document.getElementById("mapsvg").getElementById("grid").setAttribute("d", path.join(" ")) @@ -315,9 +351,16 @@ function update_map() { e.classList.toggle("action", is_unit_action(u)) e.classList.toggle("selected", is_unit_selected(u)) + e.classList.toggle("disrupted", is_unit_disrupted(u)) + e.classList.toggle("moved", is_unit_moved(u)) + // e.classList.toggle("unsupplied", !is_unit_supplied(u)) } if (ui.hexes[hex]) { ui.hexes[hex].classList.toggle("action", is_hex_action(hex)) + ui.hexes[hex].classList.toggle("from", hex === view.from1 || hex === view.from2) + ui.hexes[hex].classList.toggle("to", hex === view.to1 || hex === view.to2) + ui.hexes[hex].classList.toggle("axis_control", is_hex_axis_controlled(hex)) + ui.hexes[hex].classList.toggle("allied_control", is_hex_allied_controlled(hex)) if (view.axis_supply) { ui.hexes[hex].classList.toggle("axis_supply", is_hex_axis_supply(hex)) for (let s = 0; s < 3; ++s) @@ -328,6 +371,10 @@ function update_map() { for (let s = 0; s < 3; ++s) ui.sides[hex*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(hex*3+s)) } + for (let s = 0; s < 3; ++s) { + ui.sides[hex*3+s].classList.toggle("axis_control", is_side_axis_controlled(hex*3+s)) + ui.sides[hex*3+s].classList.toggle("allied_control", is_side_allied_controlled(hex*3+s)) + } } } } |