feat: add interactive button state and PocketBase integration
- Implemented button press tracking with visual feedback and event emission - Integrated PocketBase for real-time session and movie data management - Added session ID routing across pages for game state persistence
This commit is contained in:
+53
-37
@@ -1,56 +1,69 @@
|
||||
<script setup lang="ts">
|
||||
import card_data from "@/assets/card_data.json"
|
||||
import PocketBase from 'pocketbase'
|
||||
|
||||
const pb = new PocketBase('http://localhost:8090')
|
||||
|
||||
type playfieldButton = {
|
||||
id: number,
|
||||
title: string,
|
||||
icon: string,
|
||||
color: string,
|
||||
description: string,
|
||||
|
||||
isPressed: boolean | null
|
||||
|
||||
}
|
||||
const movie_data = ref({
|
||||
"Title": "A Maple Valley Christmas",
|
||||
"Year": "2022",
|
||||
"Rated": "TV-G",
|
||||
"Released": "05 Nov 2022",
|
||||
"Runtime": "85 min",
|
||||
"Genre": "Comedy, Drama, Romance",
|
||||
"Director": "Paul Ziller",
|
||||
"Writer": "Joie Botkin, Jerry Todt",
|
||||
"Actors": "Peyton List, Andrew W. Walker, Frances Flanagan",
|
||||
"Plot": "Erica is a rancher who has spent her whole life working the family farm with her mother and sister. When Aaron arrives and disrupts her plans, she starts to question what it is she actually wants.",
|
||||
"Language": "English, Italian",
|
||||
"Country": "Canada, United States",
|
||||
"Awards": "1 nomination total",
|
||||
"Poster": "https://m.media-amazon.com/images/M/MV5BZjliMTRlMGItOGQzZC00NTI2LWJkODctZWZmMDIzOGRmYTQ3XkEyXkFqcGc@._V1_SX300.jpg",
|
||||
"Ratings": [
|
||||
{
|
||||
"Source": "Internet Movie Database",
|
||||
"Value": "6.3/10"
|
||||
}
|
||||
],
|
||||
"Metascore": "N/A",
|
||||
"imdbRating": "6.3",
|
||||
"imdbVotes": "1,577",
|
||||
"imdbID": "tt21841642",
|
||||
"Type": "movie",
|
||||
"DVD": "N/A",
|
||||
"BoxOffice": "N/A",
|
||||
"Production": "N/A",
|
||||
"Website": "N/A",
|
||||
"Response": "True"
|
||||
type movie = {
|
||||
id: string,
|
||||
title: string,
|
||||
plot: string,
|
||||
poster_url: string,
|
||||
imdbid: string,
|
||||
isActive: boolean,
|
||||
created: string,
|
||||
updated: string
|
||||
}
|
||||
|
||||
const sessionid = checkSession()
|
||||
|
||||
async function getCards() {
|
||||
const data = pb.collection('cards').getFullList()
|
||||
return data
|
||||
}
|
||||
|
||||
async function get_session() {
|
||||
const data = pb.collection('game_sessions').getOne(sessionid as string, { expand: 'movie_title' })
|
||||
return data
|
||||
}
|
||||
|
||||
const movie_data = ref<movie>()
|
||||
movie_data.value = (await get_session()).expand?.movie_title
|
||||
|
||||
const cards_data = ref(await getCards())
|
||||
|
||||
const playfield = computed(() => {
|
||||
pb.collection('game_sessions').subscribe(sessionid as string, (e) => {
|
||||
console.log(e.action)
|
||||
console.log(e.record)
|
||||
})
|
||||
})
|
||||
|
||||
const buttons = ref(card_data)
|
||||
function onButtonPress(id: string) {
|
||||
const card = cards_data.value.find((card) => card.id === id)
|
||||
if (card) {
|
||||
card.isPressed = !card.isPressed
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="game-room-container">
|
||||
<div>
|
||||
<h1>{{ movie_data.Title }}</h1>
|
||||
<h1>{{ movie_data?.title }}</h1>
|
||||
</div>
|
||||
<div class="playfield">
|
||||
<PlayFieldButton v-for="button in buttons" :key="button.id" :icon="button.icon" :title="button.title" :description="button.description" />
|
||||
<PlayFieldButton v-for="card in cards_data" :key="card.id" :icon="card.icon" :title="card.title"
|
||||
:description="card.description" :id="card.id" :isPressed="card.isPressed"
|
||||
@button-pressed="onButtonPress" />
|
||||
</div>
|
||||
<div class="end-game">
|
||||
<button class="btn btn-primary">Lopeta peli</button>
|
||||
@@ -63,13 +76,14 @@ const buttons = ref(card_data)
|
||||
padding: 1rem;
|
||||
display: grid;
|
||||
gap: 1rem;
|
||||
|
||||
|
||||
}
|
||||
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.playfield {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
@@ -83,9 +97,11 @@ h1 {
|
||||
place-items: center;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.end-game {
|
||||
justify-self: center;
|
||||
width: 100%;
|
||||
|
||||
button {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user