summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js64
1 files changed, 31 insertions, 33 deletions
diff --git a/play.js b/play.js
index ddb552c..64cdc30 100644
--- a/play.js
+++ b/play.js
@@ -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)