Revert gamemode being its own Object to only being a id, also added websocket startGame integration
This commit is contained in:
@@ -9,6 +9,7 @@ export class WebsocketClient {
|
||||
selectedPlaylistId: ''
|
||||
});
|
||||
socket: WebSocket | null = null;
|
||||
onGameStart: () => void = () => {};
|
||||
|
||||
connect(url: string): void {
|
||||
if (this.socket) this.socket.close();
|
||||
@@ -50,6 +51,10 @@ export class WebsocketClient {
|
||||
case 'settingsUpdate':
|
||||
this.gameSettings = message.settings;
|
||||
break;
|
||||
|
||||
case 'startGame':
|
||||
this.onGameStart()
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to parse WebSocket message:', error);
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
|
||||
// Game $state
|
||||
let currentPlayerId = $state<string>('test1');
|
||||
let cards = $state<SongCard[]>([]);
|
||||
let placedCards = $state<SongCard[]>([]);
|
||||
let currentCard = $state<SongCard | null>(null);
|
||||
let dragPosition = $state<{ x: number; y: number } | null>(null);
|
||||
@@ -216,7 +215,6 @@
|
||||
onMount(() => {
|
||||
// Set up initial game $state
|
||||
placedCards = [mockCards[0], mockCards[1]];
|
||||
cards = mockCards.slice(2);
|
||||
currentCard = mockCards[3];
|
||||
|
||||
// Set up event listeners for drag and drop
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type { User } from '../../../app';
|
||||
import type { Playlist, Settings } from '$lib/types';
|
||||
import type { User, Playlist, Settings } from '../../../app';
|
||||
import { env } from '$env/dynamic/public';
|
||||
|
||||
export const load: PageServerLoad = async ({ params, fetch, locals: { user } }) => {
|
||||
|
||||
@@ -14,6 +14,11 @@
|
||||
|
||||
let { data }: PageProps = $props();
|
||||
|
||||
wsClient.onGameStart = () => {
|
||||
console.log('Game starting');
|
||||
goto('/game');
|
||||
};
|
||||
|
||||
let lobbyCode = $state(data.lobby.id);
|
||||
let isHost = $state(data.user.email === data.lobby.host.email); // Assume current user is host for this example
|
||||
|
||||
@@ -39,7 +44,7 @@
|
||||
type: 'startGame',
|
||||
settings: wsClient.gameSettings
|
||||
});
|
||||
// In a real app, this would navigate to the game screen
|
||||
// goto('/game');
|
||||
}
|
||||
|
||||
function copyLobbyCode() {
|
||||
@@ -49,12 +54,10 @@
|
||||
|
||||
function leaveLobby() {
|
||||
wsClient.sendMessage({
|
||||
type: 'leaveGame',
|
||||
player: data.user.email
|
||||
type: 'leaveGame'
|
||||
});
|
||||
wsClient.disconnect();
|
||||
goto('/');
|
||||
// In a real app, you'd likely redirect to another page here
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
@@ -70,7 +73,6 @@
|
||||
|
||||
onDestroy(() => {
|
||||
// Clean up WebSocket connection when component is destroyed
|
||||
leaveLobby();
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user