diff --git a/src/components/ingame/TieC.vue b/src/components/ingame/TieC.vue index 873c33e..1a6eaec 100644 --- a/src/components/ingame/TieC.vue +++ b/src/components/ingame/TieC.vue @@ -4,37 +4,78 @@ import {useIngame} from "@/composables/useIngame.ts"; import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo} from "@/types/GameTypes.ts"; import {useQuasar} from "quasar"; import { ref } from 'vue'; -import { computed } from 'vue' +import { computed, nextTick } from 'vue' const wb = useWebSocket() const wi = useIngame() const tieInf = computed(() => wi.data as TieInfo) -const tieBlankCard = [ - "/images/cards/AS.png" -] +const tieBlankCard = "/images/cards/1B.png" const $q = useQuasar(); function getCardImagePath(cardPath: string) { if (!cardPath) return '' if (cardPath.includes('://') || cardPath.startsWith('/')) return cardPath return `/${cardPath}` } -function selectTie(tieIndex: number) { - wb.sendAndWait("PickTie", { cardIndex: tieIndex }).then( - $q.notify({ - message: "You've successfully picked your tieCard", - color: "positive", - position: "top" - }) - ).catch((error) => { - $q.notify({ - message: error.message, - color: "negative", - position: "top" - }) - }) +function getPlayerName(playerId: string) { + return tieInf.value.tiedPlayers.find(p => p.id === playerId)?.name || 'Player'; } -const model = ref(1) +const myRevealedCard = computed(() => { + const myId = tieInf.value.self?.id; + + if (!myId || !tieInf.value.selectedCards) return null; + + const card = tieInf.value.selectedCards[myId]; + + return card ? getCardImagePath(card.path) : null; +}); + +const isFlipping = ref(false); +const showPickScreen = computed(() => { + const isMyTurn = tieInf.value.self?.id === tieInf.value.currentPlayer?.id; + return isFlipping.value || (isMyTurn && !showResultScreen.value); +}); + +const showResultScreen = computed(() => { + const allPicked = Object.keys(tieInf.value.selectedCards).length === tieInf.value.tiedPlayers.length; + return allPicked && !isFlipping.value; +}); + + +function selectTie(tieIndex: number) { + isFlipping.value = true; + nextTick(() => { + wb.sendAndWait("PickTie", { cardIndex: tieIndex }) + .then(() => { + console.log("Server accepted pick, starting animation..."); + console.log("CARD SELECTED: " + Object.keys(tieInf.value.selectedCards).length) + + + $q.notify({ + message: "Card revealed!", + color: "positive", + position: "top", + timeout: 1000 + }); + + setTimeout(() => { + isFlipping.value = false; + model.value = null; + }, 2500); + }) + .catch((error) => { + isFlipping.value = false; + console.error("Pick failed:", error); + $q.notify({ + message: error.message || "Failed to pick card", + color: "negative", + position: "top" + }); + }); + }); + +} +const model = ref(null) const options = computed(() => { const list = [] const max = tieInf.value.highestAmount?.valueOf() || 0 @@ -47,52 +88,398 @@ const options = computed(() => { diff --git a/src/types/GameTypes.ts b/src/types/GameTypes.ts index 9c3bca5..60b98e6 100644 --- a/src/types/GameTypes.ts +++ b/src/types/GameTypes.ts @@ -5,7 +5,8 @@ import type { PodiumPlayer, Round, Trick, - User + User, + Card } from "@/types/GameSubTypes.ts"; @@ -31,6 +32,8 @@ type TieInfo = { self: Player | null tiedPlayers: Player[] highestAmount: number + selectedCards: Record + winners: Player[] | null } type TrumpInfo = {