From 41df873b95bd489975cb69f37ba024f2fdb479eb Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 26 Nov 2024 00:14:53 +0100 Subject: separate expiration dates for promises --- play.js | 85 ++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 42 insertions(+), 43 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 7824ce3..3df499d 100644 --- a/play.js +++ b/play.js @@ -95,11 +95,14 @@ 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 DI_A_POWER = 0 +const DI_B_POWER = 1 +const DI_A_TURN = 2 +const DI_B_TURN = 3 +const DI_A_PHASE = 4 +const DI_B_PHASE = 5 +const DI_A_PROMISE = 6 +const DI_B_PROMISE = 7 const F_EMPEROR_FRANCE = 1 const F_EMPEROR_AUSTRIA = 2 @@ -1843,24 +1846,25 @@ function update_subsidy_list(subs, elt, title) { } function update_deal_item(deal) { - let [ turn, a_power, b_power, a_promise, b_promise, a_phase, b_phase ] = deal - let str = "" + let [ a_power, b_power, a_turn, b_turn, a_phase, b_phase, a_promise, b_promise ] = deal + let str = "" str += "" + power_image[a_power] str += "" + html_escape(a_promise) - str += "" + phase_list(a_phase) - str += "" + turn_name[turn] - str += "" + str += "" + phase_list(a_phase) + "" + str += "" + turn_name[a_turn] + str += "" str += "" + power_image[b_power] str += "" + html_escape(b_promise) - str += "" + phase_list(b_phase) + str += "" + phase_list(b_phase) + "" + str += "" + turn_name[b_turn] return str } function update_deal_list(deals, elt, title) { if (deals && deals.length > 0) { + //let str = "
" + title + "phaseuntil" let str = "
" + title - for (let deal of deals) - str += update_deal_item(deal) + str += deals.map(update_deal_item).join("
") str += "
" elt.innerHTML = str elt.style.display = "block" @@ -1882,14 +1886,14 @@ function propose_deal() { let form = window.propose_deal_form - form.a_phase_politics.checked = false - form.b_phase_politics.checked = false - form.a_phase_hussars.checked = false - form.b_phase_hussars.checked = false - form.a_phase_movement.checked = false - form.b_phase_movement.checked = false - form.a_phase_retreat.checked = false - form.b_phase_retreat.checked = false + window.a_phase_politics.checked = false + window.b_phase_politics.checked = false + window.a_phase_hussars.checked = false + window.b_phase_hussars.checked = false + window.a_phase_movement.checked = false + window.b_phase_movement.checked = false + window.a_phase_retreat.checked = false + window.b_phase_retreat.checked = false form.a_power.value = view.power switch (view.power) { @@ -1906,9 +1910,12 @@ function propose_deal() { form.b_power.value = P_PRAGMATIC break } - form.turn.value = view.turn + form.a_turn.value = view.turn + form.b_turn.value = view.turn - for (let opt of form.turn.options) + for (let opt of form.a_turn.options) + opt.disabled = (opt.value < view.turn) + for (let opt of form.b_turn.options) opt.disabled = (opt.value < view.turn) update_deal_options() @@ -1919,37 +1926,29 @@ function propose_deal() { 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) - - data.a_phase = 0 - data.b_phase = 0 - data.a_phase |= (data.a_phase_politics ? V_POLITICS : 0) - data.b_phase |= (data.b_phase_politics ? V_POLITICS : 0) - if (data.a_power === P_AUSTRIA) - data.a_phase |= (data.a_phase_hussars ? V_HUSSARS : 0) - if (data.b_power === P_AUSTRIA) - data.b_phase |= (data.b_phase_hussars ? V_HUSSARS : 0) - data.a_phase |= (data.a_phase_movement ? V_MOVEMENT : 0) - data.b_phase |= (data.b_phase_movement ? V_MOVEMENT : 0) - data.a_phase |= (data.a_phase_retreat ? V_RETREAT : 0) - data.b_phase |= (data.b_phase_retreat ? V_RETREAT : 0) + let form = new FormData(window.propose_deal_form) + let data = { + a_power: Number(form.get("a_power")), + b_power: Number(form.get("b_power")), + a_turn: Number(form.get("a_turn")), + b_turn: Number(form.get("b_turn")), + a_phase: form.getAll("a_phase").reduce((acc,x)=>acc|x, 0), + b_phase: form.getAll("b_phase").reduce((acc,x)=>acc|x, 0), + a_promise: form.get("a_promise"), + b_promise: form.get("b_promise"), + } 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, data.a_phase, data.b_phase ] + let deal = [ data.a_power, data.b_power, data.a_turn, data.b_turn, data.a_phase, data.b_phase, data.a_promise, data.b_promise ] if (view.actions.propose_deal) send_message("action", [ "propose_deal", deal, game_cookie ]) -- cgit v1.2.3