From 26fa5f3398fbe2825329f2750490d8e741492ead Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Mon, 2 Oct 2017 04:30:30 -0400 Subject: [PATCH] Move playfield and editor html to separate files --- html/editor.html | 12 ++++++++++++ html/playfield.html | 15 +++++++++++++++ js/editor.js | 2 ++ js/playfield.js | 8 ++++---- server.js | 44 ++------------------------------------------ 5 files changed, 35 insertions(+), 46 deletions(-) create mode 100644 html/editor.html create mode 100644 html/playfield.html diff --git a/html/editor.html b/html/editor.html new file mode 100644 index 0000000..8f1da6d --- /dev/null +++ b/html/editor.html @@ -0,0 +1,12 @@ + + + + + Editor + + +
+ +
+ + diff --git a/html/playfield.html b/html/playfield.html new file mode 100644 index 0000000..d4055fc --- /dev/null +++ b/html/playfield.html @@ -0,0 +1,15 @@ + + + + + + Playfield + + +
+
DECK
+
DISCARD
+
+
+ + diff --git a/js/editor.js b/js/editor.js index 2410319..902972c 100644 --- a/js/editor.js +++ b/js/editor.js @@ -1,3 +1,5 @@ +document.title = "Editor|" + window.location.pathname.split('/')[2]; + window.addEventListener("load", () => { document.querySelector('#jsonUpload').addEventListener('change', event => { let files = event.target.files; diff --git a/js/playfield.js b/js/playfield.js index b1d22fc..34ae4b3 100644 --- a/js/playfield.js +++ b/js/playfield.js @@ -3,9 +3,11 @@ //jshint latedef:nofunc /* globals interact:true */ -let deckName, deckNum, deckJSON, cardCount, deckWidth, deckHeight, +let deckNum, deckJSON, cardCount, deckWidth, deckHeight, piles = {'deck': [], discard: []}; +document.title = "Playfield|" + window.location.pathname.split('/')[2]; + interact.dynamicDrop(true); window.addEventListener('load', () => { @@ -18,13 +20,11 @@ window.addEventListener('load', () => { shuffle(piles.deck); deckWidth = deckJSON.CustomDeck[deckNum].NumWidth; deckHeight = deckJSON.CustomDeck[deckNum].NumHeight; - console.log(deckName); }); - deckName = document.querySelector('#card-container').getAttribute("data-deckName"); xhr.open("GET", "deck.json"); xhr.send(); - window.addEventListener("contextmenu", event => event.preventDefault()); + window.addEventListener("contextmenu", event => event.preventDefault()); }); let cardInteract = interact('.card', {ignoreFrom: '.in-list'}) diff --git a/server.js b/server.js index bd8b316..47add4c 100644 --- a/server.js +++ b/server.js @@ -67,10 +67,10 @@ const server = http.createServer((req, res) => { let deckName = decodeURI(pathParts[2]); switch (pathParts[3]) { case 'play': - sendPlayfield(res, deckName); + sendFile(res, 'html/playfield.html'); break; case 'editor': - sendEditor(res, deckName); + sendFile(res, 'html/editor.html'); break; case 'deck.png': sendFile(res, deckName + '.png', 'image/png'); @@ -130,46 +130,6 @@ function sendDeckIndex(res, deckName) { res.end(html, 'utf-8'); } -function sendEditor(res, deckName) { - const html = ` - - - - - ${deckName} - Editor - - -
-
- - - `; - res.writeHead(200, {'Content-type': 'text/html; charset=utf-8'}); - res.end(html, 'utf-8'); -} - -function sendPlayfield(res, deckName) { - const html = ` - - - - - - ${deckName} - Playfield - - -
-
DECK
-
DISCARD
-
-
- - `; - res.writeHead(200, {'Content-type': 'text/html; charset=utf-8'}); - res.end(html, 'utf-8'); -} - - function sendFileJSON(res, deckName) { fs.readFile(deckName + '.json', (error, content) => { console.log(JSON.parse(content));