refactor: Modularize JavaScript Code into Separate Files
All checks were successful
Build and Push Docker Image / docker (push) Successful in 9s

This commit is contained in:
2025-09-05 14:41:55 +02:00
parent 24c8c41f1e
commit 35b88c0b29
5 changed files with 449 additions and 452 deletions

23
public/js/session.js Normal file
View File

@@ -0,0 +1,23 @@
import { $nameDisplay, $nameLobby } from './dom.js';
import { state } from './state.js';
import { sendMsg } from './ws.js';
// If we have a stored player name, set it in the input and send to server
export function reusePlayerName() {
const stored = localStorage.getItem('playerName');
if (!stored) return;
if ($nameLobby && $nameLobby.value !== stored) {
$nameLobby.value = stored;
}
if ($nameDisplay) {
$nameDisplay.textContent = stored;
}
sendMsg({ type: 'set_name', name: stored });
}
export function reconnectLastRoom() {
const last = state.room?.id || localStorage.getItem('lastRoomId');
if (last && !localStorage.getItem('sessionId')) {
sendMsg({ type: 'join_room', code: last });
}
}