WIP: Fix game page for now, so build is possible

This commit is contained in:
Pablu23
2025-10-10 16:07:44 +02:00
parent 9dffac4de3
commit 5270368cec

View File

@@ -1,7 +1,7 @@
<script lang="ts"> <script lang="ts">
import { onMount, onDestroy } from 'svelte'; import { onMount, onDestroy } from 'svelte';
import { createWebSocketClient } from '$lib/websocketClient'; import { wsClient } from '$lib/websocketClient.svelte';
import type { Player } from '$lib/types'; import type { User } from '../../app';
// Game types // Game types
interface SongCard { interface SongCard {
@@ -11,11 +11,8 @@
year: number; year: number;
} }
// WebSocket connection
let ws = $state(createWebSocketClient());
// Game $state // Game $state
let currentPlayerId = $state<number>(1); let currentPlayerId = $state<string>('test1');
let cards = $state<SongCard[]>([]); let cards = $state<SongCard[]>([]);
let placedCards = $state<SongCard[]>([]); let placedCards = $state<SongCard[]>([]);
let currentCard = $state<SongCard | null>(null); let currentCard = $state<SongCard | null>(null);
@@ -29,10 +26,10 @@
let isPlaying = $state(false); let isPlaying = $state(false);
// Mock player data // Mock player data
const players: Player[] = [ const players: User[] = [
{ id: 1, name: 'YourName', isHost: true }, { email: 'test1', username: 'YourName' },
{ id: 2, name: 'Player2', isHost: false }, { email: 'test2', username: 'Player2' },
{ id: 3, name: 'GamerX', isHost: false } { email: 'test3', username: 'GamerX' }
]; ];
// Mock cards data // Mock cards data
@@ -45,7 +42,7 @@
// Set up player information // Set up player information
function getPlayerInfo() { function getPlayerInfo() {
const playerIndex = players.findIndex((p) => p.id === currentPlayerId); const playerIndex = players.findIndex((p) => p.email === currentPlayerId);
const info = { const info = {
previous: playerIndex > 0 ? players[playerIndex - 1] : null, previous: playerIndex > 0 ? players[playerIndex - 1] : null,
current: players[playerIndex], current: players[playerIndex],
@@ -104,7 +101,7 @@
// Card dragging functionality // Card dragging functionality
function startDrag(event: MouseEvent) { function startDrag(event: MouseEvent) {
// Only allow dragging for the current player // Only allow dragging for the current player
if (currentPlayerId !== players[0].id) return; if (currentPlayerId !== players[0].email) return;
const card = document.getElementById('current-card'); const card = document.getElementById('current-card');
if (!card) return; if (!card) return;
@@ -184,7 +181,7 @@
placedCards = newCards; placedCards = newCards;
// Send update to other players via WebSocket // Send update to other players via WebSocket
ws.sendMessage({ wsClient.sendMessage({
type: 'cardPlaced', type: 'cardPlaced',
cardId: currentCard!.id, cardId: currentCard!.id,
position: dragTargetIndex position: dragTargetIndex
@@ -245,7 +242,7 @@
// stopProgressTimer(); // stopProgressTimer();
// Clean up WebSocket connection // Clean up WebSocket connection
ws.disconnect(); wsClient.disconnect();
}); });
</script> </script>
@@ -263,7 +260,7 @@
<div class="flex flex-col items-center bg-indigo-600 px-4 py-1 rounded-lg"> <div class="flex flex-col items-center bg-indigo-600 px-4 py-1 rounded-lg">
<span class="text-xs text-indigo-200">Current</span> <span class="text-xs text-indigo-200">Current</span>
<span class="text-lg font-semibold">{getPlayerInfo().current?.name}</span> <span class="text-lg font-semibold">{getPlayerInfo().current?.username}</span>
</div> </div>
{#if getPlayerInfo().next} {#if getPlayerInfo().next}
@@ -393,7 +390,7 @@
<div <div
id="current-card" id="current-card"
class="card relative w-48 h-64 rounded-lg overflow-hidden shadow-lg border border-indigo-400 cursor-move {currentPlayerId !== class="card relative w-48 h-64 rounded-lg overflow-hidden shadow-lg border border-indigo-400 cursor-move {currentPlayerId !==
players[0].id players[0].email
? 'pointer-events-none opacity-70' ? 'pointer-events-none opacity-70'
: ''}" : ''}"
onmousedown={startDrag} onmousedown={startDrag}