summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js43
1 files changed, 23 insertions, 20 deletions
diff --git a/play.js b/play.js
index c5ef4a0..0214247 100644
--- a/play.js
+++ b/play.js
@@ -16,11 +16,14 @@ function set_has(set, item) {
return false
}
-const CLEOPATRA = "Cleopatra"
-const DEAD = "Dead"
-const LEVY = "Levy"
+const DEAD = space_index["Dead"]
+const LEVY = space_index["Levy"]
+
const ENEMY = { "Caesar": "Pompeius", "Pompeius": "Caesar" }
+const block_count = BLOCKS.length
+const space_count = SPACES.length
+
let label_style = window.localStorage['julius-caesar/label-style'] || 'columbia'
let label_layout = window.localStorage['julius-caesar/label-layout'] || 'spread'
@@ -145,7 +148,7 @@ function block_original_owner(who) {
function block_owner(who) {
if (set_has(view.traitor, who))
- return enemy(block_original_owner(who))
+ return ENEMY[block_original_owner(who)]
return block_original_owner(who)
}
@@ -233,7 +236,7 @@ function build_map() {
ui.offmap_element = document.getElementById("offmap")
ui.spaces_element = document.getElementById("spaces")
- for (let s in SPACES) {
+ for (let s = 0; s < space_count; ++s) {
let space = SPACES[s]
let element = document.createElement("div")
element.classList.add("space")
@@ -315,7 +318,7 @@ function build_map() {
ui.battle_menu[b] = menu
}
- for (let b in BLOCKS) {
+ for (let b = 0; b < block_count; ++b) {
let block = BLOCKS[b]
block.color = (block.name === "Cleopatra" ? "Cleopatra" : block.owner)
build_map_block(b, block)
@@ -468,7 +471,7 @@ function is_known_block(who) {
function is_visible_block(where, who) {
if (view.game_over && player === 'Observer')
return true
- if (where === "Levy")
+ if (where === LEVY)
return block_owner(who) === player
return true
}
@@ -476,7 +479,7 @@ function is_visible_block(where, who) {
function update_map() {
let layout = {}
- for (let s in SPACES)
+ for (let s = 0; s < space_count; ++s)
layout[s] = { north: [], south: [] }
for (let b in view.location) {
@@ -484,7 +487,7 @@ function update_map() {
let element = ui.blocks[b]
let space = view.location[b]
if (is_visible_block(space, b)) {
- let moved = view.moved[b] ? " moved" : ""
+ let moved = set_has(view.moved, b) ? " moved" : ""
if (space === DEAD && info.type !== 'leader')
moved = " moved"
if (is_known_block(b)) {
@@ -517,22 +520,22 @@ function update_map() {
}
}
- for (let space in SPACES)
- layout_blocks(space, layout[space].north, layout[space].south)
+ for (let s = 0; s < space_count; ++s)
+ layout_blocks(s, layout[s].north, layout[s].south)
// Mark selections and highlights
- for (let where in SPACES) {
- if (ui.spaces[where]) {
- ui.spaces[where].classList.remove('highlight')
- ui.spaces[where].classList.remove('where')
+ for (let s = 0; s < space_count; ++s) {
+ if (ui.spaces[s]) {
+ ui.spaces[s].classList.remove('highlight')
+ ui.spaces[s].classList.remove('where')
}
}
if (view.actions && view.actions.space)
for (let where of view.actions.space)
ui.spaces[where].classList.add('highlight')
- for (let b in BLOCKS) {
+ for (let b = 0; b < block_count; ++b) {
ui.blocks[b].classList.remove('highlight')
ui.blocks[b].classList.remove('selected')
}
@@ -540,11 +543,11 @@ function update_map() {
if (view.actions && view.actions.block)
for (let b of view.actions.block)
ui.blocks[b].classList.add('highlight')
- if (view.who)
+ if (view.who >= 0)
ui.blocks[view.who].classList.add('selected')
}
- for (let b in BLOCKS) {
+ for (let b = 0; b < block_count; ++b) {
let s = view.location[b]
if (view.actions && view.actions.secret && view.actions.secret.includes(s))
ui.blocks[b].classList.add('highlight')
@@ -616,7 +619,7 @@ function update_battle() {
ui.battle_block[block].classList.add("secret")
else
ui.battle_block[block].classList.remove("secret")
- if (view.moved[block] || reserve)
+ if (set_has(view.moved, block) || reserve)
ui.battle_block[block].classList.add("moved")
else
ui.battle_block[block].classList.remove("moved")
@@ -626,7 +629,7 @@ function update_battle() {
ui.battle_block[block].classList.add("known")
}
- for (let b in BLOCKS) {
+ for (let b = 0; b < block_count; ++b) {
if (!ui.present.has(b)) {
if (cell.contains(ui.battle_menu[b]))
cell.removeChild(ui.battle_menu[b])