Compare commits

...

2 Commits

Author SHA1 Message Date
dbffce8818 feat: FRO-26 Create Tie selection component 2026-01-14 10:35:27 +01:00
LQ63
f29ed9d338 feat(ui): Tie selection
Added a nice tie selection ui
2026-01-13 22:22:34 +01:00
2 changed files with 405 additions and 58 deletions

View File

@@ -1,40 +1,85 @@
<script setup lang="ts"> <script setup lang="ts">
import {useWebSocket} from "@/composables/useWebsocket.ts"; import {useWebSocket} from "@/composables/useWebsocket.ts";
import {useIngame} from "@/composables/useIngame.ts"; import {useIngame} from "@/composables/useIngame.ts";
import type {GameInfo, LobbyInfo, TieInfo, TrumpInfo} from "@/types/GameTypes.ts"; import type { TieInfo } from "@/types/GameTypes.ts";
import {useQuasar} from "quasar"; import {useQuasar} from "quasar";
import { ref } from 'vue'; import { computed, nextTick, ref } from 'vue'
import { computed } from 'vue'
const wb = useWebSocket() const wb = useWebSocket()
const wi = useIngame() const wi = useIngame()
const tieInf = computed(() => wi.data as TieInfo) const tieInf = computed(() => wi.data as TieInfo)
const tieBlankCard = [ const tieBlankCard = "/images/cards/1B.png"
"/images/cards/AS.png"
]
const $q = useQuasar(); const $q = useQuasar();
function getCardImagePath(cardPath: string) { function getCardImagePath(cardPath: string) {
if (!cardPath) return '' if (!cardPath) return ''
if (cardPath.includes('://') || cardPath.startsWith('/')) return cardPath if (cardPath.includes('://') || cardPath.startsWith('/')) return cardPath
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) => { function getPlayerName(playerId: string) {
return tieInf.value.tiedPlayers.find(p => p.id === playerId)?.name || 'Player';
}
const myRevealedCard = computed(() => {
// 1. Get your own ID from the 'self' object in the DTO
const myId = tieInf.value.self?.id;
// 2. Safety check: ensure we have an ID and the map exists
if (!myId || !tieInf.value.selectedCards) return null;
// 3. Look up the CardDTO using your ID as the key
const card = tieInf.value.selectedCards[myId];
// 4. If found, convert the relative path to a full URL
return card ? getCardImagePath(card.path) : null;
});
const isFlipping = ref(false);
// Used to force-remount the flipping subtree so the CSS transition/animation restarts reliably
const revealKey = ref(0);
// This replaces your v-if check.
// It keeps the "Pick" screen visible while flipping.
const showPickScreen = computed(() => {
const isMyTurn = tieInf.value.self?.id === tieInf.value.currentPlayer?.id;
return isMyTurn || isFlipping.value;
});
function selectTie(tieIndex: number) {
// Use model.value because it's a ref
wb.sendAndWait("PickTie", { cardIndex: tieIndex })
.then(async () => {
console.log("Server accepted pick, starting animation...");
// 1. Trigger the animation state
isFlipping.value = true;
// 2. Force a remount of the flip-card for the selected card so the flip restarts even if src doesn't change
revealKey.value += 1;
await nextTick();
// 3. Optional Notification
$q.notify({ $q.notify({
message: error.message, message: "Card revealed!",
color: "positive",
position: "top",
timeout: 1000
});
// 4. Wait for animation to finish before switching to Waiting Screen
setTimeout(() => {
isFlipping.value = false;
model.value = null;
}, 500);
})
.catch((error) => {
console.error("Pick failed:", error);
$q.notify({
message: error.message || "Failed to pick card",
color: "negative", color: "negative",
position: "top" position: "top"
}) });
}) });
} }
const model = ref(1) const model = ref<number | null>(null)
const options = computed(() => { const options = computed(() => {
const list = [] const list = []
const max = tieInf.value.highestAmount?.valueOf() || 0 const max = tieInf.value.highestAmount?.valueOf() || 0
@@ -47,52 +92,352 @@ const options = computed(() => {
</script> </script>
<template> <template>
<q-card v-if="tieInf.self?.name === tieInf.currentPlayer?.name" class="player-profile-card" flat bordered> <transition
<q-card-section class="bg-white text-dark text-center q-py-lg"> appear
<div class="text-h3 text-weight-bolder"> enter-active-class="animate__animated animate__fadeInDown"
{{ tieInf.self?.name || "Loading Player..."}} leave-active-class="animate__animated animate__fadeOutDown"
mode="out-in"
>
<q-card v-if="showPickScreen" class="game-container text-center overflow-hidden">
<div class="bg-glow"></div>
<q-card-section class="content-layer q-py-xl">
<div class="text-overline text-primary letter-spacing-2">Tie-Break Round</div>
<div class="text-h4 text-weight-bold text-white q-mb-xl text-uppercase tracking-widest">
{{ isFlipping ? 'Your Result' : (model ? `Selection: Card #${model}` : 'Pick Your Card') }}
</div>
<div class="card-fan-container q-mb-xl">
<div
v-for="n in options"
:key="n"
@click="!isFlipping && (model = n)"
v-show="model === null || model === n"
class="tie-card-wrapper"
:class="{ 'selected-card': model === n, 'is-flipping': isFlipping && model === n }"
>
<div class="card-inner">
<!-- Flip card: keep both faces mounted; flip the inner wrapper. -->
<div
class="flip-card"
:class="{ 'flip-card--flipped': isFlipping && model === n && !!myRevealedCard }"
:key="(isFlipping && model === n) ? `${revealKey}-${n}` : `static-${n}`"
>
<div class="flip-card__inner">
<!-- FRONT: blank card (deck back) -->
<div class="flip-card__face flip-card__front">
<q-img
:src="getCardImagePath(tieBlankCard)"
class="card-image shadow-24"
no-spinner
no-transition
/>
</div>
<!-- BACK: revealed card (your pick result) -->
<div class="flip-card__face flip-card__back">
<q-img
:src="(model === n && myRevealedCard) ? myRevealedCard : getCardImagePath(tieBlankCard)"
class="card-image shadow-24"
no-spinner
no-transition
/>
</div>
</div>
</div>
<div v-if="!isFlipping" class="card-number">
{{ n }}
</div>
</div>
</div>
</div>
<div class="action-area" :class="{ 'visible': model !== null && !isFlipping }">
<div class="row q-gutter-md justify-center items-center">
<q-btn flat color="grey-4" label="Cancel" @click="model = null" />
<q-btn
label="Confirm Selection"
color="positive"
unelevated
@click="selectTie(model!)"
class="confirm-btn"
/>
</div>
</div>
<div v-if="!model && !isFlipping" class="text-grey-6 text-italic q-mt-md">
Hover and click to select a card from the deck
</div> </div>
</q-card-section> </q-card-section>
<q-card-section class="bg-dark text-dark text-center q-py-lg"> </q-card>
<div class="q-pa-md" style="max-width: 500px">
<div class="q-gutter-md"> <q-card v-else class="game-container text-center overflow-hidden">
<q-select <q-card-section class="content-layer q-py-xl">
v-model="model" <div class="text-overline text-primary letter-spacing-2">Tie-Break Round</div>
:options="options"
label="Select Amount" <div class="column items-center">
filled
bg-color="white" <div class="revealed-row q-mb-lg">
label-color="primary" <div
color="primary" v-for="(card, playerId) in tieInf.selectedCards"
popup-content-class="bg-white text-black" :key="playerId"
/> class="revealed-card-wrapper"
<q-btn >
color="positive" <div class="text-caption text-grey-5 q-mb-xs">{{ getPlayerName(playerId) }}</div>
icon="sports_martial_arts" <q-img :src="getCardImagePath(card.path)" class="card-image shadow-24" />
@click="selectTie(model)" </div>
class="full-width" </div>
<div class="card-fan-container skeleton-fan">
<q-skeleton
v-for="n in options"
:key="n"
type="rect"
class="skeleton-card"
/> />
</div> </div>
<div class="q-mt-xl">
<q-spinner-hourglass color="primary" size="4em" />
<div class="text-subtitle1 text-grey-5 q-mt-sm italic">
Waiting for <span class="text-white">{{ tieInf.currentPlayer?.name }}</span> to pick a card...
</div>
</div>
</div> </div>
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card </transition>
v-else
class="player-profile-card text-center"
flat
bordered
style="min-height: 200px; display: flex; flex-direction: column; justify-content: center;"
>
<q-card-section class="q-pa-lg">
<q-spinner-hourglass color="black" size="3em" class="q-mb-md" />
<div class="text-h5 text-grey-8">
Waiting for {{ tieInf.currentPlayer?.name || 'the other player' }} to select card for the tie...
</div>
</q-card-section>
</q-card>
</template> </template>
<style scoped> <style scoped>
.game-container {
max-width: 1400px;
width: 95vw;
margin: 0 auto;
background: #0f0f0f;
border: 1px solid rgba(255,255,255,0.1);
border-radius: 20px;
position: relative;
}
.bg-glow {
position: absolute;
top: 50%;
left: 50%;
width: 600px;
height: 400px;
background: radial-gradient(circle, rgba(25, 118, 210, 0.15) 0%, rgba(0,0,0,0) 70%);
transform: translate(-50%, -50%);
pointer-events: none;
}
.card-fan-container {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 60px 20px;
min-height: 300px;
perspective: 1000px;
gap: 40px 0;
}
.tie-card-wrapper {
position: relative;
transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
margin-left: -35px;
z-index: 1;
}
.tie-card-wrapper:first-child { margin-left: 0; }
.card-image {
width: 60px;
border-radius: 10px;
border: 1px solid rgba(255,255,255,0.1);
}
.tie-card-wrapper:hover {
transform: translateY(-40px) scale(1.1) rotate(2deg);
z-index: 50 !important;
}
.selected-card {
margin-left: 0 !important;
transform: scale(1.4) !important;
z-index: 100;
}
.selected-card .card-image {
border: 3px solid #1976d2;
box-shadow: 0 0 30px rgba(25, 118, 210, 0.5);
}
.card-number {
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
font-weight: 900;
font-size: 1.1rem;
color: #fff;
}
.confirm-btn {
padding: 12px 40px;
border-radius: 50px;
font-weight: bold;
letter-spacing: 1px;
}
.letter-spacing-2 { letter-spacing: 2px; }
/* Hide action area when no model is selected */
.action-area {
opacity: 0;
transform: translateY(20px);
transition: all 0.3s ease;
}
.action-area.visible {
opacity: 1;
transform: translateY(0);
}
.bg-glow.dimmed {
background: radial-gradient(circle, rgba(150, 150, 150, 0.05) 0%, rgba(0,0,0,0) 70%);
}
.tracking-widest {
letter-spacing: 0.2em;
}
@keyframes pulse {
0%, 100% { transform: scale(1); opacity: 0.2; }
50% { transform: scale(1.05); opacity: 0.5; }
}
.skeleton-fan {
opacity: 0.15;
perspective: 1000px;
}
.skeleton-card {
width: 60px;
height: 90px;
background: rgba(255, 255, 255, 0.1) !important;
margin-left: -35px; /* Matches your tie-card-wrapper overlap */
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.05);
}
.skeleton-card:first-child {
margin-left: 0;
}
/* Container for the cards that have been "pulled" higher */
.revealed-row {
display: flex;
justify-content: center;
align-items: flex-end;
gap: 20px;
min-height: 140px; /* Reserves space so the layout doesn't jump */
width: 100%;
}
.revealed-card-wrapper {
display: flex;
flex-direction: column;
align-items: center;
animation: slideDownFade 0.4s ease-out;
}
/* Specific styling for the revealed card images */
.revealed-card-wrapper .card-image {
width: 65px;
border-radius: 8px;
border: 2px solid var(--q-primary);
}
/* Keeping your original skeleton fan look */
.skeleton-fan {
opacity: 0.15;
display: flex;
justify-content: center;
margin-top: 20px;
}
.skeleton-card {
width: 60px;
height: 90px;
background: rgba(255, 255, 255, 0.1) !important;
margin-left: -35px;
border-radius: 10px;
}
.skeleton-card:first-child {
margin-left: 0;
}
@keyframes slideDownFade {
0% { opacity: 0; transform: translateY(-20px); }
100% { opacity: 1; transform: translateY(0); }
}
.card-inner {
perspective: 1000px;
transform-style: preserve-3d;
}
/* --- Flip card (reliable 3D flip) --- */
.flip-card {
width: 60px;
/* height follows image; q-img sets its own box, but we want a stable 3D container */
perspective: 1000px;
}
.flip-card__inner {
position: relative;
width: 100%;
transform-style: preserve-3d;
transition: transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.flip-card__face {
position: absolute;
inset: 0;
backface-visibility: hidden;
}
/* Ensure the q-img root stretches to fill the face */
.flip-card__face :deep(.q-img) {
width: 100%;
}
.flip-card__front {
transform: rotateY(0deg);
}
.flip-card__back {
transform: rotateY(180deg);
}
.flip-card--flipped .flip-card__inner {
/* Lift/scale a bit like your original dramatic flip */
transform: rotateY(180deg) scale(1.3) translateY(-10px);
}
/* While flipping, don't let hover/selected transforms fight the 3D transform */
.tie-card-wrapper.is-flipping:hover {
transform: none;
}
/* Optional: Slight pulse while the button is waiting to be clicked */
.selected-card:not(.is-flipping) {
animation: pulse 0.5s infinite;
}
@keyframes pulse {
0% { transform: scale(1.4); }
50% { transform: scale(1.45); box-shadow: 0 0 40px rgba(25, 118, 210, 0.6); }
100% { transform: scale(1.4); }
}
</style> </style>

View File

@@ -5,7 +5,8 @@ import type {
PodiumPlayer, PodiumPlayer,
Round, Round,
Trick, Trick,
User User,
Card
} from "@/types/GameSubTypes.ts"; } from "@/types/GameSubTypes.ts";
@@ -31,6 +32,7 @@ type TieInfo = {
self: Player | null self: Player | null
tiedPlayers: Player[] tiedPlayers: Player[]
highestAmount: number highestAmount: number
selectedCards: Record<string, Card>
} }
type TrumpInfo = { type TrumpInfo = {