Move playfield and editor html to separate files
This commit is contained in:
parent
6444eae91d
commit
c21d1866be
12
html/editor.html
Normal file
12
html/editor.html
Normal file
@ -0,0 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="/js/editor.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title>Editor</title>
|
||||
</head>
|
||||
<body>
|
||||
<input id="jsonUpload" type="file"><br>
|
||||
|
||||
<div id="deck"></div>
|
||||
</body>
|
||||
</html>
|
15
html/playfield.html
Normal file
15
html/playfield.html
Normal file
@ -0,0 +1,15 @@
|
||||
<html>
|
||||
<head>
|
||||
<script src="/js/interact.js"></script>
|
||||
<script src="/js/playfield.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title>Playfield</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="card-container">
|
||||
<div class="card-pile deck" data-pile="deck">DECK</div>
|
||||
<div class="card-pile discard" data-pile="discard">DISCARD</div>
|
||||
<div id="hand"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -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;
|
||||
|
@ -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,9 +20,7 @@ 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();
|
||||
|
||||
|
44
server.js
44
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 = `
|
||||
<html>
|
||||
<head>
|
||||
<script src="/js/editor.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title>${deckName} - Editor</title>
|
||||
</head>
|
||||
<body>
|
||||
<input id="jsonUpload" type="file"><br>
|
||||
<div id="deck"></div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
res.writeHead(200, {'Content-type': 'text/html; charset=utf-8'});
|
||||
res.end(html, 'utf-8');
|
||||
}
|
||||
|
||||
function sendPlayfield(res, deckName) {
|
||||
const html = `
|
||||
<html>
|
||||
<head>
|
||||
<script src="/js/interact.js"></script>
|
||||
<script src="/js/playfield.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<title>${deckName} - Playfield</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="card-container" data-deckName="${deckName}">
|
||||
<div class="card-pile deck" data-pile="deck">DECK</div>
|
||||
<div class="card-pile discard" data-pile="discard">DISCARD</div>
|
||||
<div id="hand"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>`;
|
||||
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));
|
||||
|
Loading…
Reference in New Issue
Block a user