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: []};
|
||||
|
||||
interact.dynamicDrop(true);
|
||||
@ -6,16 +6,17 @@ interact.dynamicDrop(true);
|
||||
window.addEventListener('load', () => {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.addEventListener("load", () => {
|
||||
deckJSON = JSON.parse(xhr.responseText).ObjectStates[0];
|
||||
piles.deck = deckJSON.DeckIDs.map(c => c - 100);
|
||||
deckJSON = JSON.parse(xhr.responseText);
|
||||
deckNum = Object.keys(deckJSON.CustomDeck)[0];
|
||||
piles.deck = deckJSON.DeckIDs.map(c => c - deckNum * 100);
|
||||
cardCount = piles.deck.length;
|
||||
shuffle(piles.deck);
|
||||
deckWidth = deckJSON.CustomDeck["1"].NumWidth;
|
||||
deckHeight = deckJSON.CustomDeck["1"].NumHeight;
|
||||
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/" + deckName + "/deck.json");
|
||||
xhr.open("GET", "deck.json");
|
||||
xhr.send();
|
||||
|
||||
window.addEventListener("contextmenu", event => event.preventDefault());
|
||||
@ -182,10 +183,10 @@ interact('.card-pile')
|
||||
searchBox.setAttribute('type', 'search');
|
||||
searchBox.setAttribute('placeholder', 'Filter');
|
||||
searchBox.addEventListener('input', event => {
|
||||
let input = event.target.value;
|
||||
Array.from(cardList.children).forEach(card => {
|
||||
let input = event.target.value;
|
||||
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 =
|
||||
(cardData.Nickname.toLowerCase().includes(input.toLowerCase()) ||
|
||||
cardData.Description.toLowerCase().includes(input.toLowerCase())) ?
|
||||
@ -224,8 +225,8 @@ function makeCard(cardNum) {
|
||||
card.style.backgroundPositionX =
|
||||
-(cardNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px";
|
||||
card.style.backgroundPositionY =
|
||||
card.style.backgroundImage = "url('deck.png')";
|
||||
-Math.floor(cardNum/deckWidth) * parseInt(style.getPropertyValue("height")) + "px";
|
||||
card.style.backgroundImage = `url(${deckJSON.CustomDeck[deckNum].FaceURL})`;
|
||||
card.style.backgroundSize = `${deckWidth * 100}% ${deckHeight * 100}%`;
|
||||
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');
|
||||
break;
|
||||
case 'deck.json':
|
||||
sendFile(res, deckName + '.json', 'application/json');
|
||||
sendFileJSON(res, deckName);
|
||||
break;
|
||||
case 'upload':
|
||||
handleUpload(res, req, deckName);
|
||||
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) {
|
||||
let body = '';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user