mirror of
https://github.com/DeNNiiInc/Connect-5.git
synced 2026-06-24 13:04:40 +00:00
Improve UX: Prompt for username immediately in multiplayer
This commit is contained in:
+12
-6
@@ -20,6 +20,14 @@ class MultiplayerClient {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show username modal immediately if not saved
|
||||||
|
const savedUsername = localStorage.getItem('connect5_username');
|
||||||
|
if (!savedUsername) {
|
||||||
|
this.showUsernameModal();
|
||||||
|
} else {
|
||||||
|
this.username = savedUsername; // Pre-load username
|
||||||
|
}
|
||||||
|
|
||||||
// Dynamically construct proxy URLs based on current origin
|
// Dynamically construct proxy URLs based on current origin
|
||||||
const targetUrl = window.location.origin;
|
const targetUrl = window.location.origin;
|
||||||
const servers = [
|
const servers = [
|
||||||
@@ -111,16 +119,14 @@ class MultiplayerClient {
|
|||||||
this.socket.on('connect', () => {
|
this.socket.on('connect', () => {
|
||||||
console.log('✅ Connected to multiplayer server');
|
console.log('✅ Connected to multiplayer server');
|
||||||
|
|
||||||
// Check if username is saved in localStorage
|
// If we have a username (from localStorage or recently entered), try to register
|
||||||
const savedUsername = localStorage.getItem('connect5_username');
|
const savedUsername = localStorage.getItem('connect5_username') || this.username;
|
||||||
|
|
||||||
if (savedUsername) {
|
if (savedUsername) {
|
||||||
console.log('Found saved username:', savedUsername);
|
console.log('Found saved username:', savedUsername);
|
||||||
// Auto-login with saved username
|
|
||||||
this.registerPlayer(savedUsername);
|
this.registerPlayer(savedUsername);
|
||||||
} else {
|
|
||||||
// Show username modal if no saved username
|
|
||||||
this.showUsernameModal();
|
|
||||||
}
|
}
|
||||||
|
// If no username yet, do nothing (user is seeing the modal and will call registerPlayer when they submit)
|
||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on('disconnect', () => {
|
this.socket.on('disconnect', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user