summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2022-05-22 22:19:27 +0200
committerTor Andersson <tor@ccxvii.net>2022-11-16 19:08:56 +0100
commitdd346772cb76d58c3334bba5738862e437d9105d (patch)
tree564cf5c7dab7390c231ba687c0d74eca2dde7122
parent28cf5ed6773a7c2736d995711bbc8a0720d9a514 (diff)
downloadjulius-caesar-dd346772cb76d58c3334bba5738862e437d9105d.tar.gz
New battle CSS.
-rw-r--r--play.css10
-rw-r--r--play.html32
-rw-r--r--play.js69
-rw-r--r--rules.js15
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 @@
</head>
<body>
-<table id="battle">
-<tr>
-<th id="battle_header" colspan=4>
-<tr class="battle_reserves enemy">
-<td colspan=4><div id="ER"></div>
-<tr class="battle_line enemy">
-<td class="battle_a_cell"><div id="EA"></div>
-<td class="battle_b_cell"><div id="EB"></div>
-<td class="battle_c_cell"><div id="EC"></div>
-<td class="battle_d_cell"><div id="ED"></div>
-<tr class="battle_separator">
-<td colspan=4>
-<tr class="battle_line friendly">
-<td class="battle_a_cell"><div id="FA"></div>
-<td class="battle_b_cell"><div id="FB"></div>
-<td class="battle_c_cell"><div id="FC"></div>
-<td class="battle_d_cell"><div id="FD"></div>
-<tr class="battle_reserves friendly">
-<td colspan=4><div id="FR"></div>
-<tr>
-<th id="battle_message" colspan=4>
-</table>
+<div id="battle">
+<div id="battle_header"></div>
+<div id="ER"></div>
+<div id="EF"></div>
+<div id="FF"></div>
+<div id="FR"></div>
+<div id="battle_message"></div>
+</div>
<header>
+ <div id="toolbar">
<div class="menu">
<div class="menu_title"><img src="/images/cog.svg"></div>
<div class="menu_popup">
@@ -61,6 +48,7 @@
<div class="icon_button" onclick="toggle_blocks()"><img src="/images/earth-africa-europe.svg"></div>
<div class="icon_button" onclick="toggle_zoom()"><img src="/images/magnifying-glass.svg"></div>
<div class="icon_button" onclick="toggle_log()"><img src="/images/scroll-quill.svg"></div>
+ </div>
<div id="prompt"></div>
<div id="actions"></div>
</header>
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;
}