Skip to content
Permalink
Browse files

Handle new labels and deck format from March update

  • Loading branch information...
dougmill committed Mar 28, 2019
1 parent 88fa65d commit dff0b0a78973026b8e66bf354a145838c4440154
Showing with 86 additions and 18 deletions.
  1. +10 −5 shared/util.js
  2. +43 −7 window_background/background.js
  3. +33 −6 window_background/labels.js
@@ -2150,12 +2150,17 @@ function get_deck_export_txt(deck) {
}

//
function convert_from_v3_list(list) {
let ret = [];
for (var i=0; i < list.length; i+=2) {
ret.push({'id' : list[i], 'quantity' : list[i+1]});
function convert_deck_from_v3(deck) {
return JSON.parse(JSON.stringify(deck), (key, value) => {
if (key === "mainDeck" || key === "sideboard") {
let ret = [];
for (let i = 0; i < value.length; i += 2) {
ret.push({ id : value[i], quantity : value[i + 1] });
}
return ret;
}
return ret;
return value;
})
}

//
@@ -14,14 +14,19 @@ global
compare_archetypes,
onLabelClientToMatchServiceMessageTypeClientToGREMessage,
onLabelInEventGetPlayerCourse,
onLabelInEventGetPlayerCourseV2,
onLabelInEventGetCombinedRankInfo,
onLabelInDeckGetDeckLists,
onLabelInDeckGetDeckListsV3,
onLabelInEventGetPlayerCourses,
onLabelInEventGetPlayerCoursesV2,
onLabelInDeckUpdateDeck,
onLabelInDeckUpdateDeckV3,
onLabelInventoryUpdated,
onLabelInPlayerInventoryGetPlayerInventory,
onLabelInPlayerInventoryGetPlayerCardsV3,
onLabelInEventDeckSubmit,
onLabelInEventDeckSubmitV3,
onLabelEventMatchCreated,
onLabelOutDirectGameChallenge,
onLabelInDraftDraftStatus,
@@ -981,6 +986,13 @@ function onLogEntryFound(entry) {
}
break;

case "Event.GetPlayerCourseV2":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInEventGetPlayerCourseV2(entry, json);
}
break;

case "Event.GetCombinedRankInfo":
if (entry.arrow == "<==") {
json = entry.json();
@@ -1002,20 +1014,41 @@ function onLogEntryFound(entry) {
}
break;

case "Deck.GetDeckListsV3":
case "Event.GetPlayerCoursesV2":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInEventGetPlayerCoursesV2(entry, json);
}
break;

case "Deck.GetDeckLists":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInDeckGetDeckLists(entry, json);
}
break;

case "Deck.UpdateDeckV3":
case "Deck.GetDeckListsV3":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInDeckGetDeckListsV3(entry, json);
}
break;

case "Deck.UpdateDeck":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInDeckUpdateDeck(entry, json);
}
break;

case "Deck.UpdateDeckV3":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInDeckUpdateDeckV3(entry, json);
}
break;

case "Inventory.Updated":
json = entry.json();
onLabelInventoryUpdated(entry, json);
@@ -1035,13 +1068,20 @@ function onLogEntryFound(entry) {
}
break;

case "Event.DeckSubmitV3":
case "Event.DeckSubmit":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInEventDeckSubmit(entry, json);
}
break;

case "Event.DeckSubmitV3":
if (entry.arrow == "<==") {
json = entry.json();
onLabelInEventDeckSubmitV3(entry, json);
}
break;

case "Event.MatchCreated":
json = entry.json();
onLabelEventMatchCreated(entry, json);
@@ -1607,10 +1647,6 @@ function select_deck(arg) {
} else {
currentDeck = arg;
}

currentDeck.mainDeck = convert_from_v3_list(currentDeck.mainDeck);
currentDeck.sideboard = convert_from_v3_list(currentDeck.sideboard);

originalDeck = currentDeck;
//console.log(currentDeck, arg);
ipc_send("set_deck", currentDeck, windowOverlay);
@@ -724,6 +724,14 @@ function onLabelInEventGetPlayerCourse(entry, json) {
}
}

function onLabelInEventGetPlayerCourseV2(entry, json) {
if (!json) return;
if (json.CourseDeck) {
json.CourseDeck = convert_deck_from_v3(json.CourseDeck);
}
onLabelInEventGetPlayerCourse(entry, json);
}

function onLabelInEventGetCombinedRankInfo(entry, json) {
if (!json) return;

@@ -774,9 +782,6 @@ function onLabelInDeckGetDeckLists(entry, json) {
deck.tags.push(formats[deck.format]);
}

deck.mainDeck = convert_from_v3_list(deck.mainDeck);
deck.sideboard = convert_from_v3_list(deck.sideboard);

decks[deckId] = deck;
if (decks["index"].indexOf(deckId) == -1) {
decks["index"].push(deck.id);
@@ -789,6 +794,11 @@ function onLabelInDeckGetDeckLists(entry, json) {
ipc_send("set_decks", JSON.stringify(decks));
}

function onLabelInDeckGetDeckListsV3(entry, json) {
if (!json) return;
onLabelInDeckGetDeckLists(entry, json.map(d => convert_deck_from_v3(d)));
}

function onLabelInEventGetPlayerCourses(entry, json) {
if (!json) return;

@@ -807,6 +817,16 @@ function onLabelInEventGetPlayerCourses(entry, json) {
});
}

function onLabelInEventGetPlayerCoursesV2(entry, json) {
if (!json) return;
json.forEach(course => {
if (course.CourseDeck) {
course.CourseDeck = convert_deck_from_v3(course.CourseDeck);
}
});
onLabelInEventGetPlayerCourses(entry, json);
}

function onLabelInDeckUpdateDeck(entry, json) {
if (!json) return;
logTime = parseWotcTime(entry.timestamp);
@@ -825,9 +845,6 @@ function onLabelInDeckUpdateDeck(entry, json) {
previousSide: _deck.sideboard
};

json.mainDeck = convert_from_v3_list(json.mainDeck);
json.sideboard = convert_from_v3_list(json.sideboard);

// Check Mainboard
_deck.mainDeck.forEach(function(card) {
var cardObj = cardsDb.get(card.id);
@@ -888,6 +905,11 @@ function onLabelInDeckUpdateDeck(entry, json) {
});
}

function onLabelInDeckUpdateDeckV3(entry, json) {
if (!json) return;
onLabelInDeckUpdateDeck(entry, convert_deck_from_v3(json));
}

function onLabelInventoryUpdated(entry, json) {
if (!json) return;
json.date = parseWotcTime(entry.timestamp);
@@ -970,6 +992,11 @@ function onLabelInEventDeckSubmit(entry, json) {
select_deck(json);
}

function onLabelInEventDeckSubmitV3(entry, json) {
if (!json) return;
onLabelInEventDeckSubmit(entry, convert_deck_from_v3(json));
}

function onLabelEventMatchCreated(entry, json) {
if (!json) return;
matchBeginTime = parseWotcTime(entry.timestamp);

0 comments on commit dff0b0a

Please sign in to comment.
You can’t perform that action at this time.