SyntaxSquad/DADProject#16 feat: MATCHES AND STUFF
This commit is contained in:
@@ -1,26 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="relative min-h-screen overflow-hidden bg-green-900">
|
<div class="relative min-h-screen overflow-hidden bg-green-900">
|
||||||
<div v-if="shouldShowBoard && !gameOver" class="absolute top-4 right-4 z-50">
|
<div v-if="shouldShowBoard && !gameOver" class="absolute top-4 right-4 z-50">
|
||||||
<button
|
<button @click="handleSurrender"
|
||||||
@click="handleSurrender"
|
class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-lg shadow-lg border-2 border-red-800 transition-all transform hover:scale-105 flex items-center gap-2">
|
||||||
class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-lg shadow-lg border-2 border-red-800 transition-all transform hover:scale-105 flex items-center gap-2"
|
|
||||||
>
|
|
||||||
<span>🏳️</span> Surrender
|
<span>🏳️</span> Surrender
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="!wsStore.connected && hasConnectedOnce" class="absolute top-4 left-4 z-50 flex items-center gap-2 bg-gray-800 px-4 py-2 rounded-lg border border-gray-700 shadow-xl">
|
<div v-if="!wsStore.connected && hasConnectedOnce"
|
||||||
|
class="absolute top-4 left-4 z-50 flex items-center gap-2 bg-gray-800 px-4 py-2 rounded-lg border border-gray-700 shadow-xl">
|
||||||
<div class="w-3 h-3 rounded-full bg-red-500 animate-pulse"></div>
|
<div class="w-3 h-3 rounded-full bg-red-500 animate-pulse"></div>
|
||||||
<span class="text-white text-sm">Reconnecting...</span>
|
<span class="text-white text-sm">Reconnecting...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="shouldShowBoard && !gameOver && isMyTurn" class="absolute top-4 left-1/2 -translate-x-1/2 z-50">
|
<div v-if="shouldShowBoard && !gameOver && isMyTurn" class="absolute top-4 left-1/2 -translate-x-1/2 z-50">
|
||||||
<div class="bg-gray-800 px-6 py-3 rounded-lg border-2 shadow-xl transition-colors duration-300"
|
<div class="bg-gray-800 px-6 py-3 rounded-lg border-2 shadow-xl transition-colors duration-300"
|
||||||
:class="timeLeft <= 5 ? 'border-red-500 bg-red-900/20' : 'border-gray-700'">
|
:class="timeLeft <= 5 ? 'border-red-500 bg-red-900/20' : 'border-gray-700'">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<svg class="w-6 h-6" :class="timeLeft <= 5 ? 'text-red-500 animate-bounce' : 'text-white'" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
<svg class="w-6 h-6" :class="timeLeft <= 5 ? 'text-red-500 animate-bounce' : 'text-white'" viewBox="0 0 24 24"
|
||||||
<circle cx="12" cy="12" r="10" stroke-width="2"/>
|
fill="none" stroke="currentColor">
|
||||||
<polyline points="12 6 12 12 16 14" stroke-width="2"/>
|
<circle cx="12" cy="12" r="10" stroke-width="2" />
|
||||||
|
<polyline points="12 6 12 12 16 14" stroke-width="2" />
|
||||||
</svg>
|
</svg>
|
||||||
<span :class="['text-3xl font-mono font-bold', timeLeft <= 5 ? 'text-red-500' : 'text-white']">
|
<span :class="['text-3xl font-mono font-bold', timeLeft <= 5 ? 'text-red-500' : 'text-white']">
|
||||||
{{ timeLeft }}
|
{{ timeLeft }}
|
||||||
@@ -30,62 +30,41 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="shouldShowBoard">
|
<div v-if="shouldShowBoard">
|
||||||
<GameBoard
|
<GameBoard :trump-card="trumpCard" :cards-remaining="deckCount + (trumpCard ? 1 : 0)" :player-hand="visibleHand"
|
||||||
:trump-card="trumpCard"
|
:opponent-hand="opponentHand" :player-score="playerScore" :opponent-score="opponentScore"
|
||||||
:cards-remaining="deckCount + (trumpCard ? 1 : 0)"
|
:player-name="myDisplayName" :opponent-name="opponentDisplayName" :current-turn="currentTurnLabel"
|
||||||
|
:current-trick="displayedTrick" :is-my-turn="isMyTurn" @play-card="handlePlayCard" />
|
||||||
:player-hand="visibleHand"
|
|
||||||
:opponent-hand="opponentHand"
|
|
||||||
|
|
||||||
:player-score="playerScore"
|
|
||||||
:opponent-score="opponentScore"
|
|
||||||
|
|
||||||
:player-name="myDisplayName"
|
|
||||||
:opponent-name="opponentDisplayName"
|
|
||||||
:current-turn="currentTurnLabel"
|
|
||||||
|
|
||||||
:current-trick="displayedTrick"
|
|
||||||
:is-my-turn="isMyTurn"
|
|
||||||
@play-card="handlePlayCard"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else-if="!gameOver" class="flex h-screen items-center justify-center bg-green-900 text-white">
|
<div v-else-if="!gameOver" class="flex h-screen items-center justify-center bg-green-900 text-white">
|
||||||
<div class="text-center p-8 bg-green-800/50 rounded-2xl border border-green-700 shadow-2xl backdrop-blur-sm">
|
<div class="text-center p-8 bg-green-800/50 rounded-2xl border border-green-700 shadow-2xl backdrop-blur-sm">
|
||||||
<div class="relative mx-auto mb-6 h-16 w-16">
|
<div class="relative mx-auto mb-6 h-16 w-16">
|
||||||
<div class="absolute inset-0 rounded-full border-4 border-green-600"></div>
|
<div class="absolute inset-0 rounded-full border-4 border-green-600"></div>
|
||||||
<div class="absolute inset-0 rounded-full border-4 border-t-white border-r-transparent border-b-transparent border-l-transparent animate-spin"></div>
|
<div
|
||||||
|
class="absolute inset-0 rounded-full border-4 border-t-white border-r-transparent border-b-transparent border-l-transparent animate-spin">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="text-2xl font-bold mb-2">
|
<h2 class="text-2xl font-bold mb-2">
|
||||||
Waiting for Opponent...
|
Waiting for Opponent...
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<p class="text-green-100 mb-8 max-w-sm">
|
<p class="text-green-100 mb-8 max-w-sm">
|
||||||
Share the game code or wait for a player to join your lobby.
|
Share the game code or wait for a player to join your lobby.
|
||||||
</p>
|
</p>
|
||||||
|
<div class="bg-black/20 p-3 rounded mb-6 font-mono text-sm border border-white/10 text-green-100">
|
||||||
<button
|
Match ID: <span class="font-bold text-white">{{ matchState.id }}</span>
|
||||||
@click="handleCloseModal"
|
</div>
|
||||||
class="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-lg font-semibold transition-all shadow-lg hover:shadow-red-500/20"
|
<button @click="handleCloseModal"
|
||||||
>
|
class="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-lg font-semibold transition-all shadow-lg hover:shadow-red-500/20">
|
||||||
Cancel & Return Home
|
Cancel & Return Home
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<GameOver
|
<GameOver :is-visible="gameOver" :winner="winnerResult" :player-score="playerScore" :opponent-score="opponentScore"
|
||||||
:is-visible="gameOver"
|
:player-name="myDisplayName" :opponent-name="opponentDisplayName" :stats="{ playerTricks: 0, opponentTricks: 0 }"
|
||||||
:winner="winnerResult"
|
:is-logging-out="false" @play-again="handleCloseModal" @close="handleCloseModal" />
|
||||||
:player-score="playerScore"
|
|
||||||
:opponent-score="opponentScore"
|
|
||||||
:player-name="myDisplayName"
|
|
||||||
:opponent-name="opponentDisplayName"
|
|
||||||
:stats="{ playerTricks: 0, opponentTricks: 0 }"
|
|
||||||
:is-logging-out="false"
|
|
||||||
@play-again="handleCloseModal"
|
|
||||||
@close="handleCloseModal"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -115,11 +94,14 @@ const timeLeft = ref(20)
|
|||||||
const timerInterval = ref(null)
|
const timerInterval = ref(null)
|
||||||
const hasConnectedOnce = ref(false)
|
const hasConnectedOnce = ref(false)
|
||||||
|
|
||||||
|
// --- STATE ---
|
||||||
|
const matchState = computed(() => wsStore.gameState || { id: gameId.value })
|
||||||
|
|
||||||
const gameMetadata = ref({
|
const gameMetadata = ref({
|
||||||
p1_id: null,
|
p1_id: null,
|
||||||
p1_name: 'Player 1',
|
p1_name: 'Player 1',
|
||||||
p2_id: null,
|
p2_id: null,
|
||||||
p2_name: 'Opponent'
|
p2_name: 'Opponent'
|
||||||
})
|
})
|
||||||
|
|
||||||
const displayedTrick = ref({ playerCard: null, opponentCard: null })
|
const displayedTrick = ref({ playerCard: null, opponentCard: null })
|
||||||
@@ -130,38 +112,38 @@ const trickClearTimer = ref(null)
|
|||||||
const myUserId = computed(() => authStore.currentUser?.id)
|
const myUserId = computed(() => authStore.currentUser?.id)
|
||||||
|
|
||||||
const shouldShowBoard = computed(() => {
|
const shouldShowBoard = computed(() => {
|
||||||
const s = wsStore.gameState;
|
const s = wsStore.gameState;
|
||||||
if (s && s.player2 && s.player2.id > 1) {
|
if (s && s.player2 && s.player2.id > 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
})
|
})
|
||||||
|
|
||||||
const amIHost = computed(() => {
|
const amIHost = computed(() => {
|
||||||
if (gameMetadata.value.p1_id) {
|
if (gameMetadata.value.p1_id) {
|
||||||
return String(gameMetadata.value.p1_id) === String(myUserId.value)
|
return String(gameMetadata.value.p1_id) === String(myUserId.value)
|
||||||
}
|
}
|
||||||
const p1Id = wsStore.gameState?.player1_user_id || wsStore.gameState?.player1?.id
|
const p1Id = wsStore.gameState?.player1_user_id || wsStore.gameState?.player1?.id
|
||||||
return String(p1Id) === String(myUserId.value)
|
return String(p1Id) === String(myUserId.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const myDisplayName = computed(() => amIHost.value ? gameMetadata.value.p1_name : gameMetadata.value.p2_name)
|
const myDisplayName = computed(() => amIHost.value ? gameMetadata.value.p1_name : gameMetadata.value.p2_name)
|
||||||
const opponentDisplayName = computed(() => amIHost.value ? gameMetadata.value.p2_name : gameMetadata.value.p1_name)
|
const opponentDisplayName = computed(() => amIHost.value ? gameMetadata.value.p2_name : gameMetadata.value.p1_name)
|
||||||
|
|
||||||
const mappedTrick = computed(() => {
|
const mappedTrick = computed(() => {
|
||||||
const table = wsStore.gameState?.table
|
const table = wsStore.gameState?.table
|
||||||
if (!table) return { playerCard: null, opponentCard: null }
|
if (!table) return { playerCard: null, opponentCard: null }
|
||||||
if (amIHost.value) {
|
if (amIHost.value) {
|
||||||
return { playerCard: table.playerCard, opponentCard: table.opponentCard }
|
return { playerCard: table.playerCard, opponentCard: table.opponentCard }
|
||||||
} else {
|
} else {
|
||||||
return { playerCard: table.opponentCard, opponentCard: table.playerCard }
|
return { playerCard: table.opponentCard, opponentCard: table.playerCard }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const currentTurnLabel = computed(() => {
|
const currentTurnLabel = computed(() => {
|
||||||
const turnId = wsStore.gameState?.currentTurn
|
const turnId = wsStore.gameState?.currentTurn
|
||||||
if (!turnId) return 'player'
|
if (!turnId) return 'player'
|
||||||
return String(turnId) === String(myUserId.value) ? 'player' : 'opponent'
|
return String(turnId) === String(myUserId.value) ? 'player' : 'opponent'
|
||||||
})
|
})
|
||||||
|
|
||||||
const trumpCard = computed(() => wsStore.gameState?.trumpCard || null)
|
const trumpCard = computed(() => wsStore.gameState?.trumpCard || null)
|
||||||
@@ -178,34 +160,34 @@ const opponentHand = computed(() => {
|
|||||||
// --- WATCHERS ---
|
// --- WATCHERS ---
|
||||||
|
|
||||||
watch(() => wsStore.connected, (isConnected) => {
|
watch(() => wsStore.connected, (isConnected) => {
|
||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
hasConnectedOnce.value = true
|
hasConnectedOnce.value = true
|
||||||
wsStore.joinGame(gameId.value)
|
wsStore.joinGame(gameId.value)
|
||||||
}
|
}
|
||||||
}, { immediate: true })
|
}, { immediate: true })
|
||||||
|
|
||||||
watch(() => wsStore.gameState, async (newState, oldState) => {
|
watch(() => wsStore.gameState, async (newState, oldState) => {
|
||||||
const oldP2 = oldState?.player2?.id;
|
const oldP2 = oldState?.player2?.id;
|
||||||
const newP2 = newState?.player2?.id;
|
const newP2 = newState?.player2?.id;
|
||||||
if (newP2 && newP2 > 1 && newP2 !== oldP2) {
|
if (newP2 && newP2 > 1 && newP2 !== oldP2) {
|
||||||
await fetchGameMetadata();
|
await fetchGameMetadata();
|
||||||
}
|
}
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
watch(mappedTrick, (newVal) => {
|
watch(mappedTrick, (newVal) => {
|
||||||
if (newVal.playerCard || newVal.opponentCard) {
|
if (newVal.playerCard || newVal.opponentCard) {
|
||||||
if (trickClearTimer.value) clearTimeout(trickClearTimer.value)
|
if (trickClearTimer.value) clearTimeout(trickClearTimer.value)
|
||||||
displayedTrick.value = { ...newVal }
|
displayedTrick.value = { ...newVal }
|
||||||
|
} else {
|
||||||
|
const currentlyShowing = displayedTrick.value.playerCard || displayedTrick.value.opponentCard
|
||||||
|
if (currentlyShowing) {
|
||||||
|
trickClearTimer.value = setTimeout(() => {
|
||||||
|
displayedTrick.value = { playerCard: null, opponentCard: null }
|
||||||
|
}, 1500)
|
||||||
} else {
|
} else {
|
||||||
const currentlyShowing = displayedTrick.value.playerCard || displayedTrick.value.opponentCard
|
displayedTrick.value = { playerCard: null, opponentCard: null }
|
||||||
if (currentlyShowing) {
|
|
||||||
trickClearTimer.value = setTimeout(() => {
|
|
||||||
displayedTrick.value = { playerCard: null, opponentCard: null }
|
|
||||||
}, 1500)
|
|
||||||
} else {
|
|
||||||
displayedTrick.value = { playerCard: null, opponentCard: null }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
// --- FIX: TIMER GHOSTING ---
|
// --- FIX: TIMER GHOSTING ---
|
||||||
@@ -213,8 +195,8 @@ const startTimer = () => {
|
|||||||
if (timerInterval.value) clearInterval(timerInterval.value)
|
if (timerInterval.value) clearInterval(timerInterval.value)
|
||||||
|
|
||||||
if (!shouldShowBoard.value && wsStore.gameState?.status !== 'playing') {
|
if (!shouldShowBoard.value && wsStore.gameState?.status !== 'playing') {
|
||||||
timeLeft.value = 20;
|
timeLeft.value = 20;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FORCE RESET to avoid showing old time for 1 frame
|
// FORCE RESET to avoid showing old time for 1 frame
|
||||||
@@ -238,44 +220,44 @@ const startTimer = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch(() => wsStore.gameState?.currentTurn, (newTurn) => {
|
watch(() => wsStore.gameState?.currentTurn, (newTurn) => {
|
||||||
if (newTurn) startTimer()
|
if (newTurn) startTimer()
|
||||||
}, { immediate: true })
|
}, { immediate: true })
|
||||||
|
|
||||||
const animateDeal = async (cards) => {
|
const animateDeal = async (cards) => {
|
||||||
if (isDealing.value) return
|
if (isDealing.value) return
|
||||||
isDealing.value = true
|
isDealing.value = true
|
||||||
visibleHand.value = []
|
visibleHand.value = []
|
||||||
for (const card of cards) {
|
for (const card of cards) {
|
||||||
visibleHand.value.push(card)
|
visibleHand.value.push(card)
|
||||||
await new Promise(r => setTimeout(r, 150))
|
await new Promise(r => setTimeout(r, 150))
|
||||||
}
|
}
|
||||||
isDealing.value = false
|
isDealing.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(serverHand, (newHand) => {
|
watch(serverHand, (newHand) => {
|
||||||
if (visibleHand.value.length === 0 && newHand.length > 0 && !hasInitialDealHappened.value) {
|
if (visibleHand.value.length === 0 && newHand.length > 0 && !hasInitialDealHappened.value) {
|
||||||
animateDeal(newHand)
|
animateDeal(newHand)
|
||||||
hasInitialDealHappened.value = true
|
hasInitialDealHappened.value = true
|
||||||
} else if (!isDealing.value) {
|
} else if (!isDealing.value) {
|
||||||
visibleHand.value = [...newHand]
|
visibleHand.value = [...newHand]
|
||||||
}
|
}
|
||||||
}, { deep: true })
|
}, { deep: true })
|
||||||
|
|
||||||
// --- METHODS ---
|
// --- METHODS ---
|
||||||
|
|
||||||
const fetchGameMetadata = async () => {
|
const fetchGameMetadata = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/games/${gameId.value}`)
|
const response = await axios.get(`${API_BASE_URL}/games/${gameId.value}`)
|
||||||
const game = response.data.data || response.data
|
const game = response.data.data || response.data
|
||||||
gameMetadata.value = {
|
gameMetadata.value = {
|
||||||
p1_id: game.player1_user_id,
|
p1_id: game.player1_user_id,
|
||||||
p1_name: game.player1?.nickname || 'Host',
|
p1_name: game.player1?.nickname || 'Host',
|
||||||
p2_id: game.player2_user_id,
|
p2_id: game.player2_user_id,
|
||||||
p2_name: game.player2?.nickname || 'Opponent'
|
p2_name: game.player2?.nickname || 'Opponent'
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to load metadata", e)
|
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to load metadata", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handlePlayCard = (card) => {
|
const handlePlayCard = (card) => {
|
||||||
@@ -293,31 +275,31 @@ const handleBeforeUnload = (event) => {
|
|||||||
|
|
||||||
// --- FIX: SURRENDER LOGIC ---
|
// --- FIX: SURRENDER LOGIC ---
|
||||||
const handleSurrender = () => {
|
const handleSurrender = () => {
|
||||||
if(confirm('Are you sure you want to surrender? You will lose.')) {
|
if (confirm('Are you sure you want to surrender? You will lose.')) {
|
||||||
wsStore.surrender(gameId.value)
|
wsStore.surrender(gameId.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCloseModal = async () => {
|
const handleCloseModal = async () => {
|
||||||
// 1. If game is still in Lobby (Pending) and I am the Host, DELETE it.
|
// 1. If game is still in Lobby (Pending) and I am the Host, DELETE it.
|
||||||
if (!shouldShowBoard.value && amIHost.value && !gameOver.value) {
|
if (!shouldShowBoard.value && amIHost.value && !gameOver.value) {
|
||||||
try {
|
try {
|
||||||
// This calls Route::delete('/{game}', ...) in your api.php
|
// This calls Route::delete('/{game}', ...) in your api.php
|
||||||
await axios.delete(`${API_BASE_URL}/games/${gameId.value}`);
|
await axios.delete(`${API_BASE_URL}/games/${gameId.value}`);
|
||||||
console.log("Lobby cancelled and deleted.");
|
console.log("Lobby cancelled and deleted.");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Failed to delete pending game:", e);
|
console.error("Failed to delete pending game:", e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Notify server of voluntary exit (to skip the 10s reconnect timer)
|
// 2. Notify server of voluntary exit (to skip the 10s reconnect timer)
|
||||||
if (wsStore.socket) {
|
if (wsStore.socket) {
|
||||||
wsStore.socket.emit('notify_disconnect');
|
wsStore.socket.emit('notify_disconnect');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Disconnect and go home
|
// 3. Disconnect and go home
|
||||||
wsStore.disconnect();
|
wsStore.disconnect();
|
||||||
router.push({ name: 'home' });
|
router.push({ name: 'home' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- LIFECYCLE ---
|
// --- LIFECYCLE ---
|
||||||
@@ -325,29 +307,29 @@ const handleCloseModal = async () => {
|
|||||||
onBeforeRouteLeave(async (to, from, next) => {
|
onBeforeRouteLeave(async (to, from, next) => {
|
||||||
// CASE A: Game is Pending (Waiting Room)
|
// CASE A: Game is Pending (Waiting Room)
|
||||||
if (!shouldShowBoard.value && !gameOver.value) {
|
if (!shouldShowBoard.value && !gameOver.value) {
|
||||||
if (amIHost.value) {
|
if (amIHost.value) {
|
||||||
// Ask for confirmation to close the lobby
|
// Ask for confirmation to close the lobby
|
||||||
const confirmClose = window.confirm("This will cancel the lobby. Are you sure?");
|
const confirmClose = window.confirm("This will cancel the lobby. Are you sure?");
|
||||||
if (confirmClose) {
|
if (confirmClose) {
|
||||||
try {
|
try {
|
||||||
// Delete the game from DB so it doesn't get stuck as "Pending"
|
// Delete the game from DB so it doesn't get stuck as "Pending"
|
||||||
await axios.delete(`${API_BASE_URL}/games/${gameId.value}`);
|
await axios.delete(`${API_BASE_URL}/games/${gameId.value}`);
|
||||||
} catch(e) { console.error(e) }
|
} catch (e) { console.error(e) }
|
||||||
|
|
||||||
if(wsStore.socket) wsStore.socket.emit('notify_disconnect');
|
if (wsStore.socket) wsStore.socket.emit('notify_disconnect');
|
||||||
wsStore.disconnect();
|
wsStore.disconnect();
|
||||||
next();
|
next();
|
||||||
} else {
|
} else {
|
||||||
next(false); // Stay on page
|
next(false); // Stay on page
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
// If I am NOT host (just a guest waiting), just leave
|
// If I am NOT host (just a guest waiting), just leave
|
||||||
if(wsStore.socket) wsStore.socket.emit('notify_disconnect');
|
if (wsStore.socket) wsStore.socket.emit('notify_disconnect');
|
||||||
wsStore.disconnect();
|
wsStore.disconnect();
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CASE B: Game is Over (Standard exit)
|
// CASE B: Game is Over (Standard exit)
|
||||||
@@ -363,15 +345,15 @@ onBeforeRouteLeave(async (to, from, next) => {
|
|||||||
|
|
||||||
if (answer) {
|
if (answer) {
|
||||||
// ... (Your existing surrender logic) ...
|
// ... (Your existing surrender logic) ...
|
||||||
try { await wsStore.surrender(gameId.value); } catch (e) {}
|
try { await wsStore.surrender(gameId.value); } catch (e) { }
|
||||||
|
|
||||||
if (wsStore.socket) {
|
if (wsStore.socket) {
|
||||||
wsStore.socket.emit('notify_disconnect', () => {
|
wsStore.socket.emit('notify_disconnect', () => {
|
||||||
wsStore.disconnect();
|
wsStore.disconnect();
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
setTimeout(() => { if (wsStore.connected) { wsStore.disconnect(); next(); } }, 500);
|
setTimeout(() => { if (wsStore.connected) { wsStore.disconnect(); next(); } }, 500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wsStore.disconnect();
|
wsStore.disconnect();
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -1,112 +1,362 @@
|
|||||||
|
<script setup>
|
||||||
|
import { ref, onMounted, computed, inject, onUnmounted, watch } from 'vue'
|
||||||
|
import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router'
|
||||||
|
import { useAuthStore } from '@/stores/auth'
|
||||||
|
import { useSocketStore } from '@/stores/socket'
|
||||||
|
import { Coins, Trophy, Frown } from 'lucide-vue-next'
|
||||||
|
import { Button } from '@/components/ui/button'
|
||||||
|
import GameBoard from '@/components/game/GameBoard.vue'
|
||||||
|
import axios from 'axios'
|
||||||
|
import { toast } from 'vue-sonner'
|
||||||
|
|
||||||
|
const API_BASE_URL = inject('apiBaseURL')
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
const wsStore = useSocketStore()
|
||||||
|
|
||||||
|
// --- FIX: Flag to prevent double cancellation ---
|
||||||
|
const isCancelling = ref(false)
|
||||||
|
|
||||||
|
const matchState = ref({
|
||||||
|
id: route.params.id,
|
||||||
|
wager: 0,
|
||||||
|
myMarks: 0,
|
||||||
|
oppMarks: 0,
|
||||||
|
currentGameId: null,
|
||||||
|
player1: null,
|
||||||
|
player2: null,
|
||||||
|
status: 'Pending'
|
||||||
|
})
|
||||||
|
|
||||||
|
const timeLeft = ref(20)
|
||||||
|
const timerInterval = ref(null)
|
||||||
|
const showSurrenderModal = ref(false)
|
||||||
|
const showTrickResult = ref(false)
|
||||||
|
const lastTrickWinner = ref(null)
|
||||||
|
const showRoundModal = ref(false)
|
||||||
|
const roundData = ref({ winnerId: null, marksAdded: 0, myPoints: 0, oppPoints: 0, reason: '' })
|
||||||
|
|
||||||
|
const myUserId = computed(() => authStore.currentUser?.id)
|
||||||
|
const amIHost = computed(() => matchState.value.player1?.id === myUserId.value)
|
||||||
|
const isPending = computed(() => !matchState.value.player2 || matchState.value.player2.id <= 1)
|
||||||
|
const matchOver = computed(() => matchState.value.myMarks >= 4 || matchState.value.oppMarks >= 4)
|
||||||
|
const iWonMatch = computed(() => matchState.value.myMarks > matchState.value.oppMarks)
|
||||||
|
const isMyTurn = computed(() => String(wsStore.gameState?.currentTurn) === String(myUserId.value))
|
||||||
|
const currentTurnLabel = computed(() => isMyTurn.value ? 'player' : 'opponent')
|
||||||
|
|
||||||
|
const myDisplayName = computed(() => amIHost.value ? matchState.value.player1?.nickname : matchState.value.player2?.nickname)
|
||||||
|
const opponentDisplayName = computed(() => amIHost.value ? matchState.value.player2?.nickname : matchState.value.player1?.nickname)
|
||||||
|
|
||||||
|
const opponentHand = computed(() => {
|
||||||
|
const count = wsStore.gameState?.opponent?.cardCount || 0
|
||||||
|
return Array.from({ length: count }, (_, i) => ({ id: `opp-${i}`, suit: 'back', rank: 0 }))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Timer
|
||||||
|
watch(() => wsStore.gameState?.currentTurn, () => { startTimer() }, { deep: true })
|
||||||
|
const startTimer = () => {
|
||||||
|
if (timerInterval.value) clearInterval(timerInterval.value);
|
||||||
|
timeLeft.value = 20;
|
||||||
|
if(!wsStore.gameState) return;
|
||||||
|
timerInterval.value = setInterval(() => {
|
||||||
|
if(timeLeft.value > 0) timeLeft.value--;
|
||||||
|
else clearInterval(timerInterval.value);
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
const handlePlayCard = (card) => {
|
||||||
|
if (wsStore.socket) wsStore.socket.emit('game:play-card', { matchId: matchState.value.id, cardId: card.id })
|
||||||
|
}
|
||||||
|
|
||||||
|
const openSurrenderModal = () => { showSurrenderModal.value = true }
|
||||||
|
const confirmSurrenderRound = () => {
|
||||||
|
showSurrenderModal.value = false;
|
||||||
|
if (wsStore.socket) wsStore.socket.emit('game:surrender', { matchId: matchState.value.id });
|
||||||
|
}
|
||||||
|
const confirmSurrenderMatch = () => {
|
||||||
|
showSurrenderModal.value = false;
|
||||||
|
if (wsStore.socket) wsStore.socket.emit('match:surrender', { matchId: matchState.value.id });
|
||||||
|
}
|
||||||
|
const closeRoundModal = () => { showRoundModal.value = false; }
|
||||||
|
|
||||||
|
const updateLocalState = (data) => {
|
||||||
|
if (!data) return
|
||||||
|
if (data.player1) matchState.value.player1 = data.player1
|
||||||
|
if (data.player2) matchState.value.player2 = data.player2
|
||||||
|
if (data.stake) matchState.value.wager = data.stake
|
||||||
|
matchState.value.status = data.status
|
||||||
|
|
||||||
|
if (data.marks) {
|
||||||
|
const myId = authStore.currentUser?.id;
|
||||||
|
const oppId = amIHost.value ? matchState.value.player2?.id : matchState.value.player1?.id;
|
||||||
|
matchState.value.myMarks = data.marks[myId] || 0;
|
||||||
|
matchState.value.oppMarks = data.marks[oppId] || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.game) {
|
||||||
|
matchState.value.currentGameId = data.game.id;
|
||||||
|
wsStore.gameState = data.game;
|
||||||
|
} else if (data.status === 'Playing') {
|
||||||
|
matchState.value.currentGameId = null;
|
||||||
|
wsStore.gameState = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- FIX: Cancel Match with Flag ---
|
||||||
|
const cancelMatch = async () => {
|
||||||
|
if (isCancelling.value) return;
|
||||||
|
isCancelling.value = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await axios.delete(`${API_BASE_URL}/matches/${matchState.value.id}`)
|
||||||
|
router.push({ name: 'home' })
|
||||||
|
} catch (e) {
|
||||||
|
// Ignore 404s if we just deleted it
|
||||||
|
if (e.response && e.response.status === 404) {
|
||||||
|
router.push({ name: 'home' })
|
||||||
|
} else {
|
||||||
|
isCancelling.value = false; // Reset if legitimate error
|
||||||
|
alert(e.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const leaveMatch = () => router.push({ name: 'home' })
|
||||||
|
|
||||||
|
const handleBeforeUnload = (e) => {
|
||||||
|
if (matchState.value.status === 'Playing' && !matchOver.value) {
|
||||||
|
const msg = "If you leave now, you will lose the match and your wager.";
|
||||||
|
e.returnValue = msg;
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- FIX: Router Guard checks Flag ---
|
||||||
|
onBeforeRouteLeave((to, from, next) => {
|
||||||
|
// If we already clicked cancel, just let it go
|
||||||
|
if (isCancelling.value) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matchState.value.status === 'Playing' && !matchOver.value) {
|
||||||
|
if (confirm("⚠️ WARNING: Leaving now triggers an automatic match surrender (Loss).\n\nAre you sure?")) {
|
||||||
|
if(wsStore.socket) wsStore.socket.emit('match:surrender', { matchId: matchState.value.id });
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
next(false);
|
||||||
|
}
|
||||||
|
} else if (isPending.value && amIHost.value) {
|
||||||
|
if(confirm("Cancel this lobby?")) {
|
||||||
|
// Mark as cancelling so we don't trigger double requests if cancelMatch is weird
|
||||||
|
isCancelling.value = true;
|
||||||
|
cancelMatch().then(() => next());
|
||||||
|
} else {
|
||||||
|
next(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
window.addEventListener('beforeunload', handleBeforeUnload)
|
||||||
|
try {
|
||||||
|
const res = await axios.get(`${API_BASE_URL}/matches/${matchState.value.id}`)
|
||||||
|
const d = res.data.data || res.data
|
||||||
|
matchState.value.player1 = d.player1
|
||||||
|
matchState.value.player2 = d.player2
|
||||||
|
matchState.value.wager = d.stake
|
||||||
|
} catch (e) { }
|
||||||
|
|
||||||
|
wsStore.connect()
|
||||||
|
if (wsStore.socket) {
|
||||||
|
wsStore.socket.emit('match:enter', { matchId: matchState.value.id })
|
||||||
|
wsStore.socket.on('match:update', updateLocalState)
|
||||||
|
wsStore.socket.on('match:new-round', (data) => {
|
||||||
|
updateLocalState(data);
|
||||||
|
toast.info("New round started!");
|
||||||
|
})
|
||||||
|
wsStore.socket.on('match:ended', updateLocalState)
|
||||||
|
wsStore.socket.on('game:update', (state) => { wsStore.gameState = state })
|
||||||
|
wsStore.socket.on('game:trick-end', (result) => {
|
||||||
|
lastTrickWinner.value = result.winnerId;
|
||||||
|
showTrickResult.value = true;
|
||||||
|
setTimeout(() => { showTrickResult.value = false }, 2000);
|
||||||
|
});
|
||||||
|
wsStore.socket.on('match:round-ended', (data) => {
|
||||||
|
const myPoints = data.winnerId == myUserId.value ? (data.winnerId == matchState.value.player1.id ? data.p1Points : data.p2Points) : (data.winnerId == matchState.value.player1.id ? data.p2Points : data.p1Points);
|
||||||
|
const oppPoints = data.winnerId != myUserId.value ? (data.winnerId == matchState.value.player1.id ? data.p1Points : data.p2Points) : (data.winnerId == matchState.value.player1.id ? data.p2Points : data.p1Points);
|
||||||
|
|
||||||
|
roundData.value = {
|
||||||
|
winnerId: data.winnerId,
|
||||||
|
marksAdded: data.marksAdded,
|
||||||
|
myPoints: myPoints,
|
||||||
|
oppPoints: oppPoints,
|
||||||
|
reason: data.reason
|
||||||
|
};
|
||||||
|
showRoundModal.value = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
window.removeEventListener('beforeunload', handleBeforeUnload)
|
||||||
|
if (wsStore.socket) {
|
||||||
|
wsStore.socket.off('match:update')
|
||||||
|
wsStore.socket.off('match:new-round')
|
||||||
|
wsStore.socket.off('game:trick-end')
|
||||||
|
wsStore.socket.off('match:round-ended')
|
||||||
|
}
|
||||||
|
wsStore.disconnect()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="relative min-h-screen bg-slate-950 text-white">
|
<div class="relative min-h-screen bg-green-900 text-white overflow-hidden">
|
||||||
|
<div class="fixed top-0 left-0 right-0 z-40 bg-green-950/90 backdrop-blur border-b border-green-800 p-2 shadow-xl">
|
||||||
<div class="fixed top-0 left-0 right-0 z-40 bg-slate-900/90 backdrop-blur border-b border-slate-700 p-2 shadow-lg">
|
<div class="max-w-4xl mx-auto flex items-center justify-between">
|
||||||
<div class="max-w-4xl mx-auto flex items-center justify-between">
|
<div class="flex flex-col items-start">
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
<div class="flex flex-col items-start">
|
<span class="font-bold text-lg text-white drop-shadow-md">{{ myDisplayName }}</span>
|
||||||
<div class="flex items-center gap-2">
|
<span v-if="matchState.wager > 0" class="flex items-center text-xs text-yellow-300 bg-yellow-900/50 px-2 rounded border border-yellow-700/50">
|
||||||
<span class="font-bold text-lg text-blue-400">{{ myName }}</span>
|
<Coins class="w-3 h-3 mr-1" /> {{ matchState.wager }}
|
||||||
<span v-if="matchState.wager > 0" class="flex items-center text-xs text-yellow-400 bg-yellow-400/10 px-2 rounded">
|
</span>
|
||||||
<Coins class="w-3 h-3 mr-1" /> {{ matchState.wager }}
|
</div>
|
||||||
</span>
|
<div class="flex gap-1 mt-1">
|
||||||
</div>
|
<div v-for="i in 4" :key="i" class="w-3 h-3 rounded-full border border-green-400 bg-green-900"
|
||||||
<div class="flex gap-1 mt-1">
|
:class="{ '!bg-green-400 shadow-[0_0_10px_rgba(74,222,128,0.5)]': matchState.myMarks >= i }"></div>
|
||||||
<div class="w-3 h-3 rounded-full border border-blue-500"
|
</div>
|
||||||
:class="{ 'bg-blue-500': matchState.myWins >= 1 }"></div>
|
|
||||||
<div class="w-3 h-3 rounded-full border border-blue-500"
|
|
||||||
:class="{ 'bg-blue-500': matchState.myWins >= 2 }"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col items-center">
|
|
||||||
<span class="text-xs uppercase tracking-widest text-slate-400">Match {{ matchState.id }}</span>
|
|
||||||
<span class="text-xl font-black font-mono">
|
|
||||||
{{ matchState.myWins }} - {{ matchState.oppWins }}
|
|
||||||
</span>
|
|
||||||
<span class="text-[10px] text-slate-500">Best of 3</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex flex-col items-end">
|
|
||||||
<span class="font-bold text-lg text-red-400">{{ opponentName }}</span>
|
|
||||||
<div class="flex gap-1 mt-1">
|
|
||||||
<div class="w-3 h-3 rounded-full border border-red-500"
|
|
||||||
:class="{ 'bg-red-500': matchState.oppWins >= 1 }"></div>
|
|
||||||
<div class="w-3 h-3 rounded-full border border-red-500"
|
|
||||||
:class="{ 'bg-red-500': matchState.oppWins >= 2 }"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex flex-col items-center">
|
||||||
|
<span class="text-[10px] uppercase tracking-widest text-green-400 font-bold">Match #{{ matchState.id }}</span>
|
||||||
|
<span class="text-2xl font-black font-mono text-white drop-shadow-md">{{ matchState.myMarks }} - {{ matchState.oppMarks }}</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex flex-col items-end">
|
||||||
|
<span class="font-bold text-lg text-white drop-shadow-md">{{ opponentDisplayName }}</span>
|
||||||
|
<div class="flex gap-1 mt-1">
|
||||||
|
<div v-for="i in 4" :key="i" class="w-3 h-3 rounded-full border border-red-400 bg-green-900"
|
||||||
|
:class="{ '!bg-red-500 shadow-[0_0_10px_rgba(239,68,68,0.5)]': matchState.oppMarks >= i }"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="wsStore.gameState && !matchOver" class="absolute top-24 right-4 z-50">
|
||||||
|
<button @click="openSurrenderModal" class="bg-red-600 hover:bg-red-700 text-white font-bold py-2 px-4 rounded-lg shadow-lg border-2 border-red-800 transition-all hover:scale-105 flex items-center gap-2 text-sm cursor-pointer">
|
||||||
|
<span>🏳️</span> Surrender
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="wsStore.gameState && !matchOver && isMyTurn" class="absolute top-24 left-1/2 -translate-x-1/2 z-50">
|
||||||
|
<div class="bg-gray-800 px-6 py-2 rounded-lg border-2 shadow-xl transition-colors duration-300" :class="timeLeft <= 5 ? 'border-red-500 bg-red-900/20' : 'border-gray-700'">
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<svg class="w-5 h-5" :class="timeLeft <= 5 ? 'text-red-500 animate-bounce' : 'text-white'" viewBox="0 0 24 24" fill="none" stroke="currentColor">
|
||||||
|
<circle cx="12" cy="12" r="10" stroke-width="2" />
|
||||||
|
<polyline points="12 6 12 12 16 14" stroke-width="2" />
|
||||||
|
</svg>
|
||||||
|
<span :class="['text-2xl font-mono font-bold', timeLeft <= 5 ? 'text-red-500' : 'text-white']">{{ timeLeft }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pt-20 h-screen">
|
<div class="pt-20 h-screen">
|
||||||
<GameBoard
|
<GameBoard
|
||||||
v-if="matchState.currentGameId && !matchOver"
|
v-if="wsStore.gameState && !matchOver"
|
||||||
:game-id="matchState.currentGameId"
|
:game-id="matchState.currentGameId"
|
||||||
@game-end="handleGameEnd"
|
@play-card="handlePlayCard"
|
||||||
/>
|
:trump-card="wsStore.gameState?.trumpCard"
|
||||||
|
:cards-remaining="wsStore.gameState?.deckCount"
|
||||||
<div v-else-if="!matchOver" class="flex h-full items-center justify-center flex-col gap-4">
|
:player-hand="wsStore.gameState?.hand"
|
||||||
<div class="text-2xl font-bold animate-pulse">Preparing next round...</div>
|
:opponent-hand="opponentHand"
|
||||||
<p class="text-slate-400">Switching sides and shuffling deck</p>
|
:player-score="wsStore.gameState?.points"
|
||||||
|
:opponent-score="wsStore.gameState?.opponent?.points"
|
||||||
|
:current-turn="currentTurnLabel"
|
||||||
|
:current-trick="wsStore.gameState?.table"
|
||||||
|
:is-my-turn="isMyTurn"
|
||||||
|
:player-name="myDisplayName"
|
||||||
|
:opponent-name="opponentDisplayName"
|
||||||
|
/>
|
||||||
|
<div v-else-if="isPending" class="flex h-full items-center justify-center flex-col gap-6">
|
||||||
|
<div class="text-center p-8 bg-green-800/60 rounded-2xl border border-green-600 shadow-2xl backdrop-blur-md max-w-sm w-full mx-4">
|
||||||
|
<div class="relative mx-auto mb-6 h-16 w-16">
|
||||||
|
<div class="absolute inset-0 rounded-full border-4 border-green-700/50"></div>
|
||||||
|
<div class="absolute inset-0 rounded-full border-4 border-t-white border-r-transparent border-b-transparent border-l-transparent animate-spin"></div>
|
||||||
|
</div>
|
||||||
|
<h2 class="text-2xl font-bold mb-2 text-white">Waiting for Opponent</h2>
|
||||||
|
<button v-if="amIHost" @click="cancelMatch" class="bg-red-600 hover:bg-red-700 text-white py-2 px-4 rounded shadow mt-4">Cancel Match</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div v-if="matchOver" class="absolute inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-md">
|
<div v-else-if="!matchOver && !wsStore.gameState" class="flex h-full items-center justify-center flex-col gap-4">
|
||||||
<div class="text-center space-y-6 p-8 bg-slate-900 border-2 border-purple-500 rounded-2xl shadow-2xl max-w-md w-full">
|
<div class="text-3xl font-bold animate-pulse text-white drop-shadow">Preparing next round...</div>
|
||||||
<Trophy v-if="iWonMatch" class="w-20 h-20 text-yellow-400 mx-auto animate-bounce" />
|
</div>
|
||||||
<Frown v-else class="w-20 h-20 text-slate-500 mx-auto" />
|
<div v-if="matchOver" class="absolute inset-0 z-50 flex items-center justify-center bg-black/80 backdrop-blur-md">
|
||||||
|
<div class="text-center space-y-6 p-8 bg-green-900 border-2 border-green-500 rounded-2xl shadow-2xl max-w-md w-full">
|
||||||
<div>
|
<Trophy v-if="iWonMatch" class="w-24 h-24 text-yellow-400 mx-auto animate-bounce" />
|
||||||
<h1 class="text-4xl font-black uppercase mb-2"
|
<Frown v-else class="w-24 h-24 text-green-300 mx-auto opacity-75" />
|
||||||
:class="iWonMatch ? 'text-yellow-400' : 'text-slate-400'">
|
<h1 class="text-5xl font-black uppercase mb-2" :class="iWonMatch ? 'text-yellow-400' : 'text-gray-300'">{{ iWonMatch ? 'Victory!' : 'Defeat' }}</h1>
|
||||||
{{ iWonMatch ? 'Victory!' : 'Defeat' }}
|
<p class="text-green-100 text-lg">Marks: <span class="font-bold">{{ matchState.myMarks }} - {{ matchState.oppMarks }}</span></p>
|
||||||
</h1>
|
<Button @click="leaveMatch" class="w-full py-6 text-lg bg-purple-600 hover:bg-purple-700">Return to Lobby</Button>
|
||||||
<p class="text-slate-300">Final Score: {{ matchState.myWins }} - {{ matchState.oppWins }}</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="matchState.wager > 0" class="bg-yellow-500/10 p-4 rounded-xl border border-yellow-500/20">
|
|
||||||
<p class="text-xs uppercase text-yellow-600 font-bold mb-1">Total Reward</p>
|
|
||||||
<div class="flex items-center justify-center gap-2 text-2xl font-bold text-yellow-400">
|
|
||||||
<Coins class="w-6 h-6" />
|
|
||||||
<span>{{ iWonMatch ? '+' + (matchState.wager * 2) : '-' + matchState.wager }}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Button @click="leaveMatch" class="w-full bg-purple-600 hover:bg-purple-700">
|
|
||||||
Return to Lobby
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showRoundModal" class="fixed inset-0 z-[100] flex items-center justify-center bg-black/80 backdrop-blur-md">
|
||||||
|
<div class="bg-gray-800 p-8 rounded-2xl border-2 border-yellow-500/50 shadow-2xl max-w-md w-full text-center relative overflow-hidden">
|
||||||
|
<div class="absolute top-0 left-0 w-full h-2 bg-gradient-to-r from-transparent via-yellow-500 to-transparent"></div>
|
||||||
|
<h2 class="text-3xl font-black text-white mb-2 uppercase">Round Over</h2>
|
||||||
|
<p class="text-gray-400 mb-6 uppercase text-xs tracking-widest">{{ roundData.reason === 'surrender' ? 'Opponent Surrendered' : 'Points Limit Reached' }}</p>
|
||||||
|
|
||||||
|
<div class="flex justify-between items-center bg-black/30 p-4 rounded-lg mb-6">
|
||||||
|
<div class="text-left">
|
||||||
|
<p class="text-xs text-gray-500 uppercase">You</p>
|
||||||
|
<p class="text-2xl font-bold text-white">{{ roundData.myPoints }} pts</p>
|
||||||
|
</div>
|
||||||
|
<div class="text-xl font-bold text-yellow-500">VS</div>
|
||||||
|
<div class="text-right">
|
||||||
|
<p class="text-xs text-gray-500 uppercase">Opponent</p>
|
||||||
|
<p class="text-2xl font-bold text-white">{{ roundData.oppPoints }} pts</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mb-8">
|
||||||
|
<p class="text-lg text-white" v-if="roundData.winnerId == myUserId">
|
||||||
|
You won <span class="text-yellow-400 font-bold">+{{ roundData.marksAdded }} marks</span>!
|
||||||
|
</p>
|
||||||
|
<p class="text-lg text-white" v-else>
|
||||||
|
Opponent won <span class="text-red-400 font-bold">+{{ roundData.marksAdded }} marks</span>.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button @click="closeRoundModal" class="w-full py-4 bg-emerald-600 hover:bg-emerald-500 text-white font-bold rounded-xl shadow-lg transition-transform hover:scale-105">
|
||||||
|
Ready for Next Round
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showSurrenderModal" class="fixed inset-0 z-[100] flex items-center justify-center bg-black/70 backdrop-blur-sm">
|
||||||
|
<div class="bg-gray-800 p-6 rounded-lg border border-gray-600 shadow-2xl max-w-sm w-full text-center">
|
||||||
|
<h3 class="text-xl font-bold text-white mb-6">Surrender Options</h3>
|
||||||
|
<div class="space-y-3">
|
||||||
|
<button @click="confirmSurrenderRound" class="w-full px-4 py-3 bg-gray-700 hover:bg-gray-600 rounded text-white font-bold border border-gray-500 flex justify-between items-center group">
|
||||||
|
<span>Surrender Round</span>
|
||||||
|
<span class="text-xs bg-black/40 px-2 py-1 rounded text-gray-300 group-hover:bg-red-500 group-hover:text-white">-2 Marks</span>
|
||||||
|
</button>
|
||||||
|
<button @click="confirmSurrenderMatch" class="w-full px-4 py-3 bg-red-900/50 hover:bg-red-600 rounded text-red-200 hover:text-white font-bold border border-red-800 flex justify-between items-center group">
|
||||||
|
<span>Surrender Match</span>
|
||||||
|
<span class="text-xs bg-black/40 px-2 py-1 rounded text-red-300 group-hover:bg-red-800 group-hover:text-white">Defeat</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<button @click="showSurrenderModal = false" class="mt-6 text-gray-400 hover:text-white text-sm underline">Cancel</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Transition enter-active-class="transition-all duration-300 ease-out" enter-from-class="opacity-0 scale-50" enter-to-class="opacity-100 scale-100" leave-active-class="transition-all duration-200 ease-in" leave-from-class="opacity-100 scale-100" leave-to-class="opacity-0 scale-75">
|
||||||
|
<div v-if="showTrickResult" class="fixed top-1/3 left-1/2 -translate-x-1/2 z-[70] pointer-events-none">
|
||||||
|
<div class="bg-black/70 backdrop-blur-md px-8 py-4 rounded-2xl border border-white/10 shadow-2xl text-center">
|
||||||
|
<p class="text-sm uppercase tracking-widest text-gray-300 font-bold mb-1">Trick Winner</p>
|
||||||
|
<h2 class="text-3xl font-black" :class="lastTrickWinner === myUserId ? 'text-green-400' : 'text-red-400'">{{ lastTrickWinner === myUserId ? 'YOU' : 'OPPONENT' }}</h2>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Transition>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
|
||||||
// Imports and setup similar to GamePage, but tracking Match State
|
|
||||||
import { ref, onMounted, computed } from 'vue'
|
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
|
||||||
import { Coins, Trophy, Frown } from 'lucide-vue-next'
|
|
||||||
import GameBoard from '@/components/game/GameBoard.vue' // Reuse your existing board logic
|
|
||||||
import axios from 'axios'
|
|
||||||
// ... socket logic for match_updates ...
|
|
||||||
|
|
||||||
const matchState = ref({
|
|
||||||
id: null,
|
|
||||||
wager: 0,
|
|
||||||
myWins: 0,
|
|
||||||
oppWins: 0,
|
|
||||||
currentGameId: null,
|
|
||||||
players: {}
|
|
||||||
})
|
|
||||||
|
|
||||||
const matchOver = computed(() => matchState.value.myWins >= 2 || matchState.value.oppWins >= 2)
|
|
||||||
const iWonMatch = computed(() => matchState.value.myWins > matchState.value.oppWins)
|
|
||||||
|
|
||||||
// This function listens for Socket events on the "Match Channel"
|
|
||||||
// e.g., channel: `match.{id}` event: `RoundEnded`
|
|
||||||
const listenToMatch = () => {
|
|
||||||
// When a game ends, the server should send:
|
|
||||||
// { nextGameId: 123, scores: { p1: 1, p2: 0 } }
|
|
||||||
// Update matchState.currentGameId to trigger the GameBoard to reload
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ const userStore = useUserStore()
|
|||||||
const userLoggedIn = computed(() => authStore.isLoggedIn)
|
const userLoggedIn = computed(() => authStore.isLoggedIn)
|
||||||
const userCoins = ref(0)
|
const userCoins = ref(0)
|
||||||
const hostLoading = ref(false)
|
const hostLoading = ref(false)
|
||||||
|
const gHasMore = ref(true);
|
||||||
|
const mHasMore = ref(true);
|
||||||
|
|
||||||
const setupMatchesObserver = () => {
|
const setupMatchesObserver = () => {
|
||||||
if (mObserver.value) mObserver.value.disconnect();
|
if (mObserver.value) mObserver.value.disconnect();
|
||||||
@@ -87,40 +89,40 @@ const setupGamesObserver = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getPendingGames = async (mode = selectedMode.value) => {
|
const getPendingGames = async (mode = selectedMode.value) => {
|
||||||
if (gLoading.value) return;
|
if (gLoading.value || !gHasMore.value) return;
|
||||||
gLoading.value = true;
|
gLoading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`${API_BASE_URL}/games/open`, {
|
const response = await axios.get(`${API_BASE_URL}/games/open`, {
|
||||||
params: {
|
params: { type: mode, page: gPage.value }
|
||||||
type: mode,
|
|
||||||
page: gPage.value
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const newGames = response.data.data;
|
const newGames = response.data.data;
|
||||||
openGames.value = [...openGames.value, ...newGames];
|
if (newGames.length === 0) {
|
||||||
|
gHasMore.value = false;
|
||||||
|
} else {
|
||||||
|
openGames.value = [...openGames.value, ...newGames];
|
||||||
|
gPage.value++;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
gLoading.value = false;
|
gLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getPendingMatches = async (mode = selectedMode.value) => {
|
const getPendingMatches = async (mode = selectedMode.value) => {
|
||||||
if (mLoading.value) return;
|
if (mLoading.value || !mHasMore.value) return;
|
||||||
mLoading.value = true;
|
mLoading.value = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// FIX: Incorrect endpoint used previously
|
|
||||||
// TAG: 404
|
|
||||||
const response = await axios.get(`${API_BASE_URL}/matches/open`, {
|
const response = await axios.get(`${API_BASE_URL}/matches/open`, {
|
||||||
params: {
|
params: { type: mode, page: mPage.value }
|
||||||
type: mode,
|
|
||||||
page: mPage.value
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const newMatches = response.data.data;
|
const newMatches = response.data.data;
|
||||||
openMatches.value = [...openMatches.value, ...newMatches];
|
if (newMatches.length === 0) {
|
||||||
|
mHasMore.value = false;
|
||||||
|
} else {
|
||||||
|
openMatches.value = [...openMatches.value, ...newMatches];
|
||||||
|
mPage.value++;
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
mLoading.value = false;
|
mLoading.value = false;
|
||||||
}
|
}
|
||||||
@@ -150,8 +152,8 @@ const openStats = async () => {
|
|||||||
|
|
||||||
const getAvatarUrl = (filename) => {
|
const getAvatarUrl = (filename) => {
|
||||||
return filename
|
return filename
|
||||||
? `${API_BASE_URL.replace('/api/v1', '').replace('v1/')}/storage/photos_avatars/${filename}`
|
? `${API_BASE_URL.replace('/api/v1', '').replace('v1/', '')}/storage/photos_avatars/${filename}`
|
||||||
: `${API_BASE_URL.replace('/api/v1', '').replace('v1/')}/storage/photos_avatars/anonymous.png`;
|
: `${API_BASE_URL.replace('/api/v1', '').replace('v1/', '')}/storage/photos_avatars/anonymous.png`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchLeaderboard = async () => {
|
const fetchLeaderboard = async () => {
|
||||||
@@ -160,11 +162,9 @@ const fetchLeaderboard = async () => {
|
|||||||
try {
|
try {
|
||||||
const response = await apiStore.getLeaderboard({ page: lbPage.value });
|
const response = await apiStore.getLeaderboard({ page: lbPage.value });
|
||||||
const newEntries = response.data.data;
|
const newEntries = response.data.data;
|
||||||
|
|
||||||
if (newEntries.length < 10) {
|
if (newEntries.length < 10) {
|
||||||
lbMorePages.value = false;
|
lbMorePages.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
leaderboardEntries.value = [...leaderboardEntries.value, ...newEntries];
|
leaderboardEntries.value = [...leaderboardEntries.value, ...newEntries];
|
||||||
lbPage.value++;
|
lbPage.value++;
|
||||||
} finally {
|
} finally {
|
||||||
@@ -188,7 +188,6 @@ const setupLeaderboardObserver = () => {
|
|||||||
fetchLeaderboard();
|
fetchLeaderboard();
|
||||||
}
|
}
|
||||||
}, { threshold: 0.1 });
|
}, { threshold: 0.1 });
|
||||||
|
|
||||||
if (lbObserverTarget.value) {
|
if (lbObserverTarget.value) {
|
||||||
lbObserver.value.observe(lbObserverTarget.value);
|
lbObserver.value.observe(lbObserverTarget.value);
|
||||||
}
|
}
|
||||||
@@ -198,9 +197,11 @@ const clickMode = async (mode) => {
|
|||||||
if (selectedMode.value === mode) return;
|
if (selectedMode.value === mode) return;
|
||||||
selectedMode.value = mode;
|
selectedMode.value = mode;
|
||||||
openGames.value = [];
|
openGames.value = [];
|
||||||
gPage.value = 1;
|
|
||||||
openMatches.value = [];
|
openMatches.value = [];
|
||||||
|
gPage.value = 1;
|
||||||
mPage.value = 1;
|
mPage.value = 1;
|
||||||
|
gHasMore.value = true;
|
||||||
|
mHasMore.value = true;
|
||||||
await Promise.all([getPendingGames(), getPendingMatches()]);
|
await Promise.all([getPendingGames(), getPendingMatches()]);
|
||||||
setupGamesObserver();
|
setupGamesObserver();
|
||||||
setupMatchesObserver();
|
setupMatchesObserver();
|
||||||
@@ -210,136 +211,90 @@ const startSingle = () => {
|
|||||||
router.push({ name: 'bisca' + selectedMode.value });
|
router.push({ name: 'bisca' + selectedMode.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleReady = () => {
|
// --- FIX: Correct Wager Logic ---
|
||||||
isReady.value = !isReady.value
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
await fetchPublicStats();
|
|
||||||
if (isLoggedIn) {
|
|
||||||
await Promise.all([getPendingGames(), getPendingMatches()]);
|
|
||||||
await nextTick();
|
|
||||||
setupGamesObserver();
|
|
||||||
setupMatchesObserver();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Update Host Game to handle Matches
|
|
||||||
const hostGame = async () => {
|
|
||||||
// 1. Validation
|
|
||||||
if (isBestOfThree.value) {
|
|
||||||
if (wagerAmount.value <= 0) {
|
|
||||||
alert("For a match, the stake must be at least 1 coin.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (wagerAmount.value > userCoins.value) {
|
|
||||||
alert("You don't have enough coins to stake this amount!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
hostLoading.value = true; // DISABLE BUTTON
|
|
||||||
|
|
||||||
// 2. Prepare Payload
|
|
||||||
const endpoint = isBestOfThree.value ? '/matches' : '/games/host'
|
|
||||||
|
|
||||||
// Note: Matches use 'stake', Games don't need it.
|
|
||||||
const payload = isBestOfThree.value
|
|
||||||
? { type: parseInt(selectedMode.value), stake: parseInt(wagerAmount.value) }
|
|
||||||
: { type: parseInt(selectedMode.value) }
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.post(`${API_BASE_URL}${endpoint}`, payload)
|
|
||||||
|
|
||||||
const resultId = response.data.match?.id || response.data.id || response.data.data?.id;
|
|
||||||
|
|
||||||
if (!resultId) {
|
|
||||||
throw new Error("Server response missing ID");
|
|
||||||
}
|
|
||||||
|
|
||||||
const routeName = isBestOfThree.value ? 'multiplayer-match' : 'multiplayer-game'
|
|
||||||
|
|
||||||
console.log(`${isBestOfThree.value ? 'Match' : 'Game'} hosted:`, resultId)
|
|
||||||
|
|
||||||
// Close modal immediately
|
|
||||||
showHostModal.value = false;
|
|
||||||
|
|
||||||
router.push({
|
|
||||||
name: routeName,
|
|
||||||
params: { id: resultId },
|
|
||||||
query: { type: selectedMode.value }
|
|
||||||
})
|
|
||||||
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Failed to host:', error);
|
|
||||||
|
|
||||||
// Handle Validation Errors (422)
|
|
||||||
if (error.response?.data?.errors) {
|
|
||||||
const firstError = Object.values(error.response.data.errors)[0][0];
|
|
||||||
alert(`Validation Error: ${firstError}`);
|
|
||||||
}
|
|
||||||
// Handle Logic Errors (e.g., "You already have a match")
|
|
||||||
else if (error.response?.data?.message) {
|
|
||||||
alert(error.response.data.message);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
alert('Failed to host: ' + error.message);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
hostLoading.value = false; // RE-ENABLE BUTTON
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const joinMatch = async (match) => {
|
const joinMatch = async (match) => {
|
||||||
selectedGame.value = match // Reusing selectedGame variable for modal context
|
// Use 'stake' because that's what the API returns
|
||||||
|
const cost = match.stake || match.wager || 0;
|
||||||
|
|
||||||
// Check balance
|
if (cost > userCoins.value) {
|
||||||
if (match.wager > userCoins.value) {
|
toast.error(`Insufficient funds! You need ${cost} coins.`);
|
||||||
alert(`Insufficient funds! You need ${match.wager} coins to join this match.`)
|
return;
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!confirm(`This match requires a wager of ${match.wager} coins. Do you want to join?`)) {
|
if (!confirm(`Join match for ${cost} coins?`)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post(`${API_BASE_URL}/matches/${match.id}/join`)
|
await axios.post(`${API_BASE_URL}/matches/${match.id}/join`)
|
||||||
router.push({
|
router.push({
|
||||||
name: 'multiplayer-match', // Redirect to Match Interface
|
name: 'multiplayer-match',
|
||||||
params: { id: match.id },
|
params: { id: match.id },
|
||||||
query: { type: selectedMode.value }
|
query: { type: selectedMode.value }
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to join match:', error)
|
toast.error(error.response?.data?.message || 'Failed to join match');
|
||||||
alert(error.response?.data?.message || 'Failed to join match')
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostGame = async () => {
|
||||||
|
if (isBestOfThree.value) {
|
||||||
|
if (wagerAmount.value <= 0) {
|
||||||
|
toast.error("Stake must be at least 1 coin.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (wagerAmount.value > userCoins.value) {
|
||||||
|
toast.error("Insufficient coins!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hostLoading.value = true;
|
||||||
|
const endpoint = isBestOfThree.value ? '/matches/host' : '/games/host'
|
||||||
|
const payload = isBestOfThree.value
|
||||||
|
? { type: parseInt(selectedMode.value), stake: parseInt(wagerAmount.value) }
|
||||||
|
: { type: parseInt(selectedMode.value) }
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.post(`${API_BASE_URL}${endpoint}`, payload)
|
||||||
|
const resultId = response.data.match?.id || response.data.id || response.data.data?.id;
|
||||||
|
|
||||||
|
if (!resultId) throw new Error("Missing ID");
|
||||||
|
|
||||||
|
showHostModal.value = false;
|
||||||
|
router.push({
|
||||||
|
name: isBestOfThree.value ? 'multiplayer-match' : 'multiplayer-game',
|
||||||
|
params: { id: resultId },
|
||||||
|
query: { type: selectedMode.value }
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response?.data?.message) {
|
||||||
|
toast.error(error.response.data.message);
|
||||||
|
} else {
|
||||||
|
toast.error('Failed to host game');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
hostLoading.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const joinGame = async (game) => {
|
const joinGame = async (game) => {
|
||||||
selectedGame.value = game
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await axios.post(`${API_BASE_URL}/games/${game.id}/join`)
|
await axios.post(`${API_BASE_URL}/games/${game.id}/join`)
|
||||||
|
|
||||||
console.log('Joined game:', game.id)
|
|
||||||
|
|
||||||
router.push({
|
router.push({
|
||||||
name: 'multiplayer-game',
|
name: 'multiplayer-game',
|
||||||
params: { id: game.id },
|
params: { id: game.id },
|
||||||
query: { type: selectedMode.value }
|
query: { type: selectedMode.value }
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to join game:', error)
|
toast.error(error.response?.data?.message || 'Failed to join game');
|
||||||
console.error('Error details:', error.response?.data)
|
|
||||||
alert('Failed to join game: ' + (error.response?.data?.message || error.message))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const openHostModal = (forMatch) => {
|
const openHostModal = (forMatch) => {
|
||||||
isBestOfThree.value = forMatch; // Set the toggle automatically
|
isBestOfThree.value = forMatch;
|
||||||
showHostModal.value = true; // Open the modal
|
showHostModal.value = true;
|
||||||
wagerAmount.value = 0; // Reset wager amount
|
wagerAmount.value = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => userLoggedIn, async (isLoggedIn) => {
|
watch(() => userLoggedIn, async (isLoggedIn) => {
|
||||||
@@ -351,11 +306,19 @@ watch(() => userLoggedIn, async (isLoggedIn) => {
|
|||||||
}
|
}
|
||||||
}, { immediate: true })
|
}, { immediate: true })
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
await fetchPublicStats();
|
||||||
|
if (isLoggedIn) {
|
||||||
|
await Promise.all([getPendingGames(), getPendingMatches()]);
|
||||||
|
await nextTick();
|
||||||
|
setupGamesObserver();
|
||||||
|
setupMatchesObserver();
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="min-h-screen bg-cover bg-center transition-all duration-700">
|
<div class="min-h-screen bg-cover bg-center transition-all duration-700">
|
||||||
|
|
||||||
<div class="flex flex-col justify-center items-center gap-5 pt-10 pb-10 px-4">
|
<div class="flex flex-col justify-center items-center gap-5 pt-10 pb-10 px-4">
|
||||||
|
|
||||||
<Card v-if="publicStats" class="w-full max-w-2xl border-[#a855f7] bg-[#f8f0ff] shadow-sm">
|
<Card v-if="publicStats" class="w-full max-w-2xl border-[#a855f7] bg-[#f8f0ff] shadow-sm">
|
||||||
@@ -381,93 +344,72 @@ watch(() => userLoggedIn, async (isLoggedIn) => {
|
|||||||
|
|
||||||
<div class="relative w-full max-w-md bg-card rounded-lg border shadow-sm overflow-hidden">
|
<div class="relative w-full max-w-md bg-card rounded-lg border shadow-sm overflow-hidden">
|
||||||
<div class="relative h-14 flex items-center">
|
<div class="relative h-14 flex items-center">
|
||||||
|
|
||||||
<button @click="clickMode('9')"
|
<button @click="clickMode('9')"
|
||||||
class="h-full flex items-center justify-center font-semibold transition-all duration-500 ease-in-out border-r last:border-r-0"
|
class="h-full flex items-center justify-center font-semibold transition-all duration-500 ease-in-out border-r last:border-r-0"
|
||||||
:class="{
|
:class="{ 'w-2/3 z-10 text-purple-600 bg-purple-500/10': selectedMode === '9', 'w-1/3 z-0 text-muted-foreground/40': selectedMode !== '9' }">
|
||||||
'w-2/3 z-10 text-purple-600 dark:text-purple-400 bg-purple-500/10': selectedMode === '9',
|
|
||||||
'w-1/3 z-0 text-muted-foreground/40 bg-transparent': selectedMode !== '9'
|
|
||||||
}">
|
|
||||||
<span>Bisca de 9</span>
|
<span>Bisca de 9</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button @click="clickMode('3')"
|
<button @click="clickMode('3')"
|
||||||
class="h-full flex items-center justify-center font-semibold transition-all duration-500 ease-in-out"
|
class="h-full flex items-center justify-center font-semibold transition-all duration-500 ease-in-out"
|
||||||
:class="{
|
:class="{ 'w-2/3 z-10 text-purple-600 bg-purple-500/10': selectedMode === '3', 'w-1/3 z-0 text-muted-foreground/40': selectedMode !== '3' }">
|
||||||
'w-2/3 z-10 text-purple-600 dark:text-purple-400 bg-purple-500/10': selectedMode === '3',
|
|
||||||
'w-1/3 z-0 text-muted-foreground/40 bg-transparent': selectedMode !== '3'
|
|
||||||
}">
|
|
||||||
<span>Bisca de 3</span>
|
<span>Bisca de 3</span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-col items-center gap-5 w-[100vw]">
|
<div class="flex flex-col items-center gap-5 w-[100vw]">
|
||||||
<Card class="w-full max-w-2xl">
|
<Card class="w-full max-w-2xl">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle class="text-3xl font-bold text-center">
|
<CardTitle class="text-3xl font-bold text-center">Single Player</CardTitle>
|
||||||
Single Player
|
<CardDescription class="text-center">Go against one of our bots!</CardDescription>
|
||||||
</CardTitle>
|
|
||||||
<CardDescription class="text-center">
|
|
||||||
Go against one of our bots!
|
|
||||||
</CardDescription>
|
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent class="space-y-6">
|
<CardContent class="space-y-6">
|
||||||
<div class="flex justify-center">
|
<div class="flex justify-center">
|
||||||
<Button @click="startSingle()" size="lg" variant="secondary"
|
<Button @click="startSingle()" size="lg" variant="secondary" class="hover:bg-purple-500 hover:text-slate-200">
|
||||||
class="hover:bg-purple-500 hover:text-slate-200">
|
|
||||||
Start Game
|
Start Game
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card class="w-full max-w-2xl flex flex-col">
|
<Card class="w-full max-w-2xl flex flex-col">
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle class="text-3xl font-bold text-center">Multi Player</CardTitle>
|
<CardTitle class="text-3xl font-bold text-center">Multi Player</CardTitle>
|
||||||
<CardDescription class="text-center">Go one on one with another player!</CardDescription>
|
<CardDescription class="text-center">Go one on one with another player!</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent class="flex-1 flex flex-col space-y-6">
|
<CardContent class="flex-1 flex flex-col space-y-6">
|
||||||
|
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1">
|
||||||
<div class="flex justify-between items-end mb-2">
|
<div class="flex justify-between items-end mb-2">
|
||||||
<label class="text-sm font-bold uppercase tracking-wider text-muted-foreground">Open
|
<label class="text-sm font-bold uppercase tracking-wider text-muted-foreground">Open Matches (Best of 3)</label>
|
||||||
Matches</label>
|
<Button v-if="isLoggedIn" @click="openHostModal(true)" size="sm" variant="outline" class="border-purple-500 text-purple-500 hover:bg-purple-500 hover:text-white font-bold">
|
||||||
<Button v-if="isLoggedIn" @click="openHostModal(true)" size="sm" variant="outline"
|
|
||||||
class="border-purple-500 text-purple-500 hover:bg-purple-500 hover:text-white transition-all duration-300 font-bold">
|
|
||||||
Host
|
Host
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="rounded-lg border bg-card text-card-foreground shadow-sm">
|
<div class="rounded-lg border bg-card text-card-foreground shadow-sm">
|
||||||
<div v-if="openMatches.length === 0" class="p-6 text-center text-sm text-muted-foreground">
|
<div v-if="openMatches.length === 0" class="p-6 text-center text-sm text-muted-foreground">
|
||||||
No open matches yet. Try hosting one!
|
No open matches.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="max-h-[350px] overflow-y-auto custom-scrollbar p-1">
|
<div v-else class="max-h-[350px] overflow-y-auto custom-scrollbar p-1">
|
||||||
<div v-for="(match, index) in openMatches" :key="match.id" @click="joinMatch(match)"
|
<div v-for="(match, index) in openMatches" :key="match.id" @click="joinMatch(match)"
|
||||||
class="flex items-center justify-between p-3 mb-2 border border-transparent rounded-lg cursor-pointer transition-all hover:bg-muted/50 hover:border-purple-500">
|
class="flex items-center justify-between p-3 mb-2 border border-transparent rounded-lg cursor-pointer transition-all hover:bg-muted/50 hover:border-purple-500">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<div
|
<div class="flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold bg-red-100 text-red-700">
|
||||||
class="flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold bg-red-100 text-red-700">
|
|
||||||
{{ index + 1 }}
|
{{ index + 1 }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="font-medium text-sm flex items-center gap-2">
|
<div class="font-medium text-sm flex items-center gap-2">
|
||||||
Match #{{ match.id }}
|
Match #{{ match.id }}
|
||||||
<span
|
<span class="flex items-center text-xs bg-yellow-100 text-yellow-700 px-2 py-0.5 rounded-full">
|
||||||
class="flex items-center text-xs bg-yellow-100 text-yellow-700 px-2 py-0.5 rounded-full">
|
<Coins class="w-3 h-3 mr-1" /> {{ match.stake || match.wager }}
|
||||||
<Coins class="w-3 h-3 mr-1" /> {{ match.wager }}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text-[10px] text-muted-foreground">
|
<div class="text-[10px] text-muted-foreground">Host: {{ match.player1?.nickname || 'Unknown' }}</div>
|
||||||
Host: {{ match.host?.nickname || 'Waiting...' }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ref="mObserverTarget" class="h-10 flex items-center justify-center">
|
<div ref="mObserverTarget" class="h-10 flex items-center justify-center">
|
||||||
<span v-if="mLoading" class="text-xs text-purple-500 animate-pulse">Loading matches...</span>
|
<span v-if="mLoading" class="text-xs text-purple-500 animate-pulse">Loading...</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -475,45 +417,34 @@ watch(() => userLoggedIn, async (isLoggedIn) => {
|
|||||||
|
|
||||||
<div class="flex flex-col flex-1">
|
<div class="flex flex-col flex-1">
|
||||||
<div class="flex justify-between items-end mb-2">
|
<div class="flex justify-between items-end mb-2">
|
||||||
<label class="text-sm font-medium uppercase tracking-wider text-muted-foreground">Open
|
<label class="text-sm font-medium uppercase tracking-wider text-muted-foreground">Open Games (Single)</label>
|
||||||
Games</label>
|
<Button v-if="isLoggedIn" @click="openHostModal(false)" size="sm" variant="outline" class="border-purple-500 text-purple-500 hover:bg-purple-500 hover:text-white font-bold">
|
||||||
<Button v-if="isLoggedIn" @click="openHostModal(false)" size="sm" variant="outline"
|
|
||||||
class="border-purple-500 text-purple-500 hover:bg-purple-500 hover:text-white transition-all duration-300 font-bold">
|
|
||||||
Host
|
Host
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="rounded-lg border bg-card text-card-foreground shadow-sm">
|
<div class="rounded-lg border bg-card text-card-foreground shadow-sm">
|
||||||
<div v-if="openGames.length === 0" class="p-6 text-center text-sm text-muted-foreground">
|
<div v-if="openGames.length === 0" class="p-6 text-center text-sm text-muted-foreground">
|
||||||
No open games yet. Try hosting one!
|
No open games.
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="max-h-[350px] overflow-y-auto custom-scrollbar p-1">
|
<div v-else class="max-h-[350px] overflow-y-auto custom-scrollbar p-1">
|
||||||
<div v-for="(game, index) in openGames" :key="game.id" @click="joinGame(game)"
|
<div v-for="(game, index) in openGames" :key="game.id" @click="joinGame(game)"
|
||||||
class="flex items-center justify-between p-3 mb-2 border border-transparent rounded-lg cursor-pointer transition-all hover:bg-muted/50 hover:border-purple-500">
|
class="flex items-center justify-between p-3 mb-2 border border-transparent rounded-lg cursor-pointer transition-all hover:bg-muted/50 hover:border-purple-500">
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<div
|
<div class="flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold bg-green-100 text-green-700">
|
||||||
class="flex h-8 w-8 items-center justify-center rounded-full text-xs font-bold bg-green-100 text-green-700">
|
|
||||||
{{ index + 1 }}
|
{{ index + 1 }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="font-medium text-sm">Host: {{ game.player1?.nickname ||
|
<div class="font-medium text-sm">Host: {{ game.player1?.nickname || 'Anonymous' }}</div>
|
||||||
'Anonymous' }}</div>
|
|
||||||
<div class="text-[10px] text-muted-foreground">{{ new
|
|
||||||
Date(game.began_at).toLocaleDateString() }} • {{ new
|
|
||||||
Date(game.began_at).toLocaleTimeString([], {
|
|
||||||
hour: '2-digit',
|
|
||||||
minute: '2-digit'
|
|
||||||
}) }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div ref="gObserverTarget" class="h-10 flex items-center justify-center">
|
<div ref="gObserverTarget" class="h-10 flex items-center justify-center">
|
||||||
<span v-if="gLoading" class="text-xs text-purple-500 animate-pulse">Loading
|
<span v-if="gLoading" class="text-xs text-purple-500 animate-pulse">Loading...</span>
|
||||||
games...</span>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
@@ -521,160 +452,25 @@ watch(() => userLoggedIn, async (isLoggedIn) => {
|
|||||||
|
|
||||||
<div v-if="showHostModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
|
<div v-if="showHostModal" class="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm">
|
||||||
<Card class="w-full max-w-sm border-purple-500 shadow-2xl">
|
<Card class="w-full max-w-sm border-purple-500 shadow-2xl">
|
||||||
<CardHeader>
|
<CardHeader><CardTitle class="text-center">{{ isBestOfThree ? 'Host Match (Best of 3)' : 'Host Game' }}</CardTitle></CardHeader>
|
||||||
<CardTitle class="text-center">
|
|
||||||
{{ isBestOfThree ? 'Host a (Best of 3)' : 'Host Single Game' }}
|
|
||||||
</CardTitle>
|
|
||||||
</CardHeader>
|
|
||||||
<CardContent class="flex flex-col gap-6 py-4">
|
<CardContent class="flex flex-col gap-6 py-4">
|
||||||
|
<div v-if="isBestOfThree" class="space-y-2">
|
||||||
<div v-if="isBestOfThree" class="space-y-2 transition-all">
|
|
||||||
<Label>Wager (Coins)</Label>
|
<Label>Wager (Coins)</Label>
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<Coins class="absolute left-3 top-2.5 h-4 w-4 text-yellow-500" />
|
<Coins class="absolute left-3 top-2.5 h-4 w-4 text-yellow-500" />
|
||||||
<Input v-model="wagerAmount" type="number" min="0" class="pl-9" placeholder="Enter wager amount" />
|
<Input v-model="wagerAmount" type="number" min="0" class="pl-9" />
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xs text-muted-foreground text-right">
|
<p class="text-xs text-muted-foreground text-right">Balance: {{ userCoins }}</p>
|
||||||
Balance: {{ userCoins }}
|
|
||||||
</p>
|
|
||||||
<p class="text-[10px] text-yellow-600 bg-yellow-100 p-2 rounded">
|
|
||||||
⚠️ Winner takes all. Coins are deducted when you join.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else class="text-center text-sm text-muted-foreground">
|
|
||||||
<p>No coins required.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-center text-sm text-muted-foreground">
|
|
||||||
<p>Host a standard game of Bisca de {{ selectedMode }}.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex gap-2">
|
<div class="flex gap-2">
|
||||||
<Button variant="outline" class="flex-1" @click="showHostModal = false" :disabled="hostLoading">
|
<Button variant="outline" class="flex-1" @click="showHostModal = false" :disabled="hostLoading">Cancel</Button>
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
<Button class="flex-1 bg-purple-600 hover:bg-purple-700" @click="hostGame" :disabled="hostLoading">
|
<Button class="flex-1 bg-purple-600 hover:bg-purple-700" @click="hostGame" :disabled="hostLoading">
|
||||||
<span v-if="hostLoading" class="animate-pulse">Creating...</span>
|
{{ hostLoading ? 'Creating...' : 'Create' }}
|
||||||
<span v-else>{{ isBestOfThree ? 'Create Match' : 'Start Game' }}</span>
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="showStatsModal"
|
|
||||||
class="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
|
|
||||||
<Card class="w-full max-w-sm max-h-2/3 border-purple-500 shadow-2xl">
|
|
||||||
<CardHeader class="border-b bg-muted/20">
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<CardTitle class="flex items-center gap-2">
|
|
||||||
<User class="text-yellow-500" /> My Statistics
|
|
||||||
</CardTitle>
|
|
||||||
<Button variant="ghost" size="sm" @click="showStatsModal = false">X</Button>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent class="py-6">
|
|
||||||
<div v-if="statsLoading" class="flex flex-col items-center py-10 gap-4">
|
|
||||||
<div class="h-8 w-8 animate-spin rounded-full border-4 border-purple-500 border-t-transparent">
|
|
||||||
</div>
|
|
||||||
<p class="text-sm text-muted-foreground">Calculating your glory...</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-else-if="userStats" class="space-y-6">
|
|
||||||
<div class="text-center">
|
|
||||||
<h3 class="text-2xl font-bold text-purple-600">{{ userStats.nickname }}</h3>
|
|
||||||
<p class="text-sm text-muted-foreground">Performance Overview</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-4">
|
|
||||||
<div
|
|
||||||
class="rounded-lg bg-muted/50 p-4 text-center border border-transparent hover:border-purple-500/30 transition-all">
|
|
||||||
<p class="text-xs uppercase text-muted-foreground font-semibold">Total Games</p>
|
|
||||||
<p class="text-2xl font-bold">{{ userStats.total_games }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg bg-purple-500/10 p-4 text-center border border-purple-500/20">
|
|
||||||
<p class="text-xs uppercase text-purple-600 font-semibold">Win Rate</p>
|
|
||||||
<p class="text-2xl font-bold text-purple-600">{{ userStats.win_rate }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg bg-green-500/10 p-4 text-center border border-green-500/20">
|
|
||||||
<p class="text-xs uppercase text-green-600 font-semibold">Wins</p>
|
|
||||||
<p class="text-2xl font-bold text-green-600">{{ userStats.total_wins }}</p>
|
|
||||||
</div>
|
|
||||||
<div class="rounded-lg bg-red-500/10 p-4 text-center border border-red-500/20">
|
|
||||||
<p class="text-xs uppercase text-red-600 font-semibold">Losses</p>
|
|
||||||
<p class="text-2xl font-bold text-red-600">{{ userStats.total_losses }}</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="space-y-2">
|
|
||||||
<div class="flex justify-between text-xs font-medium">
|
|
||||||
<span>Win/Loss Ratio</span>
|
|
||||||
<span>{{ userStats.total_wins }}W - {{ userStats.total_losses }}L</span>
|
|
||||||
</div>
|
|
||||||
<div class="h-2 w-full bg-red-500/20 rounded-full overflow-hidden flex">
|
|
||||||
<div class="bg-green-500 h-full" :style="{ width: userStats.win_rate }"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="showLeaderboardModal"
|
|
||||||
class="fixed inset-0 z-[60] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
|
|
||||||
<Card class="w-full max-w-lg max-h-1/2 h-[80vh] flex flex-col border-purple-500 shadow-2xl">
|
|
||||||
<CardHeader class="border-b">
|
|
||||||
<div class="flex justify-between items-center">
|
|
||||||
<CardTitle class="flex items-center gap-2">
|
|
||||||
<Trophy class="text-purple-500" /> Leaderboard
|
|
||||||
</CardTitle>
|
|
||||||
<Button variant="ghost" size="sm" @click="showLeaderboardModal = false">X</Button>
|
|
||||||
</div>
|
|
||||||
</CardHeader>
|
|
||||||
|
|
||||||
<CardContent class="flex-1 overflow-y-auto custom-scrollbar p-0">
|
|
||||||
<div v-for="(user, index) in leaderboardEntries" :key="user.id"
|
|
||||||
class="flex items-center justify-between p-4 border-b last:border-0 hover:bg-muted/30 transition-colors">
|
|
||||||
|
|
||||||
<div class="flex items-center gap-4">
|
|
||||||
<span class="font-bold text-muted-foreground w-6 text-center"
|
|
||||||
:class="{ 'text-yellow-500': index === 0, 'text-slate-400': index === 1, 'text-orange-400': index === 2 }">
|
|
||||||
#{{ index + 1 }}
|
|
||||||
</span>
|
|
||||||
<img :src="getAvatarUrl(user.photo_avatar_filename)"
|
|
||||||
class="h-10 w-10 rounded-full border border-purple-200 object-cover" alt="Avatar" />
|
|
||||||
<div>
|
|
||||||
<p class="font-semibold text-sm">{{ user.nickname }}</p>
|
|
||||||
<p class="text-[10px] text-muted-foreground uppercase tracking-wider">Player</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="text-right">
|
|
||||||
<p class="text-lg font-bold text-purple-600">{{ user.won_games_count }}</p>
|
|
||||||
<p class="text-[10px] text-muted-foreground uppercase">Wins</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div ref="lbObserverTarget" class="h-20 flex items-center justify-center">
|
|
||||||
<span v-if="lbLoading" class="text-purple-500 animate-bounce">Loading rankings...</span>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="fixed right-4 top-1/2 -translate-y-1/2 flex flex-col gap-4 z-40">
|
|
||||||
<Button @click="openLeaderboard" variant="outline" size="icon"
|
|
||||||
class="h-12 w-12 rounded-full shadow-lg border-purple-500 bg-card hover:bg-purple-500 hover:text-white transition-all">
|
|
||||||
<Trophy class="h-6 w-6" />
|
|
||||||
</Button>
|
|
||||||
<Button v-if="useAuthStore().isLoggedIn" @click="openStats" variant="outline" size="icon"
|
|
||||||
class="h-12 w-12 rounded-full shadow-lg border-purple-500 bg-card hover:bg-purple-500 hover:text-white transition-all">
|
|
||||||
<User class="h-6 w-6" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user