summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
Diffstat (limited to 'play.js')
-rw-r--r--play.js106
1 files changed, 57 insertions, 49 deletions
diff --git a/play.js b/play.js
index 0c8c5fc..62566fc 100644
--- a/play.js
+++ b/play.js
@@ -230,60 +230,64 @@ function on_click_disc(evt) {
}
}
+function create(t, p, ...c) {
+ let e = document.createElement(t)
+ Object.assign(e, p)
+ e.append(c)
+ return e
+}
+
function build_user_interface() {
let elt
document.getElementById("red_momentum").addEventListener("mousedown", on_click_red_momentum)
document.getElementById("blue_momentum").addEventListener("mousedown", on_click_blue_momentum)
- ui.red_objective_back = document.createElement("div")
- ui.red_objective_back.className = "card card_objective_back"
- ui.blue_objective_back = document.createElement("div")
- ui.blue_objective_back.className = "card card_objective_back"
+ ui.objective_back = [
+ create("div", { className: "card card_objective_back" }),
+ create("div", { className: "card card_objective_back" }),
+ create("div", { className: "card card_objective_back" }),
+ create("div", { className: "card card_objective_back" }),
+ ]
for (let c = 1; c <= 41 + 12; ++c) {
- elt = ui.cards[c] = document.createElement("div")
- elt.className = `card card_${c}`
- elt.my_card = c
- elt.addEventListener("click", on_click_card)
+ elt = ui.cards[c] = create("div", {
+ className: `card card_${c}`,
+ my_card: c,
+ onmousedown: on_click_card
+ })
}
for (let i = 0; i < 36; ++i) {
- elt = ui.cubes[i] = document.createElement("div")
- if (i < 18)
- elt.className = "piece cube red"
- else
- elt.className = "piece cube blue"
- elt.my_cube = i
- elt.addEventListener("mousedown", on_click_cube)
+ elt = ui.cubes[i] = create("div", {
+ className: (i < 18) ? "piece cube red" : "piece cube blue",
+ my_cube: i,
+ onmousedown: on_click_cube,
+ })
document.getElementById("pieces").appendChild(elt)
}
for (let i = 0; i < 4; ++i) {
- elt = ui.discs[i] = document.createElement("div")
- if (i < 2)
- elt.className = "piece disc red"
- else
- elt.className = "piece disc blue"
- elt.my_disc = i + 36
- elt.addEventListener("mousedown", on_click_disc)
+ elt = ui.discs[i] = create("div", {
+ className: (i<2) ? "piece disc red" : "piece disc blue",
+ my_disc: i + 36,
+ onmousedown: on_click_disc
+ })
document.getElementById("pieces").appendChild(elt)
}
for (let i = 0; i < space_count; ++i) {
let name = space_names[i]
let [x, y, w, h] = boxes[name]
- elt = ui.spaces[i] = document.createElement("div")
- elt.className = "space"
- elt.my_space = i
- elt.my_name = name
- elt.addEventListener("mousedown", on_click_space)
- elt.addEventListener("mouseenter", on_focus_space)
- elt.addEventListener("mouseleave", on_blur)
- elt.style.top = (y-1) + "px"
- elt.style.left = (x-1) + "px"
- elt.style.width = (w+2) + "px"
- elt.style.height = (h+2) + "px"
+ elt = ui.spaces[i] = create("div", {
+ className: "space",
+ my_space: i,
+ my_name: name,
+ onmousedown: on_click_space,
+ onmouseenter: on_focus_space,
+ onmouseleave: on_blur,
+ style: `top: ${y-1}px;left:${x-1}px;width:${w+2}px;height:${h+2}px`
+ })
space_layout_cube[i] = { x: x + Math.round(w/2), y: y + Math.round(h*1/2) }
space_layout_disc[i] = { x: x + w, y: y + h }
document.getElementById("spaces").appendChild(elt)
@@ -380,6 +384,20 @@ function on_log(text) {
return p
}
+function on_update_objective(parent, objective) {
+ if (typeof objective === "object") {
+ for (let c of objective)
+ parent.appendChild(ui.cards[c])
+ } else if (objective === 1) {
+ parent.appendChild(ui.objective_back[0])
+ } else if (objective === 2) {
+ parent.appendChild(ui.objective_back[0])
+ parent.appendChild(ui.objective_back[1])
+ } else if (objective > 2) {
+ parent.appendChild(ui.cards[objective])
+ }
+}
+
function on_update() {
if (view.initiative === "Commune")
document.getElementById("commune_info").textContent = "\u2756"
@@ -402,35 +420,25 @@ function on_update() {
ui.military_vp.className = `piece cylinder purple vp${5+view.military_vp}`
ui.political_vp.className = `piece cylinder orange vp${5+view.political_vp}`
+ document.querySelector("body").classList.toggle("censorship", view.censorship === 1)
+
document.getElementById("hand").replaceChildren()
document.getElementById("discard").replaceChildren()
document.getElementById("set_aside").replaceChildren()
-
- // document.getElementById("final").replaceChildren()
- // document.getElementById("objective").replaceChildren()
-
document.getElementById("commune_cards").replaceChildren()
document.getElementById("versailles_cards").replaceChildren()
if (view.red_final)
document.getElementById("commune_cards").appendChild(ui.cards[view.red_final])
+ on_update_objective(document.getElementById("commune_cards"), view.red_objective)
+
if (view.blue_final)
document.getElementById("versailles_cards").appendChild(ui.cards[view.blue_final])
-
- if (view.red_objective === 0)
- document.getElementById("commune_cards").appendChild(ui.red_objective_back)
- else
- for (let c of view.red_objective)
- document.getElementById("commune_cards").appendChild(ui.cards[c])
-
- if (view.blue_objective === 0)
- document.getElementById("versailles_cards").appendChild(ui.blue_objective_back)
- else
- for (let c of view.blue_objective)
- document.getElementById("versailles_cards").appendChild(ui.cards[c])
+ on_update_objective(document.getElementById("versailles_cards"), view.blue_objective)
if (view.discard)
document.getElementById("discard").appendChild(ui.cards[view.discard])
+
if (view.hand)
for (let c of view.hand)
document.getElementById("hand").appendChild(ui.cards[c])