diff options
author | Tor Andersson <tor@ccxvii.net> | 2023-10-21 18:17:26 +0200 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2023-10-22 23:13:42 +0200 |
commit | 05adcc9af69387ba1a27cd52eebda6804894cf3d (patch) | |
tree | d7cddd56f84d62c121ebb1713eeeafd8b90ddc8e /play.js | |
parent | ffa0c03be39f18dcc121553ae52c95764904886e (diff) | |
download | crusader-rex-05adcc9af69387ba1a27cd52eebda6804894cf3d.tar.gz |
Battle box #2.
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 36 |
1 files changed, 29 insertions, 7 deletions
@@ -603,6 +603,18 @@ function is_known_block(info, who, town) { return false } +function is_in_battle(b) { + if (view.battle) { + if (view.battle.FR.includes(b)) return true + if (view.battle.FC.includes(b)) return true + if (view.battle.FF.includes(b)) return true + if (view.battle.SR.includes(b)) return true + if (view.battle.SC.includes(b)) return true + if (view.battle.SF.includes(b)) return true + } + return false +} + function update_map() { let layout = {} @@ -622,11 +634,14 @@ function update_map() { for (let t = 0; t < TOWNS.length; ++t) layout[t] = { north: [], south: [] } + let is_battle_open = document.getElementById("battle").getAttribute("open") !== null + for (let b = 0; b < BLOCKS.length; ++b) { let info = BLOCKS[b] let element = ui.blocks[b] let town = view.location[b] let moved = (set_has(view.moved, b) && b !== view.who) ? " moved" : "" + let battle = (is_battle_open && is_in_battle(b)) ? " battle" : "" if (town === DEAD) { moved = " moved" } @@ -638,7 +653,7 @@ function update_map() { let image = " block_" + info.image let steps = " r" + (info.steps - view.steps[b]) let known = " known" - element.classList = info.owner + known + " block" + image + steps + moved + element.classList = info.owner + known + " block" + image + steps + moved + battle } else { let besieging = "" if (view.sieges[town] === info.owner) { @@ -650,7 +665,7 @@ function update_map() { let jihad = "" if (view.jihad === town && info.owner === view.p1) jihad = " jihad" - element.classList = info.owner + " block" + moved + besieging + jihad + element.classList = info.owner + " block" + moved + besieging + jihad + battle } if (town !== DEAD) { if (info.owner === FRANKS) @@ -693,6 +708,7 @@ function update_map() { ui.towns[t].classList.remove('highlight') ui.towns[t].classList.remove('muster') ui.towns[t].classList.remove('bad') + ui.towns[t].classList.remove('battle') } } if (view.actions && view.actions.town) { @@ -713,6 +729,8 @@ function update_map() { if (view.actions && view.actions.block) for (let b of view.actions.block) ui.blocks[b].classList.add('highlight') + } else { + ui.towns[view.battle.town].classList.add('battle') } if (view.who >= 0 && !view.battle) ui.blocks[view.who].classList.add('selected') @@ -807,7 +825,6 @@ function show_battle() { if (x > 2475 - w - 80) x = 2475 - w - 80 - //let y = space.x - h - 120 if (y < 80) y = space.x + 120 let y = space.x + h + 120 if (y > 1275) y = space.x - 120 @@ -822,7 +839,6 @@ function show_battle() { // place centered above town if possible, clamp to edges let x = space.x - w / 2 - console.log("XY", space.x, w, x) if (x < 80) x = 80 if (x > 1275 - w - 80) @@ -832,7 +848,7 @@ function show_battle() { box.style.left = x + "px" } - scroll_into_view_if_mobile(box) + scroll_into_view_if_needed(box) } function update_battle() { @@ -974,7 +990,8 @@ function on_update() { if (view.flash_next) start_flash() update_battle() - show_battle() + if (!document.getElementById("battle").classList.contains("show")) + show_battle() } else { document.getElementById("battle").classList.remove("show") } @@ -985,7 +1002,12 @@ function on_update() { window.addEventListener("resize", function (evt) { if (view && view.battle) - setTimeout(show_battle, 1) + setTimeout(function () { + document.getElementById("battle").classList.remove("show") + show_battle() + }, 1) }) +document.getElementById("battle").addEventListener("toggle", on_update) + build_map() |