summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-09-04 14:47:35 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-17 13:11:27 +0100
commitbc45178718380809be800611c39b1fa64da8ffb5 (patch)
treea2b4d96e7cb9b9f7ea49b1caa6f94c25f4e04291 /play.js
parent6d25e8e0f4e5b4c9e831350856aaf1ea6a61a18c (diff)
downloadrommel-in-the-desert-bc45178718380809be800611c39b1fa64da8ffb5.tar.gz
Keep battle blocks sorted.
Diffstat (limited to 'play.js')
-rw-r--r--play.js13
1 files changed, 12 insertions, 1 deletions
diff --git a/play.js b/play.js
index eceafdd..18dc97c 100644
--- a/play.js
+++ b/play.js
@@ -857,12 +857,23 @@ function update_cards() {
}
}
+function insert_battle_block(root, node, unit) {
+ for (let i = 0; i < root.children.length; ++i) {
+ let prev = root.children[i]
+ if (prev.unit > unit) {
+ root.insertBefore(node, prev)
+ return
+ }
+ }
+ root.appendChild(node)
+}
+
function update_battle_line(hex, line, test) {
for (let u = 0; u < unit_count; ++u) {
let e = ui.battle_units[u]
if (unit_hex(u) === hex && test(u)) {
if (!line.contains(e))
- line.appendChild(e)
+ insert_battle_block(line, e, u)
let r = unit_lost_steps(u)
e.classList.toggle("r0", r === 0)