Spaces:
Sleeping
Sleeping
Update templates/Briscola.html
Browse files- templates/Briscola.html +42 -9
templates/Briscola.html
CHANGED
|
@@ -395,6 +395,43 @@
|
|
| 395 |
const confirmResignButton = document.getElementById('confirm-resign-button');
|
| 396 |
const cancelResignButton = document.getElementById('cancel-resign-button');
|
| 397 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
function set_cards(parsedResponse, length = 3) {
|
| 399 |
let numb_cards = 34 - 2 * counter;
|
| 400 |
document.getElementById('Rounds').innerText = (numb_cards > 0) ? `${numb_cards} Cards Left` : '';
|
|
@@ -408,8 +445,7 @@
|
|
| 408 |
const cardString = parsedResponse.my_hand[i];
|
| 409 |
if (cardString && !cardString.includes('The game is over')) {
|
| 410 |
let card_name = cardString.replace(' ', '_') + '.jpg';
|
| 411 |
-
cardElement
|
| 412 |
-
cardElement.style.visibility = 'visible';
|
| 413 |
cardElement.disabled = false;
|
| 414 |
} else {
|
| 415 |
cardElement.style.visibility = 'hidden';
|
|
@@ -423,8 +459,7 @@
|
|
| 423 |
|
| 424 |
if (counter == 0) {
|
| 425 |
let briscola_name = parsedResponse.briscola.replace(' ', '_') + '.jpg';
|
| 426 |
-
document.getElementById('image_briscola')
|
| 427 |
-
document.getElementById('image_briscola').style.visibility = 'visible';
|
| 428 |
document.getElementById('title_briscola').innerText = '';
|
| 429 |
}
|
| 430 |
if (counter >= 17) {
|
|
@@ -437,10 +472,9 @@
|
|
| 437 |
function opponent_card_appears(parsedResponse) {
|
| 438 |
if (parsedResponse.card_player_1 != 'Not played yet') {
|
| 439 |
let name_card_played_by_opp = parsedResponse.card_player_1.replace(' ', '_') + '.jpg';
|
| 440 |
-
opponentCardImg
|
| 441 |
-
opponentCardImg.style.visibility = 'visible';
|
| 442 |
} else {
|
| 443 |
-
opponentCardImg
|
| 444 |
}
|
| 445 |
}
|
| 446 |
|
|
@@ -509,8 +543,7 @@
|
|
| 509 |
}
|
| 510 |
|
| 511 |
let name_card_played_by_opp = parsedResponse.pl_1_previous_card.replace(' ', '_') + '.jpg';
|
| 512 |
-
opponentCardImg
|
| 513 |
-
opponentCardImg.style.visibility = 'visible';
|
| 514 |
|
| 515 |
setTimeout(() => {
|
| 516 |
if (counter < 20) {
|
|
|
|
| 395 |
const confirmResignButton = document.getElementById('confirm-resign-button');
|
| 396 |
const cancelResignButton = document.getElementById('cancel-resign-button');
|
| 397 |
|
| 398 |
+
function updateCardImage(imgElement, newSrc) {
|
| 399 |
+
// If no newSrc is provided, just hide the image element.
|
| 400 |
+
if (!newSrc) {
|
| 401 |
+
imgElement.style.visibility = 'hidden';
|
| 402 |
+
return;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
// If the image is already the correct one and is visible, do nothing.
|
| 406 |
+
if (imgElement.src.endsWith(newSrc) && imgElement.style.visibility === 'visible') {
|
| 407 |
+
return;
|
| 408 |
+
}
|
| 409 |
+
|
| 410 |
+
// To prevent flickering, hide the image element first.
|
| 411 |
+
imgElement.style.visibility = 'hidden';
|
| 412 |
+
|
| 413 |
+
// Create a temporary image object to preload the new image.
|
| 414 |
+
const preloader = new Image();
|
| 415 |
+
|
| 416 |
+
// Define what happens once the new image is successfully loaded.
|
| 417 |
+
preloader.onload = () => {
|
| 418 |
+
// Set the source of the actual image element.
|
| 419 |
+
// Since the image is now cached, this will be instantaneous.
|
| 420 |
+
imgElement.src = newSrc;
|
| 421 |
+
// Make the image element visible.
|
| 422 |
+
imgElement.style.visibility = 'visible';
|
| 423 |
+
};
|
| 424 |
+
|
| 425 |
+
// Define what happens if the image fails to load.
|
| 426 |
+
preloader.onerror = () => {
|
| 427 |
+
console.error('Failed to load image:', newSrc);
|
| 428 |
+
// Optionally, you could set a fallback image here.
|
| 429 |
+
};
|
| 430 |
+
|
| 431 |
+
// Set the source of the preloader, which starts the download.
|
| 432 |
+
preloader.src = newSrc;
|
| 433 |
+
}
|
| 434 |
+
|
| 435 |
function set_cards(parsedResponse, length = 3) {
|
| 436 |
let numb_cards = 34 - 2 * counter;
|
| 437 |
document.getElementById('Rounds').innerText = (numb_cards > 0) ? `${numb_cards} Cards Left` : '';
|
|
|
|
| 445 |
const cardString = parsedResponse.my_hand[i];
|
| 446 |
if (cardString && !cardString.includes('The game is over')) {
|
| 447 |
let card_name = cardString.replace(' ', '_') + '.jpg';
|
| 448 |
+
updateCardImage(cardElement, 'static/cards/' + card_name);
|
|
|
|
| 449 |
cardElement.disabled = false;
|
| 450 |
} else {
|
| 451 |
cardElement.style.visibility = 'hidden';
|
|
|
|
| 459 |
|
| 460 |
if (counter == 0) {
|
| 461 |
let briscola_name = parsedResponse.briscola.replace(' ', '_') + '.jpg';
|
| 462 |
+
updateCardImage(document.getElementById('image_briscola'), 'static/cards/' + briscola_name);
|
|
|
|
| 463 |
document.getElementById('title_briscola').innerText = '';
|
| 464 |
}
|
| 465 |
if (counter >= 17) {
|
|
|
|
| 472 |
function opponent_card_appears(parsedResponse) {
|
| 473 |
if (parsedResponse.card_player_1 != 'Not played yet') {
|
| 474 |
let name_card_played_by_opp = parsedResponse.card_player_1.replace(' ', '_') + '.jpg';
|
| 475 |
+
updateCardImage(opponentCardImg, 'static/cards/' + name_card_played_by_opp);
|
|
|
|
| 476 |
} else {
|
| 477 |
+
updateCardImage(opponentCardImg, null);
|
| 478 |
}
|
| 479 |
}
|
| 480 |
|
|
|
|
| 543 |
}
|
| 544 |
|
| 545 |
let name_card_played_by_opp = parsedResponse.pl_1_previous_card.replace(' ', '_') + '.jpg';
|
| 546 |
+
updateCardImage(opponentCardImg, 'static/cards/' + name_card_played_by_opp);
|
|
|
|
| 547 |
|
| 548 |
setTimeout(() => {
|
| 549 |
if (counter < 20) {
|