summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-02 16:46:08 +0100
committerMischa Untaga <99098079+MischaU8@users.noreply.github.com>2023-11-02 16:46:08 +0100
commit034875897c20a28d569ceec2622d7ead7e436c08 (patch)
treeca98642f01cb4424e2c83d1c1ca75d71a211ccfd
parentf34de1c19e40bd5fbab52ae09f00125c053af20e (diff)
downloadvotes-for-women-034875897c20a28d569ceec2622d7ead7e436c08.tar.gz
card actions WIP
-rw-r--r--play.html3
-rw-r--r--play.js94
-rw-r--r--rules.js41
3 files changed, 131 insertions, 7 deletions
diff --git a/play.html b/play.html
index d1c4b04..8bce1a6 100644
--- a/play.html
+++ b/play.html
@@ -360,6 +360,9 @@ div.region:hover {
<li class="title">TITLE
<li class="separator">
<li data-action="card_event"> &#x1f3b4; &nbsp; Event
+ <li data-action="card_campaigning"> &#x1F4E3; &nbsp; Campaigning Action
+ <li data-action="card_organizing"> &#x1F64B; &nbsp; Organizing Action
+ <li data-action="card_lobbying"> &#x1F3DB; &nbsp; Lobbying Action
</menu>
<header>
diff --git a/play.js b/play.js
index c3f107b..2b8ae7e 100644
--- a/play.js
+++ b/play.js
@@ -77,6 +77,82 @@ const LAYOUT = {
"WA": [158, 97],
}
+// CARD MENU
+
+var card_action_menu = Array.from(document.getElementById("popup").querySelectorAll("li[data-action]")).map(e => e.dataset.action)
+
+function is_popup_menu_action(menu_id, target_id) {
+ let menu = document.getElementById(menu_id)
+ for (let item of menu.querySelectorAll("li")) {
+ let action = item.dataset.action
+ if (action)
+ return true
+ }
+ return false
+}
+
+function show_popup_menu(evt, menu_id, target_id, title) {
+ let menu = document.getElementById(menu_id)
+
+ let show = false
+ for (let item of menu.querySelectorAll("li")) {
+ let action = item.dataset.action
+ if (action) {
+ if (is_card_action(action, target_id)) {
+ 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"
+}
+
+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 && view.actions.card.includes(card))
+ return true
+ }
+ return false
+}
+
function is_action(action) {
if (view.actions && view.actions[action])
return true
@@ -114,10 +190,20 @@ function on_focus_piece(evt) {
document.getElementById("status").textContent = evt.target.my_name
}
+// function on_click_card(evt) {
+// if (evt.button === 0) {
+// if (send_action('card', evt.target.my_card))
+// evt.stopPropagation()
+// }
+// }
+
function on_click_card(evt) {
- if (evt.button === 0) {
- if (send_action('card', evt.target.my_card))
- evt.stopPropagation()
+ let card = evt.target.my_card
+ console.log("CLICK", card)
+ if (is_action('card', card)) {
+ send_action('card', card)
+ } else {
+ show_popup_menu(evt, "popup", card, CARDS[card].title)
}
}
@@ -126,6 +212,7 @@ function on_click_space(evt) {
if (send_action('space', evt.target.my_space))
evt.stopPropagation()
}
+ hide_popup_menu()
}
function on_click_cube(evt) {
@@ -133,6 +220,7 @@ function on_click_cube(evt) {
if (send_action('piece', evt.target.my_cube))
evt.stopPropagation()
}
+ hide_popup_menu()
}
function create(t, p, ...c) {
diff --git a/rules.js b/rules.js
index acae9ac..ba32e48 100644
--- a/rules.js
+++ b/rules.js
@@ -112,7 +112,7 @@ function init_player_cards(first_card) {
function draw_card(deck) {
if (deck.length === 0)
throw Error("can't draw from empty deck")
- return deck.splice(-1)
+ return deck.pop()
}
function start_turn() {
@@ -190,12 +190,41 @@ function goto_operations_phase() {
begin_player_round()
}
+function current_player_hand() {
+ if (game.active === SUF) {
+ return game.support_hand
+ } else if (game.active === OPP) {
+ return game.opposition_hand
+ }
+ return []
+}
+
states.operations_phase = {
inactive: "to do Operations Phase",
prompt() {
view.prompt = "Operations Phase: Play a Card"
+
+ for (let c of current_player_hand()) {
+ gen_action("card_event", c)
+ gen_action("card_campaigning", c)
+ gen_action("card_organizing", c)
+ gen_action("card_lobbying", c)
+ }
+
gen_action("done")
},
+ card_event(c) {
+ log(`Playing C${c} as Event`)
+ },
+ card_campaigning(c) {
+ log(`Playing C${c} for Campaigning Action`)
+ },
+ card_organizing(c) {
+ log(`Playing C${c} for Organizing Action`)
+ },
+ card_lobbying(c) {
+ log(`Playing C${c} for Lobbying Action`)
+ },
done() {
end_player_round()
}
@@ -272,9 +301,13 @@ function end_cleanup_phase() {
// public functions
function gen_action(action, argument) {
- if (!(action in view.actions))
- view.actions[action] = []
- view.actions[action].push(argument)
+ if (argument === undefined) {
+ view.actions[action] = 1
+ } else {
+ if (!(action in view.actions))
+ view.actions[action] = []
+ view.actions[action].push(argument)
+ }
}
exports.action = function (state, player, action, arg) {