From 8b3f8439480b038abfb89b542d2f0ac601bbbdd4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Mon, 21 Jun 2021 23:58:51 +0200 Subject: crusader: Intrigue. --- ui.js | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) (limited to 'ui.js') diff --git a/ui.js b/ui.js index 9ef68a0..64044ee 100644 --- a/ui.js +++ b/ui.js @@ -519,7 +519,8 @@ function hide_block(element) { function update_map() { let layout = {}; - document.getElementById("turn").textContent = "Year " + game.year + " (" + (game.year-1186) + "/6)" ; + document.getElementById("turn").textContent = + "Turn " + game.turn + " of Year " + game.year; for (let town in TOWNS) layout[town] = { north: [], south: [] }; @@ -574,29 +575,41 @@ function update_map() { } } -function update_cards() { - let cards = game.hand; - for (let c = 1; c <= 27; ++c) { - ui.cards[c].classList.remove('enabled'); - if (cards && cards.includes(c)) - ui.cards[c].classList.add('show'); - else - ui.cards[c].classList.remove('show'); +function update_card_display(element, card, prior_card) { + console.log("update_card_display", element, card, prior_card); + if (!card && !prior_card) { + element.className = "small_card card_back"; + } else if (prior_card) { + element.className = "small_card prior " + CARDS[prior_card].image; + } else { + element.className = "small_card " + CARDS[card].image; } +} - if (game.actions && game.actions.play) { - for (let c of game.actions.play) - ui.cards[c].classList.add('enabled'); - } +function update_cards() { + update_card_display(document.getElementById("frank_card"), game.f_card, game.prior_f_card); + update_card_display(document.getElementById("saracen_card"), game.s_card, game.prior_s_card); - if (!game.f_card) - document.querySelector("#frank_card").className = "small_card card_back"; - else - document.querySelector("#frank_card").className = "small_card " + CARDS[game.f_card].image; - if (!game.s_card) - document.querySelector("#saracen_card").className = "small_card card_back"; - else - document.querySelector("#saracen_card").className = "small_card " + CARDS[game.s_card].image; + for (let c = 1; c <= 27; ++c) { + let element = ui.cards[c]; + if (game.hand.includes(c)) { + element.classList.add("show"); + if (game.actions && game.actions.play) { + if (game.actions.play.includes(c)) { + element.classList.add("enabled"); + element.classList.remove("disabled"); + } else { + element.classList.remove("enabled"); + element.classList.add("disabled"); + } + } else { + element.classList.remove("enabled"); + element.classList.remove("disabled"); + } + } else { + element.classList.remove("show"); + } + } } function update_battle() { -- cgit v1.2.3