summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js80
1 files changed, 63 insertions, 17 deletions
diff --git a/play.js b/play.js
index 0fedce8..7c89572 100644
--- a/play.js
+++ b/play.js
@@ -1,11 +1,5 @@
"use strict"
-function scroll_into_view_if_mobile(e) {
- // if ("ontouchstart" in window)
- if (window.innerWidth <= 800)
- e.scrollIntoView({ block: "center", inline: "center", behavior: "smooth" })
-}
-
function set_has(set, item) {
let a = 0
let b = set.length - 1
@@ -150,7 +144,7 @@ function on_blur_space_tip(x) {
}
function on_click_space_tip(x) {
- ui.spaces[x].scrollIntoView({ block:"center", inline:"center", behavior:"smooth" })
+ scroll_into_view(ui.spaces[x])
}
function sub_space_name(match, p1, offset, string) {
@@ -559,13 +553,26 @@ function is_visible_block(where, who) {
return true
}
+function is_in_battle(b) {
+ if (view.battle) {
+ if (view.battle.CR.includes(b)) return true
+ if (view.battle.PR.includes(b)) return true
+ if (view.battle.CF.includes(b)) return true
+ if (view.battle.PF.includes(b)) return true
+ }
+ return false
+}
+
function update_map() {
let layout = {}
for (let s = 0; s < space_count; ++s)
layout[s] = { north: [], south: [] }
+ let is_battle_open = document.getElementById("battle").getAttribute("open") !== null
+
for (let b in view.location) {
+ b = b | 0
let info = BLOCKS[b]
let element = ui.blocks[b]
let space = view.location[b]
@@ -573,10 +580,13 @@ function update_map() {
let moved = set_has(view.moved, b) ? " moved" : ""
if (space === DEAD && info.type !== 'leader')
moved = " moved"
+ let battle = ""
+ if (is_battle_open && is_in_battle(b))
+ battle = " battle"
if (is_known_block(b)) {
let image = " block_" + b
let known = " known"
- element.classList = block_color(b) + known + " block" + image + moved
+ element.classList = block_color(b) + known + " block" + image + moved + battle
update_steps(b, element, true)
} else {
let jupiter = ""
@@ -588,7 +598,7 @@ function update_map() {
mars = " mars"
if (block_owner(b) === view.neptune && space === view.surprise)
neptune = " neptune"
- element.classList = block_color(b) + " block" + moved + jupiter + mars + neptune
+ element.classList = block_color(b) + " block" + moved + jupiter + mars + neptune + battle
}
if (block_owner(b) === CAESAR)
layout[space].north.push(element)
@@ -609,6 +619,7 @@ function update_map() {
if (ui.spaces[s]) {
ui.spaces[s].classList.remove('highlight')
ui.spaces[s].classList.remove('where')
+ ui.spaces[s].classList.remove('battle')
}
}
if (view.actions && view.actions.space)
@@ -625,6 +636,8 @@ function update_map() {
ui.blocks[b].classList.add('highlight')
if (view.who >= 0)
ui.blocks[view.who].classList.add('selected')
+ } else {
+ ui.spaces[view.battle.where].classList.add('battle')
}
for (let b = 0; b < block_count; ++b) {
@@ -660,6 +673,37 @@ function sort_battle_row(root, ballista) {
} while (swapped)
}
+function show_battle() {
+ let box = document.getElementById("battle")
+ let space = SPACES[view.battle.where].layout
+
+ // reset position
+ box.classList.add("show")
+ box.style.top = null
+ box.style.left = null
+ box.setAttribute("open", true)
+
+ // calculate size
+ let w = box.clientWidth
+ let h = box.clientHeight
+
+ // center where possible
+ let x = space.x - w / 2
+ if (x < 140)
+ x = 140
+ if (x > 2475 - w - 60)
+ x = 2475 - w - 60
+
+ let y = space.y - h - 120
+ if (y < 50)
+ y = space.y + 120
+
+ box.style.top = y + "px"
+ box.style.left = x + "px"
+
+ scroll_into_view_if_needed(box)
+}
+
function update_battle() {
function fill_cell(name, list, reserve, ballista) {
let cell = window[name]
@@ -707,6 +751,10 @@ function update_battle() {
ui.battle_block[block].classList.remove("known")
else
ui.battle_block[block].classList.add("known")
+ if (set_has(view.traitor, block))
+ ui.battle_block[block].classList.add("jupiter")
+ else
+ ui.battle_block[block].classList.remove("jupiter")
}
for (let b = 0; b < block_count; ++b) {
@@ -798,20 +846,19 @@ function on_update() {
remember_position(ui.cards[c])
update_cards()
- update_map()
if (view.battle) {
document.getElementById("battle_header").textContent = view.battle.title
document.getElementById("battle_message").textContent = view.battle.flash
- if (!document.getElementById("battle").classList.contains("show")) {
- document.getElementById("battle").classList.add("show")
- scroll_into_view_if_mobile(document.getElementById("battle"))
- }
update_battle()
+ if (!document.getElementById("battle").classList.contains("show"))
+ show_battle()
} else {
document.getElementById("battle").classList.remove("show")
}
+ update_map()
+
ui.old_location = Object.assign({}, view.location)
ui.old_steps = Object.assign({}, view.steps)
@@ -823,10 +870,9 @@ function select_card(c) {
send_action('card', c)
}
+document.getElementById("battle").addEventListener("toggle", on_update)
+
build_map()
document.getElementById("blocks").classList.add(label_style+'-labels')
document.getElementById("battle").classList.add(label_style+'-labels')
-
-drag_element_with_mouse("#battle", "#battle_header")
-scroll_with_middle_mouse("main")