summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js56
1 files changed, 43 insertions, 13 deletions
diff --git a/play.js b/play.js
index d495750..5c9601e 100644
--- a/play.js
+++ b/play.js
@@ -152,7 +152,7 @@ function is_unit_action(unit) {
}
function is_unit_selected(unit) {
- return !!(view.selected && view.selected.includes(unit))
+ return view.selected === unit
}
function is_artillery_unit(u) {
@@ -227,16 +227,18 @@ function on_blur(evt) {
function on_click_hex(evt) {
if (evt.button === 0) {
- send_action('hex', evt.target.hex)
+ hide_supply()
+ if (send_action('hex', evt.target.hex))
+ evt.stopPropagation()
}
}
function on_click_unit(evt) {
if (evt.button === 0) {
+ hide_supply()
evt.stopPropagation()
if (focus_stack(evt.target.stack))
send_action('unit', evt.target.unit)
- return true
}
}
@@ -248,6 +250,7 @@ function on_click_battle_unit(evt) {
document.getElementById("map").addEventListener("mousedown", function (evt) {
if (evt.button === 0) {
+ hide_supply()
blur_stack()
}
})
@@ -277,6 +280,38 @@ function toggle_units() {
document.getElementById("units").classList.toggle("hide")
}
+let showing_supply = false
+
+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
+ for (let x of all_hexes) {
+ ui.hexes[x].classList.toggle("axis_supply", is_hex_axis_supply(x))
+ for (let s = 0; s < 3; ++s)
+ ui.sides[x*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(x*3+s))
+ ui.hexes[x].classList.toggle("allied_supply", is_hex_allied_supply(x))
+ for (let s = 0; s < 3; ++s)
+ ui.sides[x*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(x*3+s))
+ }
+}
+
+function hide_supply() {
+ if (showing_supply) {
+ showing_supply = false
+ for (let x of all_hexes) {
+ ui.hexes[x].classList.toggle("axis_supply", false)
+ ui.hexes[x].classList.toggle("allied_supply", false)
+ for (let s = 0; s < 3; ++s) {
+ ui.sides[x*3+s].classList.toggle("axis_supply", false)
+ ui.sides[x*3+s].classList.toggle("allied_supply", false)
+ }
+ }
+ }
+}
+
const CLEAR = 2
const PASS = 1
const ROUGH = 0
@@ -487,16 +522,6 @@ function update_map() {
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)
- ui.sides[hex*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(hex*3+s))
- }
- if (view.allied_supply) {
- ui.hexes[hex].classList.toggle("allied_supply", is_hex_allied_supply(hex))
- 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))
@@ -623,6 +648,11 @@ function on_update() {
action_button("undo", "Undo")
}
+function on_reply(q, params) {
+ if (q === 'supply')
+ show_supply(params)
+}
+
function on_focus_hex_tip(x) {
ui.hexes[x].classList.add("tip")
}