summaryrefslogtreecommitdiff
path: root/play2.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2025-02-28 00:16:57 +0100
committerTor Andersson <tor@ccxvii.net>2025-02-28 00:16:57 +0100
commitdfac77d2135ef7084852860d995113cc8709a233 (patch)
treedc9d21a1b71387f25e34e9f01981d197864f4442 /play2.js
parent27872e4dc0bd20451d502be58cbed91aca7339a6 (diff)
downloadland-and-freedom-dfac77d2135ef7084852860d995113cc8709a233.tar.gz
client wip
Diffstat (limited to 'play2.js')
-rw-r--r--play2.js234
1 files changed, 143 insertions, 91 deletions
diff --git a/play2.js b/play2.js
index 184390c..17e9ac0 100644
--- a/play2.js
+++ b/play2.js
@@ -11,6 +11,7 @@ const ui = {
},
// spaces
+ tracks_x: [],
tracks: [],
fronts: [],
@@ -80,6 +81,7 @@ function build_track(t, action_name, track_name, a, b) {
let e
ui.tracks[t] = []
+ ui.tracks_x[t] = []
for (let s = a; s <= b; ++s) {
const bm = t * 11 + s
@@ -90,12 +92,13 @@ function build_track(t, action_name, track_name, a, b) {
register_action(e, "blank_marker", bm)
ui.map.appendChild(e)
+ ui.tracks_x[t][s] = Math.round(x) + 4 + "px"
e = ui.tracks[t][s] = document.createElement("div")
e.className = "track"
e.style.top = y + "px"
- e.style.left = (x|0) + "px"
+ e.style.left = Math.round(x) + "px"
register_action(e, action_name, s);
- //ui.map.appendChild(e)
+ ui.map.appendChild(e)
x += 60.5
}
@@ -103,10 +106,9 @@ function build_track(t, action_name, track_name, a, b) {
e = (ui.standees[t] = document.createElement("div"))
e.className = "token standee standee_" + t
e.style.top = y - 10 + "px"
- e.style.left = boxes[track_name][0] + 5 + "px"
+ e.style.left = boxes[track_name][0] + 4 + "px"
register_action(e, "standee", t)
ui.map.appendChild(ui.standees[t])
-
}
function build_bonus(b, box_name, cname) {
@@ -119,7 +121,7 @@ function build_bonus(b, box_name, cname) {
ui.map.appendChild(e)
}
-function build_front(i, box_name) {
+function build_front(i, action_id, box_name) {
let e = ui.fronts[i] = document.createElement("div")
let [x, y, w, h] = boxes[box_name]
e.className = "front"
@@ -127,17 +129,13 @@ function build_front(i, box_name) {
e.style.left = Math.round(x-3) + "px"
e.style.width = Math.round(w - 6) + "px"
e.style.height = Math.round(h - 6) + "px"
- register_action(e, "front", i)
+ register_action(e, "front", action_id)
ui.map.appendChild(e)
-
- for (let i = 0; i < 5; ++i) {
- let m = document.createElement("div")
- m.className = "token square front_plus"
- e.appendChild(m)
- }
}
function on_init() {
+ var i, e
+
if (on_init_once)
return
on_init_once = true
@@ -148,16 +146,16 @@ function on_init() {
build_track(SOVIET_SUPPORT, "tr_soviet_support", "SovietSupport", 0, 10)
build_track(FOREIGN_AID, "tr_foreign_aid", "ForeignAid", 0, 10)
- build_bonus(0, "Bonus1", "bonus_morale on")
- build_bonus(1, "Bonus2", "bonus_teamwork off")
+ build_bonus(0, "Bonus1", "bonus_morale")
+ build_bonus(1, "Bonus2", "bonus_teamwork")
- build_front(0, "Aragon")
- build_front(1, "Madrid")
- build_front(2, "Northern")
- build_front(3, "Southern")
+ build_front(0, "a", "Aragon")
+ build_front(1, "m", "Madrid")
+ build_front(2, "n", "Northern")
+ build_front(3, "s", "Southern")
ui.medallion_container = []
- for (let i = 0; i < 5; ++i) {
+ for (i = 0; i < 5; ++i) {
ui.medallion_container[i] = document.createElement("div")
ui.medallion_container[i].classList = "medallion_container"
ui.medallion_container[i].style.top = boxes["Medallion"+(i+1)][1] + "px"
@@ -165,43 +163,40 @@ function on_init() {
ui.map.appendChild(ui.medallion_container[i])
}
- for (let m = 0; m < 9; ++m) {
- let e = (ui.medallions[m] = document.createElement("div"))
- e.className = "token medallion medallion_" + m
- register_action(e, "medallion", m)
- if (m < 5)
- ui.medallion_container[m].appendChild(ui.medallions[m])
+ ui.glory_container = []
+ for (i = 0; i < 4; ++i) {
+ e = (ui.glory_container[i] = document.createElement("div"))
+ e.className = "glory_container"
+ e.style.left = boxes["Glory" + (i+1)][0] + "px"
+ e.style.top = boxes["Glory" + (i+1)][1] + "px"
+ ui.map.appendChild(e)
+ }
+
+ // TODO: current year deck
+
+ ui.current_events = []
+ for (i = 0; i < 4; ++i) {
+ e = (ui.current_events[i] = document.createElement("div"))
+ e.className = "current_events"
+ e.style.left = boxes["CurrentEvent" + (i+1)][0] - 10 + "px"
+ e.style.top = boxes["CurrentEvent" + (i+1)][1] - 10 + "px"
+ ui.map.appendChild(e)
}
- for (let c = 1; c < CARD_COUNT; ++c) {
- let e = (ui.cards[c] = document.createElement("div"))
- e.className = "card"
- e.setAttribute("data-card-id", "" + data.cards[c].id)
- register_action(e, "card", c)
+ for (i = 0; i < 9; ++i) {
+ e = (ui.medallions[i] = document.createElement("div"))
+ e.className = "token medallion medallion_" + i
+ register_action(e, "medallion", i)
}
- for (let g = 0; g < GLORY_COUNT; ++g) {
- let e = (ui.glory[g] = document.createElement("div"))
- e.className = "token player"
- ui.glory_container.appendChild(ui.glory[g])
- e.style.left = LAYOUT_GLORY[g][0] + "px"
- e.style.top = LAYOUT_GLORY[g][1] + "px"
+ for (i = 1; i <= 120; ++i) {
+ e = (ui.cards[i] = document.createElement("div"))
+ e.className = "card card_" + i
+ register_action(e, "card", i)
}
- let e = (ui.initiative_token = document.createElement("div"))
+ e = ui.initiative_token = document.createElement("div")
e.className = "initiative_token"
-
- data.fronts.forEach((front) => {
- ui.tokens_on_front[front.id] = {}
- FACTIONS.forEach((faction_id) => {
- let e = (ui.tokens_on_front[front.id][faction_id] = document.createElement("div"))
- e.className = "faction_token"
- e.setAttribute("data-faction-id", faction_id)
- })
- })
- Object.keys(ui.fronts).forEach((front_id) => {
- register_action(ui.fronts[front_id].front, "front", front_id)
- })
}
function place_cards(e, cards) {
@@ -215,9 +210,107 @@ function place_cards(e, cards) {
}
}
+function update_front(container, front) {
+ var i, n, e, cn
+ container.replaceChildren()
+
+ if (front.value < 0) {
+ n = -front.value
+ cn = "token front_minus"
+ } else {
+ n = -front.value
+ cn = "token front_plus"
+ }
+ for (i = 0; i < n; ++i) {
+ let e = document.createElement("div")
+ e.className = cn
+ container.appendChild(e)
+ }
+}
+
function on_update() {
- console.log("on_update", view)
+ var i, e
+
+ console.log("on_update", JSON.stringify(view,))
on_init()
+
+ place_cards(ui.hand, view.hand)
+ place_cards(ui.tableaus.a, [ 115, ...view.tableaus.a])
+ place_cards(ui.tableaus.c, [ 116, ...view.tableaus.c])
+ place_cards(ui.tableaus.m, [ 117, ...view.tableaus.m])
+
+ // TODO: current year deck
+ ui.bonuses[0].classList.toggle("off", !view.bonuses[0])
+ ui.bonuses[1].classList.toggle("off", !view.bonuses[1])
+
+ for (i = 0; i < 4; ++i) {
+ if (i < view.current_events.length)
+ place_cards(ui.current_events[i], [view.current_events[i]])
+ else
+ place_cards(ui.current_events[i], [])
+ }
+
+ for (i = 0; i < 5; ++i)
+ ui.standees[i].style.left = ui.tracks_x[i][view.tracks[i]]
+
+ for (i = 0; i < 5; ++i) {
+ ui.medallion_container[i].replaceChildren()
+ if (i < view.medallions.pool.length)
+ ui.medallion_container[i].appendChild(ui.medallions[i])
+ }
+
+ update_front(ui.fronts[0], view.fronts.a)
+ update_front(ui.fronts[1], view.fronts.m)
+ update_front(ui.fronts[2], view.fronts.n)
+ update_front(ui.fronts[3], view.fronts.s)
+
+ action_button("add_to_front", "+1 to a Front")
+ action_button("d_liberty", "Decrease Liberty")
+ action_button("soviet_support", "Soviet Support")
+ action_button("collectivization", "Collectivization")
+ action_button("d_collectivization", "Decrease Collectivization")
+ action_button("d_foreign_aid", "Decrease Foreign Aid")
+ action_button("d_government", "Decrease Government")
+ action_button("d_soviet_support", "Decrease Soviet Support")
+ action_button("foreign_aid", "Foreign Aid")
+ action_button("government", "Government")
+ action_button("liberty", "Liberty")
+ action_button("government_to_center", "Government towards center")
+ action_button("teamwork_on", "Teamwork Bonus On")
+ action_button("Anarchist", "Anarchist")
+ action_button("Communist", "Communist")
+ action_button("Moderate", "Moderate")
+ action_button("gain_hp", "Gain Hero Points")
+ action_button("lose_hp", "Lose Hero Points")
+ action_button("draw_card", "Draw a card")
+ action_button("draw_cards", "Draw cards")
+ action_button("play_to_tableau", "Play card to Tableau")
+ action_button("play_for_event", "Play card for Event")
+ action_button("use_ap", "Use Action Points")
+ action_button("use_morale_bonus", "Use Morale Bonus")
+ action_button("move_track", "Move a Track")
+ action_button("turn_on_bonus", "Turn on a Bonus")
+ action_button("add_glory", "Add to Bag of Glory")
+ action_button("draw_glory", "Draw from Bag of Glory")
+ action_button("up", "Up")
+ action_button("down", "Down")
+ action_button("next", "Next")
+ action_button("remove_blank_marker", "Remove Blank marker")
+ action_button("confirm", "Confirm")
+ action_button("yes", "Yes")
+ action_button("no", "No")
+ action_button("skip", "Skip")
+ action_button("spend_hp", "Spend Hero Points")
+ action_button("use_momentum", "Play second card (Momentum)")
+ action_button("done", "Done")
+ action_button("end_turn", "End turn")
+ action_button("undo", "Undo")
+
+ for (let e of action_register)
+ e.classList.toggle("action", is_action(e.my_action, e.my_id))
+}
+
+function on_update_OLD() {
for (let key of Object.keys(view.hero_points)) {
ui.roles[key].hero_points.replaceChildren(`Hero Points: ${view.hero_points[key]}`)
}
@@ -296,46 +389,5 @@ function on_update() {
e.classList.toggle("action", is_action(e.my_action, e.my_id))
ui.year.replaceChildren(`Year ${view.year}`)
- action_button("add_to_front", "+1 to a Front")
- action_button("d_liberty", "Decrease Liberty")
- action_button("soviet_support", "Soviet Support")
- action_button("collectivization", "Collectivization")
- action_button("d_collectivization", "Decrease Collectivization")
- action_button("d_foreign_aid", "Decrease Foreign Aid")
- action_button("d_government", "Decrease Government")
- action_button("d_soviet_support", "Decrease Soviet Support")
- action_button("foreign_aid", "Foreign Aid")
- action_button("government", "Government")
- action_button("liberty", "Liberty")
- action_button("government_to_center", "Government towards center")
- action_button("teamwork_on", "Teamwork Bonus On")
- action_button("Anarchist", "Anarchist")
- action_button("Communist", "Communist")
- action_button("Moderate", "Moderate")
- action_button("gain_hp", "Gain Hero Points")
- action_button("lose_hp", "Lose Hero Points")
- action_button("draw_card", "Draw a card")
- action_button("draw_cards", "Draw cards")
- action_button("play_to_tableau", "Play card to Tableau")
- action_button("play_for_event", "Play card for Event")
- action_button("use_ap", "Use Action Points")
- action_button("use_morale_bonus", "Use Morale Bonus")
- action_button("move_track", "Move a Track")
- action_button("turn_on_bonus", "Turn on a Bonus")
- action_button("add_glory", "Add to Bag of Glory")
- action_button("draw_glory", "Draw from Bag of Glory")
- action_button("up", "Up")
- action_button("down", "Down")
- action_button("next", "Next")
- action_button("remove_blank_marker", "Remove Blank marker")
- action_button("confirm", "Confirm")
- action_button("yes", "Yes")
- action_button("no", "No")
- action_button("skip", "Skip")
- action_button("spend_hp", "Spend Hero Points")
- action_button("use_momentum", "Play second card (Momentum)")
- action_button("done", "Done")
- action_button("end_turn", "End turn")
- action_button("undo", "Undo")
}