summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-05-17 13:33:00 +0200
committerTor Andersson <tor@ccxvii.net>2024-08-21 00:28:20 +0200
commit62e2b0858c6b8f6e975161053d1653c59e08905d (patch)
tree4078215693760046f5744d7c1f438b2155757e66 /play.js
parent5424a2756d266a983ded718c4f36412cbbfac07a (diff)
downloadwashingtons-war-62e2b0858c6b8f6e975161053d1653c59e08905d.tar.gz
pc+cu in one array
Diffstat (limited to 'play.js')
-rw-r--r--play.js59
1 files changed, 41 insertions, 18 deletions
diff --git a/play.js b/play.js
index dc5863e..04ce045 100644
--- a/play.js
+++ b/play.js
@@ -4,6 +4,13 @@ const PC_NONE = 0
const PC_BRITISH = 1
const PC_AMERICAN = 2
+const CU_BRITISH_SHIFT = 2
+const CU_AMERICAN_SHIFT = 8
+const CU_FRENCH_SHIFT = 14
+const CU_BRITISH_MASK = 63 << CU_BRITISH_SHIFT
+const CU_AMERICAN_MASK = 63 << CU_AMERICAN_SHIFT
+const CU_FRENCH_MASK = 7 << CU_FRENCH_SHIFT
+
const GENERALS = data.generals
const CARDS = data.cards
const SPACES = data.spaces
@@ -235,7 +242,19 @@ function build_map() {
}
function get_space_pc(space) {
- return view.pc[space] & 3
+ return view.spc[space] & 3
+}
+
+function count_british_cu(s) {
+ return (view.spc[s] & CU_BRITISH_MASK) >>> CU_BRITISH_SHIFT
+}
+
+function count_american_cu(s) {
+ return (view.spc[s] & CU_AMERICAN_MASK) >>> CU_AMERICAN_SHIFT
+}
+
+function count_french_cu(s) {
+ return (view.spc[s] & CU_FRENCH_MASK) >>> CU_FRENCH_SHIFT
}
function update_units() {
@@ -307,16 +326,16 @@ function update_units() {
ui.control[c].className = "marker control"
}
- let offset = {}
+ let offset = []
for (let g in GENERALS) {
let e = ui.generals[g]
- let loc = view.generals[g]
+ let loc = view.loc[g]
let space = SPACES[loc] || BOXES[loc]
if (space) {
- let o = offset[space.name] | 0
+ let o = offset[loc] | 0
update_marker_xy(e, space.x + o * generalX, space.y + o * generalY - 32)
e.classList.remove("offmap")
- offset[space.name] = ++o
+ offset[loc] = ++o
} else {
e.classList.add("offmap")
}
@@ -327,17 +346,23 @@ function update_units() {
}
// TODO: reuse CU elements
- offset = {}
+ offset = []
+ function add_cu_marker(s, n, cn) {
+ if (n > 0) {
+ let space = SPACES[s]
+ let o = offset[s] | 0
+ let x = space.x + o * cuX
+ let y = space.y + o * cuY
+ let e = build_marker("cu", null, x, y, 122 / 2, 122 / 2, cn)
+ e.textContent = n
+ offset[s] = ++o
+ }
+ }
clear_group("cu")
- for (let i = 0; i < view.cu.length; ++i) {
- let cu = view.cu[i]
- let space = SPACES[cu.location] || BOXES[cu.location]
- let o = offset[space.name] | 0
- let x = space.x + o * cuX
- let y = space.y + o * cuY
- let e = build_marker("cu", "cu" + i, x, y, 122 / 2, 122 / 2, [ "cu", cu.owner.toLowerCase() ])
- e.textContent = cu.count
- offset[space.name] = ++o
+ for (let s = 0; s < view.spc.length; ++s) {
+ add_cu_marker(s, count_british_cu(s), [ "cu", "british" ])
+ add_cu_marker(s, count_american_cu(s), [ "cu", "american" ])
+ add_cu_marker(s, count_french_cu(s), [ "cu", "french" ])
}
}
@@ -427,9 +452,6 @@ function on_update() {
update_units()
- if (player != view.active)
- return
-
if (view.actions)
for (let action of Object.keys(view.actions)) {
let args = view.actions[action]
@@ -457,6 +479,7 @@ function on_update() {
case "place_british_pc":
case "remove_pc":
case "flip_pc":
+ console.log("ACTION", args)
for (let space of args)
ui.spaces[space].classList.add("enabled")
break