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