Add debug logging and fix registerPlayer UI feedback

This commit is contained in:
2025-12-13 20:55:30 +11:00
parent b57611f0c4
commit 831aa0856d
2 changed files with 9 additions and 3 deletions

View File

@@ -201,17 +201,21 @@ class MultiplayerClient {
modal.classList.remove('active'); modal.classList.remove('active');
} }
// Show loading state if connecting // Show loading state
const loading = document.querySelector('.loading'); const loading = document.querySelector('.loading');
if (loading && !this.socket) { if (loading) {
loading.textContent = 'Connecting to server...'; loading.textContent = 'Registering...';
} }
if (!this.socket || !this.socket.connected) { if (!this.socket || !this.socket.connected) {
console.log('Socket not ready yet, username saved and will be sent on connect.'); console.log('Socket not ready yet, username saved and will be sent on connect.');
if (loading) {
loading.textContent = 'Connecting to server...';
}
return; return;
} }
console.log('Emitting register_player for:', username);
this.socket.emit('register_player', { username }); this.socket.emit('register_player', { username });
} }

View File

@@ -36,7 +36,9 @@ io.on('connection', (socket) => {
// Player registration // Player registration
socket.on('register_player', async (data) => { socket.on('register_player', async (data) => {
console.log('📝 Registration request from', socket.id, 'username:', data.username);
const result = await gameManager.registerPlayer(socket, data.username); const result = await gameManager.registerPlayer(socket, data.username);
console.log('📝 Registration result:', result);
socket.emit('registration_result', result); socket.emit('registration_result', result);
}); });