Permalink
Browse files

Fix sideboard handling

  • Loading branch information...
dougmill committed Jan 26, 2019
1 parent 8b4a3c8 commit 7d6737dc55ab9969b99e39480b7582477c6b6a7e
Showing with 32 additions and 40 deletions.
  1. +32 −40 window_background/labels.js
@@ -382,55 +382,47 @@ function onLabelGreToClient(entry, json) {

function onLabelClientToMatchServiceMessageTypeClientToGREMessage(entry, json) {
if (!json) return;
if (!json.payload) return
if (!json.payload.type) return
if (!json.Payload) return;
if (!json.Payload.SubmitDeckResp) return;

// Get sideboard changes
if (json.payload.type == "ClientMessageType_SubmitDeckResp") {

let tempMain = {};
let tempSide = {};
json.payload.submitDeckResp.deck.deckCards.forEach( function (grpId) {
if (tempMain[grpId] == undefined) {
tempMain[grpId] = 1
let tempMain = {};
let tempSide = {};
json.Payload.SubmitDeckResp.Deck.DeckCards.forEach(function (grpId) {
if (tempMain[grpId] == undefined) {
tempMain[grpId] = 1
}
else {
tempMain[grpId] += 1;
}
});
if (json.Payload.SubmitDeckResp.Deck.SideboardCards !== undefined) {
json.Payload.SubmitDeckResp.Deck.SideboardCards.forEach(function (grpId) {
if (tempSide[grpId] == undefined) {
tempSide[grpId] = 1
}
else {
tempMain[grpId] += 1;
tempSide[grpId] += 1;
}
});
if (json.payload.submitDeckResp.deck.sideboardCards !== undefined) {
json.payload.submitDeckResp.deck.sideboardCards.forEach( function (grpId) {
if (tempSide[grpId] == undefined) {
tempSide[grpId] = 1
}
else {
tempSide[grpId] += 1;
}
});
}

var newDeck = {}
newDeck.mainDeck = [];
Object.keys(tempMain).forEach(function(key) {
var c = {"id": key, "quantity": tempMain[key]};
newDeck.mainDeck.push(c);
});
}

newDeck.sideboard = [];
if (json.payload.submitDeckResp.deck.sideboardCards !== undefined) {
Object.keys(tempSide).forEach(function(key) {
var c = {"id": key, "quantity": tempSide[key]};
newDeck.sideboard.push(c);
});
}
var newDeck = {};
newDeck.mainDeck = [];
Object.keys(tempMain).forEach(function (key) {
var c = {"id": key, "quantity": tempMain[key]};
newDeck.mainDeck.push(c);
});

//get_deck_sideboarded(currentDeck, newDeck)
//select_deck(newDeck);
currentDeck = newDeck;
ipc_send("set_deck", currentDeck, windowOverlay);
//console.log(JSON.stringify(currentDeck));
//console.log(currentDeck);
newDeck.sideboard = [];
if (json.Payload.SubmitDeckResp.Deck.SideboardCards !== undefined) {
Object.keys(tempSide).forEach(function (key) {
var c = {"id": key, "quantity": tempSide[key]};
newDeck.sideboard.push(c);
});
}
currentDeck = newDeck;
ipc_send("set_deck", currentDeck, windowOverlay);
}

function onLabelInEventGetPlayerCourse(entry, json) {

0 comments on commit 7d6737d

Please sign in to comment.