Confirm player death, fix join bug

This commit is contained in:
Alec Maier
2020-04-18 17:09:46 -04:00
parent 3d953b990b
commit 0a583c01cb
4 changed files with 11 additions and 6 deletions

View File

@@ -3,12 +3,14 @@ import { utility } from './util.js'
// respond to the game state received from the server
socket.on('joinError', function(message) {
document.getElementById("code").classList.add("error");
document.getElementById("join-error").innerText = message;
document.getElementById("join-btn").classList.remove('disabled');
document.getElementById("code").classList.add("error");
document.getElementById("join-error").innerText = message;
});
// respond to the game state received from the server
socket.on('success', function() {
document.getElementById("join-btn").classList.remove('disabled');
if (document.getElementById("code").classList.contains("error")) {
document.getElementById("code").classList.remove("error");
document.getElementById("join-error").innerText = "";
@@ -21,6 +23,7 @@ socket.on('success', function() {
});
document.getElementById("join-btn").addEventListener("click", function() {
document.getElementById("join-btn").classList.add('disabled');
if (document.getElementById("name").value.length > 0) {
const code = document.getElementById("code").value.toString().trim().toLowerCase();
if (document.getElementById("name").classList.contains("error")) {
@@ -33,6 +36,7 @@ document.getElementById("join-btn").addEventListener("click", function() {
const playerInfo = {name: document.getElementById("name").value, id: playerId, code: code};
socket.emit('joinGame', playerInfo);
} else {
document.getElementById("join-btn").classList.remove('disabled');
document.getElementById("name").classList.add("error");
document.getElementById("name-error").innerText = "Name is required.";
}