From bc45178718380809be800611c39b1fa64da8ffb5 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 4 Sep 2022 14:47:35 +0200 Subject: Keep battle blocks sorted. --- play.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'play.js') 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) -- cgit v1.2.3