From dd346772cb76d58c3334bba5738862e437d9105d Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 22 May 2022 22:19:27 +0200 Subject: New battle CSS. --- play.css | 10 +-------- play.html | 32 +++++++++-------------------- play.js | 69 +++++++++++++++++++++++++++++++++++++++------------------------ rules.js | 15 +++++--------- 4 files changed, 59 insertions(+), 67 deletions(-) diff --git a/play.css b/play.css index c060369..47f213c 100644 --- a/play.css +++ b/play.css @@ -109,15 +109,7 @@ header.your_turn { background-color: orange; } #battle { background-color: tan; } #battle_message { background-color: wheat; } #battle_header { background-color: brown; color: lemonchiffon; } -.battle_separator { background-color: brown; } - -body:not(.replay) .battle_line.enemy .battle_menu_list { min-height: 0; } -.battle_reserves .battle_menu_list { min-height: 0; } -.battle_reserves > td > div { height: 75px; padding: 5px; } -.battle_a_cell > div { min-width: 90px; padding: 5px 5px; } -.battle_b_cell > div { min-width: 270px; padding: 5px 5px; } -.battle_c_cell > div { min-width: 270px; padding: 5px 5px; } -.battle_d_cell > div { min-width: 90px; padding: 5px 5px; } +#FR, #ER { background-color: #bda27e; } /* MAP WITH BLOCKS AND SPACES */ diff --git a/play.html b/play.html index 848ac5a..c49f3ab 100644 --- a/play.html +++ b/play.html @@ -17,30 +17,17 @@ - - - - - - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
diff --git a/play.js b/play.js index 0c83319..3ce0f33 100644 --- a/play.js +++ b/play.js @@ -145,7 +145,7 @@ function on_focus_battle_block(evt) { let b = evt.target.block; let msg = block_name(b); if (!evt.target.classList.contains("known")) - document.getElementById("status").textContent = "Reserves"; + msg = "Reserves"; if (view.actions && view.actions.battle_fire && view.actions.battle_fire.includes(b)) msg = "Fire with " + msg; @@ -291,6 +291,7 @@ function build_map() { menu.classList.add("battle_menu"); menu.appendChild(element); menu.appendChild(action_list); + menu.block = b; ui.battle_menu[b] = menu; } @@ -530,8 +531,34 @@ function update_map() { } } +function compare_blocks(a, b, ballista) { + let aa = BLOCKS[a].initiative; + let bb = BLOCKS[b].initiative; + if (aa === 'X') aa = ballista; + if (bb === 'X') bb = ballista; + if (aa === bb) { + aa = BLOCKS[a].label; + bb = BLOCKS[b].label; + } + return (aa < bb) ? -1 : (aa > bb) ? 1 : 0; +} + +function sort_battle_row(root, ballista) { + let swapped; + let children = root.children; + do { + swapped = false; + for (let i = 1; i < children.length; ++i) { + if (compare_blocks(children[i-1].block, children[i].block, ballista) > 0) { + children[i].after(children[i-1]); + swapped = true; + } + } + } while (swapped); +} + function update_battle() { - function fill_cell(name, list, reserve) { + function fill_cell(name, list, reserve, ballista) { let cell = window[name]; ui.present.clear(); @@ -539,6 +566,9 @@ function update_battle() { for (let block of list) { ui.present.add(block); + if (!cell.contains(ui.battle_menu[block])) + cell.appendChild(ui.battle_menu[block]); + if (block === view.who) ui.battle_menu[block].classList.add("selected"); else @@ -577,38 +607,25 @@ function update_battle() { } for (let b in BLOCKS) { - if (ui.present.has(b)) { - if (!cell.contains(ui.battle_menu[b])) - cell.appendChild(ui.battle_menu[b]); - } else { + if (!ui.present.has(b)) { if (cell.contains(ui.battle_menu[b])) cell.removeChild(ui.battle_menu[b]); } } + + sort_battle_row(cell, ballista); } if (player === CAESAR) { - fill_cell("FR", view.battle.CR, true); - fill_cell("FA", view.battle.CA, false); - fill_cell("FB", view.battle.CB, false); - fill_cell("FC", view.battle.CC, false); - fill_cell("FD", view.battle.CD, false); - fill_cell("EA", view.battle.PA, false); - fill_cell("EB", view.battle.PB, false); - fill_cell("EC", view.battle.PC, false); - fill_cell("ED", view.battle.PD, false); - fill_cell("ER", view.battle.PR, true); + fill_cell("FR", view.battle.CR, true, 'B'); + fill_cell("FF", view.battle.CF, false, view.battle.A === CAESAR ? 'D' : 'B'); + fill_cell("EF", view.battle.PF, false, view.battle.A === CAESAR ? 'B' : 'D'); + fill_cell("ER", view.battle.PR, true, 'B'); } else { - fill_cell("ER", view.battle.CR, true); - fill_cell("EA", view.battle.CA, false); - fill_cell("EB", view.battle.CB, false); - fill_cell("EC", view.battle.CC, false); - fill_cell("ED", view.battle.CD, false); - fill_cell("FA", view.battle.PA, false); - fill_cell("FB", view.battle.PB, false); - fill_cell("FC", view.battle.PC, false); - fill_cell("FD", view.battle.PD, false); - fill_cell("FR", view.battle.PR, true); + fill_cell("FR", view.battle.PR, true, 'B'); + fill_cell("FF", view.battle.PF, false, view.battle.A === POMPEIUS ? 'D' : 'B'); + fill_cell("EF", view.battle.CF, false, view.battle.A === POMPEIUS ? 'B' : 'D'); + fill_cell("ER", view.battle.CR, true, 'B'); } } diff --git a/rules.js b/rules.js index 1a841f6..af49e3f 100644 --- a/rules.js +++ b/rules.js @@ -2583,8 +2583,9 @@ exports.resign = function (state, current) { function make_battle_view() { let bv = { - CA: [], CB: [], CC: [], CD: [], CR: [], - PA: [], PB: [], PC: [], PD: [], PR: [], + A: game.attacker[game.where], + CF: [], CR: [], + PF: [], PR: [], flash: game.flash }; @@ -2609,15 +2610,9 @@ function make_battle_view() { } fill_cell("CR", CAESAR, b => is_battle_reserve(b)); - fill_cell("CA", CAESAR, b => !is_battle_reserve(b) && block_initiative(b) === 'A'); - fill_cell("CB", CAESAR, b => !is_battle_reserve(b) && block_initiative(b) === 'B'); - fill_cell("CC", CAESAR, b => !is_battle_reserve(b) && block_initiative(b) === 'C'); - fill_cell("CD", CAESAR, b => !is_battle_reserve(b) && block_initiative(b) === 'D'); + fill_cell("CF", CAESAR, b => !is_battle_reserve(b)); fill_cell("PR", POMPEIUS, b => is_battle_reserve(b)); - fill_cell("PA", POMPEIUS, b => !is_battle_reserve(b) && block_initiative(b) === 'A'); - fill_cell("PB", POMPEIUS, b => !is_battle_reserve(b) && block_initiative(b) === 'B'); - fill_cell("PC", POMPEIUS, b => !is_battle_reserve(b) && block_initiative(b) === 'C'); - fill_cell("PD", POMPEIUS, b => !is_battle_reserve(b) && block_initiative(b) === 'D'); + fill_cell("PF", POMPEIUS, b => !is_battle_reserve(b)); return bv; } -- cgit v1.2.3