diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 120 |
1 files changed, 113 insertions, 7 deletions
@@ -162,6 +162,87 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi }
}
+// POP UP CARD MENU
+
+var card_action_menu = Array.from(document.getElementById("popup").querySelectorAll("li[data-action]")).map(e => e.dataset.action)
+
+console.log('card_action_menu', card_action_menu)
+
+function show_popup_menu(evt, menu_id, target_id, title) {
+ let menu = document.getElementById(menu_id)
+ console.log('show_popup_menu called with evt',evt, 'menu_id',menu_id, 'target_id', target_id, 'title', title)
+
+ let show = false
+ console.log(`menu.querySelectorAll("li")`, menu.querySelectorAll("li"))
+ for (let item of menu.querySelectorAll("li")) {
+ let action = item.dataset.action
+ console.log('item', item, 'action', action)
+ if (action) {
+ //console.log('in if action')
+ if (is_card_action(action, target_id)) {
+ console.log('in is_card_action',)
+ show = true
+ item.classList.add("action")
+ item.classList.remove("disabled")
+ item.onclick = function () {
+ send_action(action, target_id)
+ hide_popup_menu()
+ evt.stopPropagation()
+ }
+ } else {
+ item.classList.remove("action")
+ item.classList.add("disabled")
+ item.onclick = null
+ }
+ }
+ }
+
+ if (show) {
+ menu.onmouseleave = hide_popup_menu
+ menu.style.display = "block"
+ if (title) {
+ let item = menu.querySelector("li.title")
+ if (item) {
+ item.onclick = hide_popup_menu
+ item.textContent = title
+ }
+ }
+
+ let w = menu.clientWidth
+ let h = menu.clientHeight
+ let x = Math.max(5, Math.min(evt.clientX - w / 2, window.innerWidth - w - 5))
+ let y = Math.max(5, Math.min(evt.clientY - 12, window.innerHeight - h - 40))
+ menu.style.left = x + "px"
+ menu.style.top = y + "px"
+
+ evt.stopPropagation()
+ } else {
+ menu.style.display = "none"
+ }
+}
+
+function hide_popup_menu() {
+ document.getElementById("popup").style.display = "none"
+ document.getElementById("popup_ceh_check").style.display = "none"
+ document.getElementById("popup_opp_event").style.display = "none"
+ document.getElementById("popup_tst_8").style.display = "none"
+}
+
+
+function is_card_enabled(card) {
+ if (view.actions) {
+ if (card_action_menu.some(a => view.actions[a] && view.actions[a].includes(card)))
+ return true
+ if (view.actions.card_select && view.actions.card_select.includes(card))
+ return true
+ if (view.actions.card && view.actions.card.includes(card))
+ return true
+ }
+ return false
+}
+
+// SUPPORTING FUNCTIONS
+
function on_click_space(evt) {
if (evt.button === 0) {
const space = evt.target.my_space;
@@ -182,22 +263,47 @@ function on_click_card(evt) { //console.log('on_click_card')
if (evt.button === 0) {
const card = evt.target.my_card;
- // console.log('on_click_card_called with card:', card);
- if (send_action('card', card)) {
- evt.stopPropagation();
- } else {
- // console.log('send_action failed for card:', card);
+ console.log('on_click_card_called with card:', card);
+ if (is_action('card', card)) {
+ console.log('in action card')
+ if (send_action('card', card)) {
+ evt.stopPropagation();
+ }
+ }
+ //First check for TST special power
+ else if (is_card_action('card_tst_8', card)) {
+ show_popup_menu(evt, "popup_tst_8", card, cards[card].name)
+ }
+
+ //Check for Common European Home
+ else if (is_card_action('card_ceh', card)) {
+ show_popup_menu(evt, "popup_ceh_check", card, cards[card].name)
+ } else if (is_card_action('card_opp_event', card)) {
+ console.log('in action card_opp_event')
+ show_popup_menu(evt, "popup_opp_event", card, cards[card].name)
+ }
+ else {
+ console.log('in action card_my_event')
+ show_popup_menu(evt, "popup", card, cards[card].name)
}
}
}
function is_action(action) {
//console.log('is_action called with: ', action)
+ console.log('view.actions', view.actions)
if (view.actions && view.actions[action])
return true
return false
}
+function is_card_action(action, card) {
+ console.log('is_card_action called with action', action, 'card', card)
+ console.log('view.actions', view.actions, 'view.actions[action]', view.actions[action])
+ if (view.actions && view.actions[action] && view.actions[action].includes(card))
+ return true
+ return false
+}
function on_log(text) { // eslint-disable-line no-unused-vars
@@ -632,8 +738,8 @@ if (view.persistent_events.includes(97)) { action_button("bulgaria", "Bulgaria")
action_button("extra", "Take action round")
action_button("pass", "Pass")
- action_button("remove", "Remove influence")
- action_button("add", "Add influence")
+ action_button("remove", "Remove SPs")
+ action_button("add", "Add SPs")
action_button("ops", "Operations")
action_button("discard", "Discard")
action_button("strike", "Strike")
|