From 36e17b7cc92002d325d7f6fa93767f6189c51444 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 10 Dec 2023 00:55:11 +0100 Subject: Show "join" page when not logged in. Static page showing limited info and a call to action to login or sign up. --- public/join.js | 93 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 19 deletions(-) (limited to 'public') diff --git a/public/join.js b/public/join.js index e51b548..cc8d325 100644 --- a/public/join.js +++ b/public/join.js @@ -120,11 +120,11 @@ function start_event_source() { } function is_friend(p) { - return whitelist.includes(p.user_id) + return whitelist && whitelist.includes(p.user_id) } function is_enemy(p) { - return blacklist.includes(p.user_id) + return blacklist && blacklist.includes(p.user_id) } function is_active(player, role) { @@ -148,10 +148,81 @@ function action_link(player, action, color, text) { } function update() { + update_common() + if (user_id) + update_login() + else + update_no_login() +} + +function update_common() { if (game.scenario !== "Standard") document.querySelector("h1").textContent = game.title_name + " - " + game.scenario else document.querySelector("h1").textContent = game.title_name + + let message = window.message + if (game.status === 0) { + if (ready && (game.owner_id === user_id)) + message.innerHTML = "Ready to start..." + else if (ready) + message.innerHTML = `Waiting for ${game.owner_name} to start the game...` + else + message.innerHTML = "Waiting for players to join..." + } else if (game.status === 1) { + message.innerHTML = `Observe` + } else if (game.status === 2) { + message.innerHTML = `Review` + } else if (game.status === 3) { + message.innerHTML = "Archived" + } +} + +function update_no_login() { + for (let i = 0; i < roles.length; ++i) { + let role = roles[i] + let role_id = "role_" + role.replace(/ /g, "_") + if (game.is_random && game.status === 0) + role = "Random " + (i+1) + document.getElementById(role_id + "_name").textContent = role + let player = players.find(p => p.role === role) + let element = document.getElementById(role_id) + + if (player) { + element.classList.remove("is_invite") + switch (game.status) { + case 3: + element.innerHTML = player.name + break + case 2: + element.innerHTML = user_link(player) + break + case 1: + if (player.is_invite) { + element.classList.add("is_invite") + element.innerHTML = user_link(player) + " ?" + } else { + element.classList.toggle("is_active", is_active(player, role)) + element.innerHTML = user_link(player) + } + break + case 0: + if (player.is_invite) { + element.classList.add("is_invite") + element.innerHTML = user_link(player) + " ?" + } else { + element.innerHTML = user_link(player) + } + break + } + } else { + element.classList.remove("is_invite") + element.innerHTML = `Empty` + } + } +} + +function update_login() { for (let i = 0; i < roles.length; ++i) { let role = roles[i] let role_id = "role_" + role.replace(/ /g, "_") @@ -257,22 +328,6 @@ function update() { } } - let message = window.message - if (game.status === 0) { - if (ready && (game.owner_id === user_id)) - message.innerHTML = "Ready to start..." - else if (ready) - message.innerHTML = `Waiting for ${game.owner_name} to start the game...` - else - message.innerHTML = "Waiting for players to join..." - } else if (game.status === 1) { - message.innerHTML = `Observe` - } else if (game.status === 2) { - message.innerHTML = `Review` - } else if (game.status === 3) { - message.innerHTML = "Archived" - } - if (game.owner_id === user_id) { window.start_button.disabled = !ready window.start_button.classList = (game.status === 0) ? "" : "hide" @@ -291,7 +346,7 @@ function update() { window.onload = function () { update() - if (game.status < 2) { + if (user_id && game.status < 2) { start_event_source() timer = setInterval(start_event_source, 15000) } -- cgit v1.2.3