Files
front/components/CardPreview.vue
T

116 lines
2.2 KiB
Vue

<script setup lang="ts">
import type { Card } from '~/netcode/Card';
export interface Props {
card_id: number | undefined
locked?: boolean
wrapped?: boolean
}
const props = withDefaults(defineProps<Props>(), {
wrapped: () => false,
})
const emit = defineEmits(["click"])
const childCount = ref<number>(0)
function cardClick() {
if (!props.card_id) return
emit("click")
}
const rotation = ref(0)
// onBeforeUpdate(() => {
// rotation.value = Math.random() > .5 ? 2 : -2
// })
watch(
() => props.card_id,
() => {
rotation.value = Math.random() > .5 ? 2 : -2
},
{ immediate: true })
</script>
<template>
<div :class="`card ${childCount > 0 ? 'active' : ''} ${wrapped ? 'wrapped' : ''} ${props.locked ? 'locked' : ''}`"
@contextmenu.prevent="false" @click.left="cardClick" :style="`rotate:${rotation}deg;`">
<div id="contextMenuButtons" :ref="(el) => { childCount = ((el as Element)?.childElementCount ?? 0) }">
<slot></slot>
</div>
<img :class="`card_image`" v-if="props.card_id"
:src="'/cards/' + props.card_id.toString().padStart(3, '0') + '.png'" draggable="false">
<img :class="`card_image`" v-if="!props.card_id" :src="'/cards/background.png'" draggable="false">
</div>
</template>
<style scoped>
.card {
transition: 0.025s rotate linear;
max-width: 256px;
position: relative;
display: flex;
}
.card.active {
cursor: pointer
}
.card_image {
max-height: 250px;
transition: all .125s cubic-bezier(0.075, 0.82, 0.165, 1);
z-index: 1;
}
.card_image.outlined {
outline: 2px solid red;
outline-offset: -2px;
}
.card.locked {
/* filter: brightness(0.5); */
filter: drop-shadow(5px 15px 2px rgba(0, 0, 0, .60));
}
.card.wrapped {
max-width: 10px;
}
.card_image {
max-height: 250px;
}
#contextMenuButtons {
position: absolute;
display: flex;
flex-direction: row;
bottom: 0;
width: 100%;
transform: translateY(0);
transition: 0.1s transform cubic-bezier(0.075, 0.82, 0.165, 1);
}
.card.active:hover #contextMenuButtons {
transform: translateY(100%);
}
</style>
<style>
#contextMenuButtons>* {
flex: 1;
border-radius: 10px;
min-height: 50px;
}
</style>