diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -184,6 +184,10 @@ function is_unit_action(unit) { return !!(view.actions && view.actions.unit && view.actions.unit.includes(unit)) } +function is_unit_hit_action(unit) { + return !!(view.actions && view.actions.unit_hit && view.actions.unit_hit.includes(unit)) +} + function is_unit_selected(unit) { if (Array.isArray(view.selected)) return view.selected.includes(unit) @@ -288,6 +292,7 @@ function on_click_unit(evt) { function on_click_battle_unit(evt) { if (evt.button === 0) { send_action('unit', evt.target.unit) + send_action('unit_hit', evt.target.unit) } } @@ -740,7 +745,8 @@ function update_battle_line(hex, line, test) { e.classList.toggle("r2", r === 2) e.classList.toggle("r3", r === 3) - e.classList.toggle("action", is_unit_action(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)) @@ -768,12 +774,13 @@ function update_battle() { update_battle_line(view.battle, ui.battle_line_3, u => is_axis_unit(u) && !is_artillery_unit(u)) update_battle_line(view.battle, ui.battle_line_4, u => is_axis_unit(u) && is_artillery_unit(u)) } - target_button("armor") - target_button("infantry") - target_button("antitank") - target_button("artillery") for (let i = 0; i < 4; ++i) ui.battle_hits[i].textContent = view.hits[i] + battle_button("battle_armor_button", "armor") + battle_button("battle_infantry_button", "infantry") + battle_button("battle_antitank_button", "antitank") + battle_button("battle_artillery_button", "artillery") + battle_button("battle_end_hits_button", "end_hits") } function update_pursuit() { @@ -792,19 +799,16 @@ function update_pursuit() { ui.pursuit_hits.textContent = view.hits + " hit" else ui.pursuit_hits.textContent = view.hits + " hits" + battle_button("pursuit_end_hits_button", "end_hits") + battle_button("pursuit_end_fire_button", "end_fire") } -function target_button(action) { - let button = document.getElementById("target_" + action + "_button") - if (view.actions) { +function battle_button(id, action) { + let button = document.getElementById(id) + if (view.actions && view.actions[action]) button.classList.remove("hide") - if (view.actions[action]) - button.disabled = false - else - button.disabled = true - } else { + else button.classList.add("hide") - } } function on_update() { |