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.css | 28 +++++++++++++++------ play.html | 54 +++++++++++++++++++++++++--------------- play.js | 85 +++++++++++++++++++++++++++++++-------------------------------- rules.js | 21 ++++++++-------- 4 files changed, 108 insertions(+), 80 deletions(-) diff --git a/play.css b/play.css index 3685954..e462540 100644 --- a/play.css +++ b/play.css @@ -172,12 +172,17 @@ header.your_turn.austria { background-color: var(--color-light-austria); } dialog { background-color: #f3ebd4; + user-select: none; } dialog button { margin-left: 8px; } +dialog p { + margin: 6px 0; +} + /* PANELS */ .panel { @@ -336,24 +341,33 @@ button:not(.hide):has(img) { width: 879px; background-color: var(--color-light-political); border: 1px solid #0008; + border-collapse: collapse; } -#pd_deals td { - border: 1px solid #0004; - padding: 4px; - vertical-align: top; -} - -#pd_deals td img { +#pd_deals img { display: block; border: 1px solid black; } +#pd_deals th { + border-bottom: 1px solid #0008; +} + #pd_deals th { font-weight: normal; background-color: #0002; } +#pd_deals td { + padding: 4px; + vertical-align: top; +} + +#pd_deals tr.sep td { + border: 1px solid #000; + background-color: #0002; +} + #pd_deals .deal { margin-top: 8px; } diff --git a/play.html b/play.html index d078606..927a35e 100644 --- a/play.html +++ b/play.html @@ -166,15 +166,32 @@ -
- - - - -
+ +

+ + + + +

-

+

+ - ❦ - + +

-
- - - - -
- -

- - Last until: -
- @@ -208,8 +214,16 @@ -

+

+ + + + +

+ +
+

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 ]) diff --git a/rules.js b/rules.js index 16f9481..8143afd 100644 --- a/rules.js +++ b/rules.js @@ -83,13 +83,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_PHASE = 5 -const DI_B_PHASE = 6 +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 @@ -1405,7 +1406,7 @@ function goto_start_turn() { } // remove expired deals - game.deals = game.deals.filter(deal => deal[DI_TURN] >= game.turn) + game.deals = game.deals.filter(deal => deal[DI_A_TURN] >= game.turn || deal[DI_B_TURN] >= game.turn) } function goto_end_turn() { @@ -6617,9 +6618,9 @@ states.pong = { function should_validate_promise(me, you, phase) { for (let deal of game.deals) { - if (deal[DI_A_POWER] === me && deal[DI_B_POWER] === you && (deal[DI_A_PHASE] & phase)) + if (deal[DI_A_POWER] === me && deal[DI_B_POWER] === you && (deal[DI_A_PHASE] & phase) && game.turn <= deal[DI_A_TURN]) return true - if (deal[DI_B_POWER] === me && deal[DI_A_POWER] === you && (deal[DI_B_PHASE] & phase)) + if (deal[DI_B_POWER] === me && deal[DI_A_POWER] === you && (deal[DI_B_PHASE] & phase) && game.turn <= deal[DI_B_TURN]) return true } return false -- cgit v1.2.3