diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-09-05 19:02:29 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:27 +0100 |
commit | bcfb60a802e8297b984b3519c8fe70efa5129b89 (patch) | |
tree | d126c9d5076303adbe89ce6587f0fd58220e2b87 /play.js | |
parent | 4b8e84d1173502ff82d30d49c02adafe2b0b6b27 (diff) | |
download | rommel-in-the-desert-bcfb60a802e8297b984b3519c8fe70efa5129b89.tar.gz |
Add badges for disrupted/unsupplied enemy units.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 64 |
1 files changed, 31 insertions, 33 deletions
@@ -242,9 +242,11 @@ function is_side_allied_supply_line(side) { } function is_hex_selected(hex) { - if (hex === view.pursuit || hex === view.battle) + if (hex === view.pursuit || hex === view.battle || hex === view.selected_hexes) return true - return hex === view.selected_hexes || set_has(view.selected_hexes, hex) + if (Array.isArray(view.selected_hexes) && view.selected_hexes.includes(hex)) + return true + return false } function is_setup_hex(hex) { @@ -645,6 +647,29 @@ function build_cards() { build_units() build_cards() +function update_unit(e, u) { + if (is_unit_revealed(u)) { + let r = unit_lost_steps(u) + e.classList.toggle("r0", r === 0) + e.classList.toggle("r1", r === 1) + e.classList.toggle("r2", r === 2) + e.classList.toggle("r3", r === 3) + e.classList.toggle("revealed", true) + if (is_italian_unit(u)) + e.classList.toggle("italian", true) + } else { + e.classList.toggle("r0", false) + e.classList.toggle("r1", false) + e.classList.toggle("r2", false) + e.classList.toggle("r3", false) + e.classList.toggle("revealed", false) + if (is_italian_unit(u)) + e.classList.toggle("italian", false) + } + e.classList.toggle("disrupted", is_unit_disrupted(u)) + e.classList.toggle("unsupplied", is_unit_unsupplied(u)) +} + let stack_list = new Array(map_w * map_h + 21) for (let i = 0; i < stack_list.length; ++i) stack_list[i] = [[],[]] @@ -693,30 +718,11 @@ function layout_stack(stack, hex, start_x, start_y, wrap, xdir) { e.style.left = x + "px" e.style.zIndex = z - if (is_unit_revealed(u)) { - let r = unit_lost_steps(u) - e.classList.toggle("r0", r === 0) - e.classList.toggle("r1", r === 1) - e.classList.toggle("r2", r === 2) - e.classList.toggle("r3", r === 3) - e.classList.toggle("revealed", true) - if (is_italian_unit(u)) - e.classList.toggle("italian", true) - } else { - e.classList.toggle("r0", false) - e.classList.toggle("r1", false) - e.classList.toggle("r2", false) - e.classList.toggle("r3", false) - e.classList.toggle("revealed", false) - if (is_italian_unit(u)) - e.classList.toggle("italian", false) - } + update_unit(e, u) e.classList.toggle("action", !view.battle && is_unit_action(u)) e.classList.toggle("selected", !view.battle && 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_unsupplied(u)) } } @@ -838,8 +844,6 @@ function update_map() { if (ui.hexes[hex]) { ui.hexes[hex].classList.toggle("action", is_hex_action(hex) || is_hex_forced_march_action(hex)) ui.hexes[hex].classList.toggle("forced_march", is_hex_forced_march_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("selected", is_hex_selected(hex)) ui.hexes[hex].classList.toggle("axis_control", is_hex_axis_controlled(hex)) ui.hexes[hex].classList.toggle("allied_control", is_hex_allied_controlled(hex)) @@ -881,18 +885,12 @@ function update_battle_line(hex, line, test) { if (!line.contains(e)) insert_battle_block(line, e, u) - let r = unit_lost_steps(u) - e.classList.toggle("r0", r === 0) - e.classList.toggle("r1", r === 1) - e.classList.toggle("r2", r === 2) - e.classList.toggle("r3", r === 3) + update_unit(e, u) + e.classList.toggle("selected", is_unit_selected(u)) e.classList.toggle("action", is_unit_action(u) || is_unit_hit_action(u)) e.classList.toggle("hit", is_unit_hit_action(u)) - e.classList.toggle("selected", is_unit_selected(u)) - e.classList.toggle("disrupted", is_unit_disrupted(u)) - e.classList.toggle("moved", is_unit_fired(u)) - e.classList.toggle("revealed", is_unit_revealed(u)) + e.classList.toggle("fired", is_unit_fired(u)) } else { if (line.contains(e)) line.removeChild(e) |