diff options
author | Tor Andersson <tor@ccxvii.net> | 2021-06-23 00:25:11 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-16 19:19:38 +0100 |
commit | 6a4cb1ed6ea859d233e492f3ebf71deae04c5a91 (patch) | |
tree | 9a693ae30580ad47246e55f7b051b73ccd52d3b7 | |
parent | dc1aa50ec82e74e8e48d4abdfceab28aca107274 (diff) | |
download | crusader-rex-6a4cb1ed6ea859d233e492f3ebf71deae04c5a91.tar.gz |
crusader: Sort blocks by initiative in battle screen.
-rw-r--r-- | info/blocks.html | 9 | ||||
-rw-r--r-- | play.html | 6 | ||||
-rw-r--r-- | rules.js | 8 | ||||
-rw-r--r-- | ui.js | 23 |
4 files changed, 33 insertions, 13 deletions
diff --git a/info/blocks.html b/info/blocks.html index 178a8f8..f93ec2c 100644 --- a/info/blocks.html +++ b/info/blocks.html @@ -19,11 +19,12 @@ div.block { height: 60px; margin: 10px; background-size: cover; - box-shadow: 0 0 4px 0px rgba(0,0,0,0.5); + border-radius: 6px; + box-shadow: 0 0 4px 0px black; } -div.frank { border: 3px solid orange; } -div.saracen { border: 3px solid green; } -div.assassins { border: 3px solid purple; } +div.frank { border: 3px solid darkkhaki; } +div.saracen { border: 3px solid seagreen; } +div.assassins { border: 3px solid rebeccapurple; } div.block:hover { transform: scale(2); } </style> <body> @@ -235,7 +235,11 @@ body.shift .block.known:hover { #ER { background-image: linear-gradient(to bottom, skyblue, tan); } #FR { background-image: linear-gradient(to bottom, tan, darkseagreen); } -#FC, #EC { background-color: gray; border-top: 5px dashed tan; } +#FC, #EC { + background-color: gray; + border-top: 5px dashed tan; + border-bottom: 5px solid dimgray; +} #FC, #EC, #FF, #EF { min-height: 120px; } #FR, #ER { min-height: 40px; } @@ -5,6 +5,8 @@ // TODO: sort blocks in battle screen! +// TODO: pause after battle ends (ui maybe?) + exports.scenarios = [ "Third Crusade" ]; @@ -3197,12 +3199,6 @@ function setup_game() { // VIEW -function compare_block_initiative(a, b) { - let aa = BLOCKS[a].combat; - let bb = BLOCKS[b].combat; - return (aa < bb) ? -1 : (aa > bb) ? 1 : 0; -} - function make_battle_view() { let battle = { FR: [], FC: [], FF: [], @@ -277,6 +277,7 @@ function build_battle_block(b, block) { menu.classList.add("battle_menu"); menu.appendChild(element); menu.appendChild(menu_list); + menu.block = b; ui.battle_menu[b] = menu; } @@ -647,6 +648,25 @@ function update_cards() { } } +function compare_blocks(a, b) { + let aa = BLOCKS[a].combat; + let bb = BLOCKS[b].combat; + if (aa == bb) + return (a < b) ? -1 : (a > b) ? 1 : 0; + return (aa < bb) ? -1 : (aa > bb) ? 1 : 0; +} + +function insert_battle_block(root, node, block) { + for (let i = 0; i < root.children.length; ++i) { + let prev = root.children[i]; + if (compare_blocks(prev.block, block) > 0) { + root.insertBefore(node, prev); + return; + } + } + root.appendChild(node); +} + function update_battle() { function fill_cell(name, list, show) { let cell = document.getElementById(name); @@ -656,9 +676,8 @@ function update_battle() { for (let block of list) { ui.present.add(block); - // TODO: insert in correct order! if (!cell.contains(ui.battle_menu[block])) - cell.appendChild(ui.battle_menu[block]); + insert_battle_block(cell, ui.battle_menu[block], block); if (block == game.who) ui.battle_block[block].classList.add("selected"); |