@@ -1,3 +1,5 @@
|
||||
var canPlayCard = false;
|
||||
|
||||
function alertMessage(message) {
|
||||
let newHtml = '';
|
||||
const alertId = `alert-${Date.now()}`;
|
||||
@@ -38,7 +40,7 @@ function receiveHandEvent(eventData) {
|
||||
//Build Hand Container
|
||||
hand.forEach((card) => {
|
||||
//Data
|
||||
const idx = card.idx
|
||||
const idx = card.idx;
|
||||
const cardS = card.card;
|
||||
|
||||
const cardHtml = `
|
||||
@@ -157,6 +159,7 @@ function requestCardEvent(eventData) {
|
||||
const player = eventData.player;
|
||||
const handElement = $('#card-slide')
|
||||
handElement.removeClass('inactive');
|
||||
canPlayCard = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +284,7 @@ function receiveTurnEvent(eventData) {
|
||||
|
||||
const currentPlayerNameContainer = $('#current-player-name');
|
||||
const nextPlayersContainer = $('#next-players-container');
|
||||
const nextPlayerText = $('#next-players-section');
|
||||
const nextPlayerText = $('#next-players-text');
|
||||
|
||||
let currentPlayerName = currentPlayer.name;
|
||||
if (currentPlayer.dog) {
|
||||
@@ -293,6 +296,7 @@ function receiveTurnEvent(eventData) {
|
||||
nextPlayerText.hide();
|
||||
nextPlayersContainer.html('');
|
||||
} else {
|
||||
console.log("Length"+nextPlayers.length);
|
||||
nextPlayerText.show();
|
||||
let nextPlayersHtml = '';
|
||||
nextPlayers.forEach((player) => {
|
||||
@@ -300,7 +304,7 @@ function receiveTurnEvent(eventData) {
|
||||
if (player.dog) {
|
||||
playerName += " 🐶";
|
||||
}
|
||||
nextPlayersHtml += `<p className="fs-5 text-primary">${playerName}</p>`;
|
||||
nextPlayersHtml += `<p class="fs-5 text-primary">${playerName}</p>`;
|
||||
});
|
||||
nextPlayersContainer.html(nextPlayersHtml);
|
||||
}
|
||||
|
||||
@@ -1,37 +1,57 @@
|
||||
function handlePlayCard(cardIndex, dog) {
|
||||
function handlePlayCard(card, dog) {
|
||||
|
||||
if(!canPlayCard) return
|
||||
canPlayCard = false;
|
||||
|
||||
const cardId = card.dataset.cardId;
|
||||
|
||||
console.debug(`Playing card ${cardId} from hand`)
|
||||
|
||||
const wiggleKeyframes = [
|
||||
{ transform: 'translateX(0)' },
|
||||
{ transform: 'translateX(-5px)' },
|
||||
{ transform: 'translateX(5px)' },
|
||||
{ transform: 'translateX(-5px)' },
|
||||
{ transform: 'translateX(0)' }
|
||||
];
|
||||
|
||||
const wiggleTiming = {
|
||||
duration: 400,
|
||||
iterations: 1,
|
||||
easing: 'ease-in-out',
|
||||
fill: 'forwards'
|
||||
};
|
||||
|
||||
|
||||
const cardslide = $('#card-slide')
|
||||
cardslide.addClass("inactive")
|
||||
|
||||
const payload = {
|
||||
cardindex: cardIndex,
|
||||
cardindex: cardId,
|
||||
isDog: dog
|
||||
}
|
||||
sendEventAndWait("play Card", payload).then(
|
||||
sendEventAndWait("PlayCard", payload).then(
|
||||
() => {
|
||||
console.debug("play card successful")
|
||||
const datacardid = $(`#${cardIndex}`)
|
||||
datacardid.parent('.handcard').remove();
|
||||
card.parentElement.remove();
|
||||
cardslide.find('.handcard').each(function(newIndex) {
|
||||
|
||||
const $innerButton = $(this).find('.btn');
|
||||
|
||||
$innerButton.attr('id', newIndex);
|
||||
$innerButton.attr('data-card-id', newIndex);
|
||||
|
||||
const isInDogLife = $innerButton.attr('onclick').includes("'true'") ? 'true' : 'false';
|
||||
$innerButton.attr('onclick', `handlePlayCard(${newIndex}, '${isInDogLife}')`);
|
||||
$innerButton.attr('onclick', `handlePlayCard(this, '${isInDogLife}')`);
|
||||
|
||||
console.debug(`Re-indexed card: Old index was ${$innerButton.attr('data-card-id')}, New index is ${newIndex}`);
|
||||
});
|
||||
|
||||
cardslide.addClass("inactive")
|
||||
}
|
||||
).catch(
|
||||
(err) => {
|
||||
canPlayCard = true;
|
||||
const cardslide = $('#card-slide')
|
||||
console.warn("play card was not successful")
|
||||
if (err.message === "You can't play this card!") {
|
||||
cardslide.removeClass("inactive")
|
||||
}
|
||||
alertMessage("You aren't allowed to play this card")
|
||||
cardslide.removeClass("inactive")
|
||||
card.parentElement.animate(wiggleKeyframes, wiggleTiming);
|
||||
alertMessage(err.message)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -40,7 +60,7 @@ function handleSkipDogLife(button) {
|
||||
// TODO needs implementation
|
||||
}
|
||||
function startGame() {
|
||||
sendEvent("Start Game")
|
||||
sendEvent("StartGame")
|
||||
}
|
||||
|
||||
function handleTrumpSelection(object) {
|
||||
@@ -49,8 +69,7 @@ function handleTrumpSelection(object) {
|
||||
const payload = {
|
||||
suitIndex: trumpIndex
|
||||
}
|
||||
console.log("SENDING TRUMP SUIT SELECTION:", payload);
|
||||
sendEvent("Picked Trumpsuit", payload)
|
||||
sendEvent("PickTrumpsuit", payload)
|
||||
|
||||
}
|
||||
function handleKickPlayer(playerId) {
|
||||
|
||||
Reference in New Issue
Block a user