Edited spacing, prepend role count instead of append

This commit is contained in:
Maier
2020-05-07 05:24:26 -04:00
parent 0049962371
commit c42670c28e
2 changed files with 11 additions and 10 deletions

View File

@@ -204,6 +204,7 @@ function renderGame() {
}
function renderDeadAndAliveInformation() {
// TODO: Refactor this function.
let infoContainer = document.getElementById("info-container");
let alivePlayers = currentGame.players.filter((player) => !player.dead).sort((a, b) =>
{
@@ -235,7 +236,7 @@ function renderDeadAndAliveInformation() {
let aliveHeader = document.createElement("h2");
aliveContainer.appendChild(aliveHeader);
aliveHeader.innerText = "Roles Still Alive";
var rollCounter={}; //RTM
var rollCounter = {}; // RTM
alivePlayers.forEach((player) => {
let alivePlayerClass = player.card.team === "good" ? "alive-player-village" : "alive-player-evil";
if (player.card.isTypeOfWerewolf) {
@@ -243,21 +244,21 @@ function renderDeadAndAliveInformation() {
}
//RTM
if (rollCounter.hasOwnProperty(player.card.role)) {
rollCounter[player.card.role]+=1;
rollCounter[player.card.role] += 1;
}
else {
rollCounter[player.card.role]=1;
rollCounter[player.card.role] = 1;
//RTM
const alivePlayer = document.createElement("div");
alivePlayer.setAttribute("class", "alive-player " + alivePlayerClass);
alivePlayer.innerHTML = "<p>" + player.card.role + "</p><img src='../assets/images/info.svg'/>";
let roleCount=document.createElement("span");//RTM
let roleCount = document.createElement("span"); // RTM
roleCount.setAttribute("class","rolecount");
//Add hidden description span - RTM 4/18/2020
let playerCardInfo=document.createElement("span");
playerCardInfo.setAttribute("class","tooltiptext");
playerCardInfo.innerText=player.card.description;
alivePlayer.appendChild(roleCount);
alivePlayer.prepend(roleCount);
alivePlayer.appendChild(playerCardInfo);
aliveContainer.appendChild(alivePlayer);
}
@@ -268,18 +269,18 @@ function renderDeadAndAliveInformation() {
infoContainer.appendChild(killedContainer);
infoContainer.appendChild(aliveContainer);
document.getElementById("game-container").appendChild(infoContainer);
//Has to be done AFTER the infoContainer is rendered in the DOM to insert the updated counts
// Has to be done AFTER the infoContainer is rendered in the DOM to insert the updated counts
for (let x of document.getElementsByClassName("alive-player")) {
x.getElementsByClassName("rolecount")[0].innerHTML=rollCounter[x.getElementsByTagName("P")[0].innerHTML];
x.getElementsByClassName("rolecount")[0].innerText = rollCounter[x.getElementsByTagName("p")[0].innerText];
}
} else {
document.getElementById("killed-container").remove();
document.getElementById("alive-container").remove();
document.getElementById("info-container").append(killedContainer);
document.getElementById("info-container").append(aliveContainer);
//Has to be done AFTER the infoContainer is rendered in the DOM to insert the updated counts
// Has to be done AFTER the infoContainer is rendered in the DOM to insert the updated counts
for (let x of document.getElementsByClassName("alive-player")) {
x.getElementsByClassName("rolecount")[0].innerHTML=rollCounter[x.getElementsByTagName("P")[0].innerHTML];
x.getElementsByClassName("rolecount")[0].innerText = rollCounter[x.getElementsByTagName("p")[0].innerText];
}
}
}