diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-09-04 14:47:35 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-17 13:11:27 +0100 |
commit | bc45178718380809be800611c39b1fa64da8ffb5 (patch) | |
tree | a2b4d96e7cb9b9f7ea49b1caa6f94c25f4e04291 | |
parent | 6d25e8e0f4e5b4c9e831350856aaf1ea6a61a18c (diff) | |
download | rommel-in-the-desert-bc45178718380809be800611c39b1fa64da8ffb5.tar.gz |
Keep battle blocks sorted.
-rw-r--r-- | play.js | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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) |