Fixed last hand rendering

This commit is contained in:
2021-06-23 21:02:33 +02:00
parent 17fb1253b3
commit c9ffa273a4
+42 -49
View File
@@ -44,41 +44,45 @@ function idToCard(cardId) {
} }
function cardToElement(card, forDeck = false, drawn = false) { function cardToElement(card, forDeck = false, drawn = false) {
var element = document.createElement("okey-card"); if (card) {
element.innerHTML = card.number.toString(); var element = document.createElement("okey-card");
element.innerHTML = card.number.toString();
if (forDeck) {
element.setAttribute("onclick", "drawCard('" + cardToId(card) + "')"); if (forDeck) {
if (isHandFull()) { element.setAttribute("onclick", "drawCard('" + cardToId(card) + "')");
element.setAttribute("hand-full", ""); if (isHandFull()) {
element.setAttribute("hand-full", "");
}
} }
} else {
else { element.setAttribute("onclick", "discard('" + cardToId(card) + "')");
element.setAttribute("onclick", "discard('" + cardToId(card) + "')"); }
}
if (forDeck && drawn) {
if (forDeck && drawn) { element.classList.add("drawn-" + card.color);
element.classList.add("drawn-" + card.color); }
} else {
else { element.classList.add(card.color);
element.classList.add(card.color); element.setAttribute("clickable", "");
element.setAttribute("clickable", ""); }
}
if (!forDeck) {
if (!forDeck) { if (recommendations.length > 0 ) {
if (recommendations.length > 0 ) { if (recommendations[0].burnedCard) {
if (recommendations[0].burnedCard) { if (recommendations[0].burnedCard == card.id) {
if (recommendations[0].burnedCard == card.id) { element.classList.add("discard");
element.classList.add("discard"); }
}
else if (recommendations[0].cards && recommendations[0].cards.includes(card.id)) {
element.classList.add("select");
} }
} }
else if (recommendations[0].cards && recommendations[0].cards.includes(card.id)) {
element.classList.add("select");
}
} }
return element.outerHTML;
} }
return element.outerHTML; return "";
} }
function isHandFull(thisHand = null) { function isHandFull(thisHand = null) {
@@ -139,7 +143,7 @@ function discard(cardId, thisHand = null, update = true) {
} }
} }
function cashOut(thisHand = null) { function cashOut(thisHand = null, forceRefresh = true) {
if (recommendations.length > 0) { if (recommendations.length > 0) {
let handGiven = true; let handGiven = true;
if (thisHand == null) { if (thisHand == null) {
@@ -147,11 +151,7 @@ function cashOut(thisHand = null) {
handGiven = false; handGiven = false;
} }
// console.log("Recommendation: ");
// console.log(recommendations[0]);
if (recommendations[0].burnedCard) { if (recommendations[0].burnedCard) {
// console.log("Discarding: " + recommendations[0].burnedCard);
discard(recommendations[0].burnedCard, thisHand, false); discard(recommendations[0].burnedCard, thisHand, false);
} }
else if (recommendations[0].pattern && recommendations[0].cards) { else if (recommendations[0].pattern && recommendations[0].cards) {
@@ -163,20 +163,15 @@ function cashOut(thisHand = null) {
recommendations = []; recommendations = [];
for (let cardId of localCards) { for (let cardId of localCards) {
// console.log("Redeeming: " + cardId);
discard(cardId, thisHand, false); discard(cardId, thisHand, false);
} }
globalPoints += localPoints; globalPoints += localPoints;
// console.log("Cashed out: " + (localPoints * pointsMultiplier) + " points");
}
if (!handGiven) {
updateUI();
} }
} }
else {
// console.log("Nothing to do."); if (forceRefresh) {
updateUI();
} }
} }
@@ -239,8 +234,10 @@ function getPatterns(thisHand = null) {
// fill them with the current hand's cards // fill them with the current hand's cards
for (let cardId of thisHand) { for (let cardId of thisHand) {
let card = idToCard(cardId); let card = idToCard(cardId);
cardColorsByNumbers[card.number - 1].push(card.color); if (card) {
cardsByNumbers[card.number - 1].push(card); cardColorsByNumbers[card.number - 1].push(card.color);
cardsByNumbers[card.number - 1].push(card);
}
} }
// check if there are "color" amount of any // check if there are "color" amount of any
@@ -458,10 +455,6 @@ function recommendThrowaway(depth = 0, thisHand = null, thisDeck = null, chance
} }
return place; return place;
}); });
// let fewer = recommendations.filter(choice => choice.chance >= 0.01);
// if (fewer.length > 0) {
// recommendations = fewer;
// }
} }
} }
@@ -486,7 +479,7 @@ function updateUI(skipAuto = false) {
recommend(); recommend();
} }
else { else {
// recommendations = []; recommendations = [];
} }
} }
recommendationArray = []; recommendationArray = [];