Ein paar änderungen beim joinen screen. Sowie die

die Möglichkeit den Code zu kopieren
This commit is contained in:
2025-03-18 12:53:18 +01:00
parent 4311b4c565
commit 14507cca7d
4 changed files with 62 additions and 15 deletions

View File

@@ -30,7 +30,7 @@
Code Erstellen
</div>
</button>
<button id="joinBtn">
<button id="joinOverlayBtn">
<div class="buttonIcon">
<svg xmlns="http://www.w3.org/2000/svg" height="35px" viewBox="0 -960 960 960" width="35px"
fill="#FFFFFF">

View File

@@ -28,8 +28,7 @@ class LobbyHandler {
this.socket.emit("createLobby");
}
handleJoinClick(){
const code = prompt("Bitte gib den 6 Stelligen Code ein");
handleJoinClick(code){
this.socket.emit("joinLobby", code);
}
@@ -63,7 +62,9 @@ class LobbyHandler {
<div class="screen">
<nav>
<h1>Spiel-Code:</h1>
<h1 class="message">${this.code}</h1>
<h1 class="message" id="code">
${this.code}
</h1>
</nav>
<div id="playerList">
${playerHTML}
@@ -72,6 +73,17 @@ class LobbyHandler {
`;
});
const codeText = document.getElementById("code");
codeText.addEventListener("click", () => {
codeText.innerText = "Kopiert!"
setTimeout(() => {
codeText.innerText = this.code;
}, 1500);
navigator.clipboard.writeText(this.code);
})
this.errorMsg.style.display = "none";
}

View File

@@ -5,8 +5,9 @@ class ServerConnectionManager{
/**@type {import("../../../../backend/node_modules/socket.io-client".Socket} für Autocompletions VSC*/
this.socket = io(`http://${window.location.hostname}:${window.location.port}`);
this.lobbyContainer = document.getElementById("mainDiv");
this.createBtn = document.getElementById("createBtn");
this.joinBtn = document.getElementById("joinBtn");
this.joinOverlayBtn = document.getElementById("joinOverlayBtn");
this.leaveBtn = document.getElementById("leaveBtn");
this.lobbyHandler = new LobbyHandler(this.socket);
@@ -38,9 +39,34 @@ class ServerConnectionManager{
this.lobbyHandler.handleCreateClick();
});
this.joinBtn.addEventListener("click", () => {
this.lobbyHandler.handleJoinClick();
});
this.joinOverlayBtn.addEventListener("click", () => {
this.lobbyContainer.innerHTML = `
<div class="screen container">
<div class="formSection">
<h2>Der Spiel-Code:</h2>
<input type="text" id="codeInp" placeholder="1A2B3C">
</div>
<button id="joinBtn">
<div class="buttonIcon">
<svg xmlns="http://www.w3.org/2000/svg" height="35px" viewBox="0 -960 960 960" width="35px"
fill="#FFFFFF">
<path
d="M220-520 80-600v-160l140-80 140 80v160l-140 80Zm0-92 60-34v-68l-60-34-60 34v68l60 34Zm440 123v-93l140 82v280L560-80
320-220v-280l140-82v93l-60 35v188l160 93 160-93v-188l-60-35Zm-140 89v-480h360l-80 120 80 120H600v240h-80Zm40 69ZM220-680Z" />
</svg>
</div>
<div class="buttonText">
Beitreten
</div>
</button>
</div>
`
document.getElementById("joinBtn").addEventListener("click", () => {
const code = document.getElementById("codeInp").value;
this.lobbyHandler.handleJoinClick(code);
})
})
this.leaveBtn.addEventListener("click", () => {
this.socket.disconnect();

View File

@@ -2,7 +2,7 @@ button {
width: 350px;
}
#joinBtn{
#joinOverlayBtn{
background-color: rgb(0, 119, 255);
}
@@ -64,3 +64,12 @@ button {
background-color: rgba(0, 89, 255, 0.377);
border-radius: 0 0 10px 10px;
}
.formSection h2{
text-align: center;
}
#codeInp{
text-align: center;
}