mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-07-13 06:30:57 -05:00
Save the last deck, and select the starter deck by default
This commit is contained in:
parent
6064f1f47c
commit
ff9039f245
|
|
@ -40,6 +40,16 @@ function updatePlayerListItem(playerIndex: number) {
|
|||
listItem.innerText = "Waiting...";
|
||||
}
|
||||
|
||||
function updateDeckCount() {
|
||||
var count = 0;
|
||||
for (var el of cardButtons) {
|
||||
if (el.inputElement.checked)
|
||||
count++;
|
||||
}
|
||||
document.getElementById('countLabel')!.innerText = count.toString();
|
||||
submitDeckButton.disabled = (count != 15);
|
||||
}
|
||||
|
||||
submitDeckButton.addEventListener('click', e => {
|
||||
let req = new XMLHttpRequest();
|
||||
req.open('POST', `${config.apiBaseUrl}/games/${currentGame!.id}/chooseDeck`);
|
||||
|
|
@ -60,4 +70,22 @@ submitDeckButton.addEventListener('click', e => {
|
|||
data.append('deckName', 'Deck');
|
||||
data.append('deckCards', cardsString);
|
||||
req.send(data.toString());
|
||||
localStorage.setItem('lastDeck', cardsString);
|
||||
});
|
||||
|
||||
const starterDeck = [ 6, 34, 159, 13, 45, 137, 22, 52, 141, 28, 55, 103, 40, 56, 92 ];
|
||||
const lastDeckString = localStorage.getItem('lastDeck');
|
||||
const lastDeck = lastDeckString?.split(/\+/)?.map(s => parseInt(s)) || starterDeck;
|
||||
|
||||
cardDatabase.loadAsync().then(cards => {
|
||||
const cardList = document.getElementById('cardList')!;
|
||||
for (const card of cards) {
|
||||
const button = new CardButton('checkbox', card);
|
||||
cardButtons.push(button);
|
||||
button.inputElement.checked = lastDeck != null && lastDeck.includes(card.number);
|
||||
button.inputElement.addEventListener('input', updateDeckCount);
|
||||
cardList.appendChild(button.element);
|
||||
}
|
||||
updateDeckCount();
|
||||
document.getElementById('cardListLoadingSection')!.hidden = true;
|
||||
}).catch(e => document.getElementById('errorModal')!.hidden = false);
|
||||
|
|
|
|||
|
|
@ -36,10 +36,6 @@ function onGameStateChange(game: any, playerData: any) {
|
|||
break;
|
||||
case GameState.Preparing:
|
||||
showSection('deck');
|
||||
for (const button of cardButtons.slice(0, 15)) {
|
||||
button.inputElement.checked = true;
|
||||
}
|
||||
submitDeckButton.disabled = false;
|
||||
break;
|
||||
case GameState.Redraw:
|
||||
case GameState.Ongoing:
|
||||
|
|
@ -75,25 +71,6 @@ function onGameStateChange(game: any, playerData: any) {
|
|||
|
||||
showSection('preGame');
|
||||
|
||||
cardDatabase.loadAsync().then(cards => {
|
||||
const cardList = document.getElementById('cardList')!;
|
||||
for (var card of cards) {
|
||||
const button = new CardButton('checkbox', card);
|
||||
cardButtons.push(button);
|
||||
button.inputElement.addEventListener('input', e => {
|
||||
var count = 0;
|
||||
for (var el of cardButtons) {
|
||||
if (el.inputElement.checked)
|
||||
count++;
|
||||
}
|
||||
document.getElementById('countLabel')!.innerText = count.toString();
|
||||
submitDeckButton.disabled = (count != 15);
|
||||
});
|
||||
cardList.appendChild(button.element);
|
||||
}
|
||||
document.getElementById('cardListLoadingSection')!.hidden = true;
|
||||
}).catch(e => document.getElementById('errorModal')!.hidden = false);
|
||||
|
||||
function isInternetExplorer() {
|
||||
return !!(window.document as any).documentMode; // This is a non-standard property implemented only by Internet Explorer.
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user