Load more stuff from deck JSON
actually uses deck number and FaceURL preperation for arbitrary decks (from TTS mods) also changes to send only the deck part of the JSON
This commit is contained in:
parent
6619e20f4a
commit
2b9139dd66
@ -1,4 +1,4 @@
|
|||||||
let deckName, deckJSON, cardCount, deckWidth, deckHeight,
|
let deckName, deckNum, deckJSON, cardCount, deckWidth, deckHeight,
|
||||||
piles = {'deck': [], discard: []};
|
piles = {'deck': [], discard: []};
|
||||||
|
|
||||||
interact.dynamicDrop(true);
|
interact.dynamicDrop(true);
|
||||||
@ -6,16 +6,17 @@ interact.dynamicDrop(true);
|
|||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
let xhr = new XMLHttpRequest();
|
let xhr = new XMLHttpRequest();
|
||||||
xhr.addEventListener("load", () => {
|
xhr.addEventListener("load", () => {
|
||||||
deckJSON = JSON.parse(xhr.responseText).ObjectStates[0];
|
deckJSON = JSON.parse(xhr.responseText);
|
||||||
piles.deck = deckJSON.DeckIDs.map(c => c - 100);
|
deckNum = Object.keys(deckJSON.CustomDeck)[0];
|
||||||
|
piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100);
|
||||||
cardCount = piles.deck.length;
|
cardCount = piles.deck.length;
|
||||||
shuffle(piles.deck);
|
shuffle(piles.deck);
|
||||||
deckWidth = deckJSON.CustomDeck["1"].NumWidth;
|
deckWidth = deckJSON.CustomDeck[deckNum].NumWidth;
|
||||||
deckHeight = deckJSON.CustomDeck["1"].NumHeight;
|
deckHeight = deckJSON.CustomDeck[deckNum].NumHeight;
|
||||||
console.log(deckName);
|
console.log(deckName);
|
||||||
});
|
});
|
||||||
deckName = document.querySelector('#card-container').getAttribute("data-deckName");
|
deckName = document.querySelector('#card-container').getAttribute("data-deckName");
|
||||||
xhr.open("GET", "/deck/" + deckName + "/deck.json");
|
xhr.open("GET", "deck.json");
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
|
||||||
window.addEventListener("contextmenu", event => event.preventDefault());
|
window.addEventListener("contextmenu", event => event.preventDefault());
|
||||||
@ -182,10 +183,10 @@ interact('.card-pile')
|
|||||||
searchBox.setAttribute('type', 'search');
|
searchBox.setAttribute('type', 'search');
|
||||||
searchBox.setAttribute('placeholder', 'Filter');
|
searchBox.setAttribute('placeholder', 'Filter');
|
||||||
searchBox.addEventListener('input', event => {
|
searchBox.addEventListener('input', event => {
|
||||||
Array.from(cardList.children).forEach(card => {
|
|
||||||
let input = event.target.value;
|
let input = event.target.value;
|
||||||
|
Array.from(cardList.children).forEach(card => {
|
||||||
let cardNum = parseInt(card.getAttribute('data-num'));
|
let cardNum = parseInt(card.getAttribute('data-num'));
|
||||||
let cardData = deckJSON.ContainedObjects.find(c => c.CardID === (cardNum + 100));
|
let cardData = deckJSON.ContainedObjects.find(c => c.CardID === (cardNum + deckNum * 100));
|
||||||
card.style.display =
|
card.style.display =
|
||||||
(cardData.Nickname.toLowerCase().includes(input.toLowerCase()) ||
|
(cardData.Nickname.toLowerCase().includes(input.toLowerCase()) ||
|
||||||
cardData.Description.toLowerCase().includes(input.toLowerCase())) ?
|
cardData.Description.toLowerCase().includes(input.toLowerCase())) ?
|
||||||
@ -224,8 +225,8 @@ function makeCard(cardNum) {
|
|||||||
card.style.backgroundPositionX =
|
card.style.backgroundPositionX =
|
||||||
-(cardNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px";
|
-(cardNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px";
|
||||||
card.style.backgroundPositionY =
|
card.style.backgroundPositionY =
|
||||||
card.style.backgroundImage = "url('deck.png')";
|
|
||||||
-Math.floor(cardNum/deckWidth) * parseInt(style.getPropertyValue("height")) + "px";
|
-Math.floor(cardNum/deckWidth) * parseInt(style.getPropertyValue("height")) + "px";
|
||||||
|
card.style.backgroundImage = `url(${deckJSON.CustomDeck[deckNum].FaceURL})`;
|
||||||
card.style.backgroundSize = `${deckWidth * 100}% ${deckHeight * 100}%`;
|
card.style.backgroundSize = `${deckWidth * 100}% ${deckHeight * 100}%`;
|
||||||
document.body.removeChild(card);
|
document.body.removeChild(card);
|
||||||
|
|
||||||
|
14
server.js
14
server.js
@ -76,7 +76,8 @@ const server = http.createServer((req, res) => {
|
|||||||
sendFile(res, deckName + '.png', 'image/png');
|
sendFile(res, deckName + '.png', 'image/png');
|
||||||
break;
|
break;
|
||||||
case 'deck.json':
|
case 'deck.json':
|
||||||
sendFile(res, deckName + '.json', 'application/json');
|
sendFileJSON(res, deckName);
|
||||||
|
break;
|
||||||
case 'upload':
|
case 'upload':
|
||||||
handleUpload(res, req, deckName);
|
handleUpload(res, req, deckName);
|
||||||
break;
|
break;
|
||||||
@ -169,6 +170,17 @@ function sendPlayfield(res, deckName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function sendFileJSON(res, deckName) {
|
||||||
|
fs.readFile(deckName + '.json', (error, content) => {
|
||||||
|
console.log(JSON.parse(content));
|
||||||
|
res.writeHead(200, {'Content-type': 'application/json; charset=utf-8'});
|
||||||
|
res.end(JSON.stringify(JSON.parse(content).ObjectStates[0]), 'utf-8');
|
||||||
|
if (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function handleUpload(res, req) {
|
function handleUpload(res, req) {
|
||||||
let body = '';
|
let body = '';
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user