From 6cf749b0a21141fbc1edbd8d5ec5d5d0e5116f4c Mon Sep 17 00:00:00 2001 From: Alec Maier Date: Sat, 11 Apr 2020 13:43:56 -0400 Subject: [PATCH] Preliminary custom role saving --- static/setup.js | 49 +++++++++++++++++++++++++++++++++++++++++- static/styles.css | 4 ++++ views/create_game.html | 4 ++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/static/setup.js b/static/setup.js index d7c2ba6..bfb71c0 100644 --- a/static/setup.js +++ b/static/setup.js @@ -45,7 +45,8 @@ Array.from(document.getElementsByClassName("close")).forEach(function(element) { }); // render all of the available cards to the user -window.onload = function() { +window.onload = function() { + readInUserCustomRoles(); renderAvailableCards(); }; @@ -111,11 +112,22 @@ function renderAvailableCards() { cardTop.quantityEl = cardQuantity; cardBottom.card = newCard; cardBottom.quantityEl = cardQuantity; + + if (cards[i].custom) { + addRemoveButtonToCustomCard(i); + } } renderCustomCard(); resetCardQuantities(); } +function addRemoveButtonToCustomCard(i) { + let button = document.createElement("button"); + button.setAttribute("class", "removal-btn"); + button.innerText = "Remove"; + document.getElementById("card-" + i).appendChild(button); +} + function renderCustomCard() { let customCard = document.createElement("div"); customCard.classList.add("card", "custom-card"); @@ -149,9 +161,44 @@ function addCustomCardToRoles(e) { document.getElementById("card-select").innerHTML = ""; document.getElementById("roles").innerHTML = ""; renderAvailableCards(); + + if (document.getElementById("custom-role-remember").checked) { + let existingRoles = localStorage.getItem("play-werewolf-custom-roles"); + if (existingRoles !== null) { + let rolesArray; + try { + rolesArray = JSON.parse(existingRoles); + } catch(e) { + console.error(e.message); + } + if (rolesArray) { + rolesArray.push(newCard); + } + localStorage.setItem("play-werewolf-custom-roles", JSON.stringify(rolesArray)); + } else { + localStorage.setItem("play-werewolf-custom-roles", JSON.stringify(new Array(newCard))); + } + } closeModal(); } +function readInUserCustomRoles() { + let existingRoles = localStorage.getItem("play-werewolf-custom-roles"); + if (existingRoles !== null) { + let rolesArray; + try { + rolesArray = JSON.parse(existingRoles); + } catch(e) { + console.error(e.message); + } + if (rolesArray) { + rolesArray.forEach((role) => { + cards.push(role); + }) + } + } +} + function incrementCardQuantity(e) { if(e.target.card.quantity < 25) { diff --git a/static/styles.css b/static/styles.css index f4c98a6..7fc62ae 100644 --- a/static/styles.css +++ b/static/styles.css @@ -993,9 +993,13 @@ label { align-items: center; width: 100%; height: 100%; + transform: rotateX(0deg); -webkit-perspective: 0; -webkit-backface-visibility: hidden; -webkit-transform: translate3d(0,0,0); + -moz-backface-visibility: hidden; + -moz-transform: translate3d(0, 0, 0); + -moz-perspective: 0; visibility:visible; backface-visibility: hidden; } diff --git a/views/create_game.html b/views/create_game.html index f32d7c7..9a05ca1 100644 --- a/views/create_game.html +++ b/views/create_game.html @@ -40,6 +40,10 @@ +
+ + +