summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-05-07 11:57:00 +0200
committerTor Andersson <tor@ccxvii.net>2023-05-24 21:06:18 +0200
commitdff733bdbae936c674628a7cc88c08c0feef9d05 (patch)
tree380cbeae8bc1ba98a3ec9ddecf3fad22f5675f3d /play.js
parent1683dfb66009b504c36fb17d12558c55369fd4c4 (diff)
downloadred-flag-over-paris-dff733bdbae936c674628a7cc88c08c0feef9d05.tar.gz
No card popup menu.
Diffstat (limited to 'play.js')
-rw-r--r--play.js155
1 files changed, 61 insertions, 94 deletions
diff --git a/play.js b/play.js
index 1c3c137..4d3bffb 100644
--- a/play.js
+++ b/play.js
@@ -157,6 +157,12 @@ const boxes = {
"Prussian Collaboration 3": [306,330,157,39],
}
+function is_action(action) {
+ if (view.actions && view.actions[action])
+ return true
+ return false
+}
+
function is_card_action(action, card) {
if (view.actions && view.actions[action] && view.actions[action].includes(card))
return true
@@ -183,6 +189,27 @@ function on_focus_space(evt) {
document.getElementById("status").textContent = evt.target.my_name
}
+function on_click_red_momentum(evt) {
+ if (evt.button === 0) {
+ if (send_action('red_momentum'))
+ evt.stopPropagation()
+ }
+}
+
+function on_click_blue_momentum(evt) {
+ if (evt.button === 0) {
+ if (send_action('blue_momentum'))
+ evt.stopPropagation()
+ }
+}
+
+function on_click_card(evt) {
+ if (evt.button === 0) {
+ if (send_action('card', evt.target.my_card))
+ evt.stopPropagation()
+ }
+}
+
function on_click_space(evt) {
if (evt.button === 0) {
if (send_action('space', evt.target.my_space))
@@ -207,6 +234,9 @@ function on_click_disc(evt) {
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)
+
for (let c = 1; c <= 41 + 12; ++c) {
elt = ui.cards[c] = document.createElement("div")
elt.className = `card card_${c}`
@@ -336,11 +366,6 @@ function on_log(text) {
}
function on_update() {
- if (view.discard)
- document.getElementById("discarded_card").className = `card card_${view.discard}`
- else
- document.getElementById("discarded_card").className = `card card_strategy_back`
-
if (view.initiative === "Commune")
document.getElementById("commune_info").textContent = "\u2756"
else
@@ -351,22 +376,35 @@ function on_update() {
document.getElementById("versailles_info").textContent = ""
ui.round_marker.className = `piece pawn round${view.round}`
- ui.red_momentum.className = `piece cylinder red m${view.red_momentum}`
- ui.blue_momentum.className = `piece cylinder blue m${view.blue_momentum}`
+ if (is_action("red_momentum"))
+ ui.red_momentum.className = `piece cylinder red m${view.red_momentum} action`
+ else
+ ui.red_momentum.className = `piece cylinder red m${view.red_momentum}`
+ if (is_action("blue_momentum"))
+ ui.blue_momentum.className = `piece cylinder blue m${view.blue_momentum} action`
+ else
+ ui.blue_momentum.className = `piece cylinder blue m${view.blue_momentum}`
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.getElementById("hand").replaceChildren()
document.getElementById("final").replaceChildren()
+ document.getElementById("discard").replaceChildren()
+ document.getElementById("set_aside").replaceChildren()
document.getElementById("objective").replaceChildren()
+ if (view.final)
+ document.getElementById("final").appendChild(ui.cards[view.final])
+ 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])
- if (view.final)
- for (let c of view.final)
- document.getElementById("final").appendChild(ui.cards[c])
+ if (view.set_aside)
+ for (let c of view.set_aside)
+ document.getElementById("set_aside").appendChild(ui.cards[c])
if (view.objective)
- document.getElementById("objective").appendChild(ui.cards[view.objective])
+ for (let c of view.objective)
+ document.getElementById("objective").appendChild(ui.cards[c])
for (let i = 0; i < space_names.length; ++i)
layout[i] = []
@@ -391,6 +429,7 @@ function on_update() {
for (let i = 1; i < ui.cards.length; ++i) {
ui.cards[i].classList.toggle("action", is_card_action('card', i))
+ ui.cards[i].classList.toggle("selected", i === view.selected_card)
}
action_button("commune", "Commune");
@@ -399,95 +438,23 @@ function on_update() {
action_button("spend", "Spend");
action_button("draw", "Draw");
+ action_button("momentum", "Momentum")
+ action_button("event", "Event")
+ action_button("political", "Political")
+ action_button("military", "Military")
+
+ action_button("ops", "Operations")
+ action_button("place", "Place")
+ action_button("remove", "Remove")
+ action_button("replace", "Replace")
+
action_button("end_remove", "End Remove");
action_button("end_turn", "End Turn");
+ action_button("skip", "Skip");
action_button("done", "Done");
action_button("undo", "Undo");
}
-/* CARD ACTION MENU */
-
-let current_popup_card = 0
-
-function show_popup_menu(evt, list) {
- document.querySelectorAll("#popup div").forEach(e => e.classList.remove('enabled'))
- for (let item of list) {
- let e = document.getElementById("menu_" + item)
- e.classList.add('enabled')
- }
- let popup = document.getElementById("popup")
- popup.style.display = 'block'
- popup.style.left = (evt.clientX-50) + "px"
- popup.style.top = (evt.clientY-12) + "px"
- ui.cards[current_popup_card].classList.add("selected")
-}
-
-function hide_popup_menu() {
- let popup = document.getElementById("popup")
- popup.style.display = 'none'
- if (current_popup_card) {
- ui.cards[current_popup_card].classList.remove("selected")
- current_popup_card = 0
- }
-}
-
-function on_card_event() {
- if (send_action('card_event', current_popup_card))
- hide_popup_menu()
-}
-
-function on_card_ops() {
- if (send_action('card_ops', current_popup_card))
- hide_popup_menu()
-}
-
-function on_card_ops_political() {
- if (send_action('card_ops_political', current_popup_card))
- hide_popup_menu()
-}
-
-function on_card_ops_military() {
- if (send_action('card_ops_military', current_popup_card))
- hide_popup_menu()
-}
-
-function on_card_use_discarded() {
- if (send_action('card_use_discarded', current_popup_card))
- hide_popup_menu()
-}
-
-function on_card_advance_momentum() {
- if (send_action('card_advance_momentum', current_popup_card))
- hide_popup_menu()
-}
-
-function on_click_card(evt) {
- if (evt.button === 0) {
- if (view.actions) {
- let card = evt.target.my_card
- if (is_card_action('card', card)) {
- send_action('card', card)
- } else {
- let menu = []
- if (is_card_action('card_event', card))
- menu.push('card_event')
- if (is_card_action('card_ops_political', card))
- menu.push('card_ops_political')
- if (is_card_action('card_ops_military', card))
- menu.push('card_ops_military')
- if (is_card_action('card_use_discarded', card))
- menu.push('card_use_discarded')
- if (is_card_action('card_advance_momentum', card))
- menu.push('card_advance_momentum')
- if (menu.length > 0) {
- current_popup_card = card
- show_popup_menu(evt, menu)
- }
- }
- }
- }
-}
-
build_user_interface()
scroll_with_middle_mouse("main")