summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-12-05 20:55:49 +0100
committerTor Andersson <tor@ccxvii.net>2024-12-05 23:20:14 +0100
commit7a6bdfefcca400e40a7a1067bed52e983a17be65 (patch)
tree1777096dd6b798aa178cadd4305a77e3857e86aa /play.js
parent67d0bc93091c45dde6237cf19fc98d248e8f5638 (diff)
downloadrommel-in-the-desert-7a6bdfefcca400e40a7a1067bed52e983a17be65.tar.gz
Cycle supply line overlay between axis/allied/both/none.
Also update colors.
Diffstat (limited to 'play.js')
-rw-r--r--play.js84
1 files changed, 52 insertions, 32 deletions
diff --git a/play.js b/play.js
index c7fefdd..daae5d4 100644
--- a/play.js
+++ b/play.js
@@ -226,10 +226,6 @@ function is_hex_forced_march_action(hex) {
return !!(view.actions && view.actions.forced_march && view.actions.forced_march.includes(hex))
}
-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)
}
@@ -246,16 +242,20 @@ 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
+function is_hex_axis_supply(hex) {
+ return supply.axis_supply[hex] > 0
}
function is_hex_allied_supply(hex) {
- return view.allied_supply[hex] > 0
+ return supply.allied_supply[hex] > 0
+}
+
+function is_side_axis_supply_line(side) {
+ return supply.axis_supply_line[side] > 0
}
function is_side_allied_supply_line(side) {
- return view.allied_supply_line[side] > 0
+ return supply.allied_supply_line[side] > 0
}
function is_hex_selected(hex) {
@@ -423,43 +423,59 @@ function toggle_units() {
document.getElementById("units").classList.toggle("hide")
}
-let showing_supply = false
+let supply_show = 0
+let supply = null
function toggle_supply() {
- if (!showing_supply)
+ if (supply_show === 0)
+ supply_show = (player === AXIS) ? 1 : 2
+ else if (supply_show === 1)
+ supply_show = (player === AXIS) ? 2 : 3
+ else if (supply_show === 2)
+ supply_show = (player === AXIS) ? 3 : 1
+ else if (supply_show === 3)
+ supply_show = 0
+ if (!supply)
send_query('supply')
else
- hide_supply()
+ update_supply()
}
-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
+function hide_supply() {
+ supply_show = 0
+ update_supply()
+}
+
+function fetch_supply() {
+ if (supply) {
+ supply = null
+ send_query('supply')
+ }
+}
+
+function update_supply() {
for (let x of all_hexes) {
- ui.hexes[x].classList.toggle("axis_supply", is_hex_axis_supply(x))
- ui.hexes[x].classList.toggle("allied_supply", is_hex_allied_supply(x))
+ ui.hexes[x].classList.toggle("axis_supply", false)
+ ui.hexes[x].classList.toggle("allied_supply", false)
for (let s = 0; s < 3; ++s) {
if (ui.lines[x*3+s]) {
- ui.lines[x*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(x*3+s))
- ui.lines[x*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(x*3+s))
+ ui.lines[x*3+s].classList.toggle("axis_supply", false)
+ ui.lines[x*3+s].classList.toggle("allied_supply", false)
}
}
}
-}
-
-function hide_supply() {
- if (showing_supply) {
- showing_supply = false
+ if (supply) {
for (let x of all_hexes) {
- ui.hexes[x].classList.toggle("axis_supply", false)
- ui.hexes[x].classList.toggle("allied_supply", false)
+ if (supply_show & 1)
+ ui.hexes[x].classList.toggle("axis_supply", is_hex_axis_supply(x))
+ if (supply_show & 2)
+ ui.hexes[x].classList.toggle("allied_supply", is_hex_allied_supply(x))
for (let s = 0; s < 3; ++s) {
if (ui.lines[x*3+s]) {
- ui.lines[x*3+s].classList.toggle("axis_supply", false)
- ui.lines[x*3+s].classList.toggle("allied_supply", false)
+ if (supply_show & 1)
+ ui.lines[x*3+s].classList.toggle("axis_supply", is_side_axis_supply_line(x*3+s))
+ if (supply_show & 2)
+ ui.lines[x*3+s].classList.toggle("allied_supply", is_side_allied_supply_line(x*3+s))
}
}
}
@@ -1026,6 +1042,8 @@ function on_update() {
return setTimeout(on_update, 500)
}
+ fetch_supply()
+
update_map()
update_cards()
@@ -1102,8 +1120,10 @@ function on_update() {
}
function on_reply(q, params) {
- if (q === 'supply')
- show_supply(params)
+ if (q === 'supply') {
+ supply = params
+ update_supply()
+ }
}
function on_focus_hex_tip(x) {