summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-03 01:57:36 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-06 01:49:09 +0100
commit719b7f1cd0917980021f8715c7f5bf8a642254f6 (patch)
treefb7005a1273955a71f52d135bb70330715b44dcd /play.js
parent3c1ae85c4614cabbc84d2aa515885028c3e5bb0b (diff)
downloadmaria-719b7f1cd0917980021f8715c7f5bf8a642254f6.tar.gz
Propose deals and list accepted deals in political display.
Diffstat (limited to 'play.js')
-rw-r--r--play.js113
1 files changed, 112 insertions, 1 deletions
diff --git a/play.js b/play.js
index 0decf5f..76aeb9e 100644
--- a/play.js
+++ b/play.js
@@ -92,6 +92,12 @@ const turn_name = [
"Winter 1744",
]
+const DI_TURN = 0
+const DI_A_POWER = 1
+const DI_B_POWER = 2
+const DI_A_PROMISE = 3
+const DI_B_PROMISE = 4
+
const F_EMPEROR_FRANCE = 1
const F_EMPEROR_AUSTRIA = 2
const F_ITALY_FRANCE = 4
@@ -1523,11 +1529,21 @@ function on_update() {
layout_combat_marker()
}
- action_menu(document.getElementById("subsidy_menu"), [
+ window.subsidy_menu.classList.toggle("hide", is_intro())
+ action_menu(window.subsidy_menu, [
"propose_subsidy",
"cancel_subsidy",
+ "propose_deal",
])
+ update_deal_list(view.deals, window.active_deal_list, "Active Deals")
+ if (view.proposed_deal) {
+ update_deal_list([ view.proposed_deal ], window.proposed_deal_list, "Proposed Deal")
+ setTimeout(() => scroll_into_view(window.proposed_deal_list), 333)
+ } else {
+ update_deal_list(null, window.proposed_deal_list, "Proposed Deal")
+ }
+
action_button_with_argument("suit", SPADES, colorize_S)
action_button_with_argument("suit", CLUBS, colorize_C)
action_button_with_argument("suit", HEARTS, colorize_H)
@@ -1679,6 +1695,101 @@ function on_log(text) {
return p
}
+/* DEAL DIALOGS */
+
+function propose_subsidy() { send_action("propose_subsidy") }
+function cancel_subsidy() { send_action("cancel_subsidy") }
+
+function html_escape(str) {
+ return str.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;")
+}
+
+function update_deal_item(deal) {
+ let [ turn, a_power, b_power, a_promise, b_promise ] = deal
+ let str = "<tr>"
+ str += "<td width=24>" + power_image[a_power]
+ str += "<td>" + html_escape(a_promise)
+ str += "<td width=24>" + power_image[b_power]
+ str += "<td>" + html_escape(b_promise)
+ str += "<td width=60>" + turn_name[turn]
+ return str
+}
+
+function update_deal_list(deals, elt, title) {
+ if (deals && deals.length > 0) {
+ let str = "<table><tr><th colspan=5>" + title
+ for (let deal of deals)
+ str += update_deal_item(deal)
+ str += "</table>"
+ elt.innerHTML = str
+ elt.style.display = "block"
+ } else {
+ elt.style.display = "none"
+ }
+}
+
+function propose_deal() {
+ if (!is_action("propose_deal"))
+ return
+
+ let form = window.propose_deal_form
+
+ form.a_power.value = view.power
+ switch (view.power) {
+ case P_FRANCE:
+ form.b_power.value = P_PRUSSIA
+ break
+ case P_PRUSSIA:
+ form.b_power.value = P_FRANCE
+ break
+ case P_PRAGMATIC:
+ form.b_power.value = P_AUSTRIA
+ break
+ case P_AUSTRIA:
+ form.b_power.value = P_PRAGMATIC
+ break
+ }
+ form.turn.value = view.turn
+
+ for (let opt of form.turn.options)
+ opt.disabled = (opt.value < view.turn)
+
+ window.propose_deal_dlog.showModal()
+}
+
+function propose_deal_submit(evt) {
+ evt.preventDefault()
+
+ let data = Object.fromEntries(new FormData(window.propose_deal_form))
+
+ data.turn = Number(data.turn)
+ data.a_power = Number(data.a_power)
+ data.b_power = Number(data.b_power)
+
+ if (!data.a_promise || !data.b_promise) {
+ alert("Each side must promise something!")
+ return
+ }
+
+ console.log(data, player_from_power(data.a_power), player_from_power(data.b_power))
+ if (player_from_power(data.a_power) === player_from_power(data.b_power)) {
+ alert("Cannot create deals between powers controlled by the same player.")
+ return
+ }
+
+ let deal = [ data.turn, data.a_power, data.b_power, data.a_promise, data.b_promise ]
+
+ if (view.actions.propose_deal)
+ send_message("action", [ "propose_deal", deal, game_cookie ])
+
+ window.propose_deal_dlog.close()
+}
+
+function propose_deal_cancel(evt) {
+ evt.preventDefault()
+ window.propose_deal_dlog.close()
+}
+
/* COMMON LIBRARY */
function array_insert(array, index, item) {