Switch Playfield to use Fetch instead of XMLHTTPRequest

This commit is contained in:
Adam Goldsmith 2017-10-12 03:15:28 -04:00
parent 08e5a8f376
commit b435916f32

View File

@ -11,9 +11,10 @@ document.title = "Playfield|" + window.location.pathname.split('/')[2];
interact.dynamicDrop(true); interact.dynamicDrop(true);
window.addEventListener('load', () => { window.addEventListener('load', () => {
let xhr = new XMLHttpRequest(); fetch("deck.json")
xhr.addEventListener("load", () => { .then(data => data.json())
deckJSON = JSON.parse(xhr.responseText); .then(json => {
deckJSON = json;
deckNum = Object.keys(deckJSON.CustomDeck)[0]; deckNum = Object.keys(deckJSON.CustomDeck)[0];
piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100); piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100);
cardCount = piles.deck.length; cardCount = piles.deck.length;
@ -21,8 +22,6 @@ window.addEventListener('load', () => {
deckWidth = deckJSON.CustomDeck[deckNum].NumWidth; deckWidth = deckJSON.CustomDeck[deckNum].NumWidth;
deckHeight = deckJSON.CustomDeck[deckNum].NumHeight; deckHeight = deckJSON.CustomDeck[deckNum].NumHeight;
}); });
xhr.open("GET", "deck.json");
xhr.send();
window.addEventListener("contextmenu", event => event.preventDefault()); window.addEventListener("contextmenu", event => event.preventDefault());
}); });