Skip to content
Permalink
Browse files

Merge pull request #511 from lusbenjamin/precon-decks

Precon decks
  • Loading branch information...
Manuel-777 committed Jul 29, 2019
2 parents 9895b78 + 6a6711a commit cd14be028e369f40959c0a073ddfab77df54e9e7
Showing with 74 additions and 2 deletions.
  1. +15 −0 shared/database.js
  2. +44 −2 shared/player-data.js
  3. +8 −0 window_background/background.js
  4. +7 −0 window_background/labels.js
@@ -11,14 +11,17 @@ class Database {
this.handleSetDb = this.handleSetDb.bind(this);
this.handleSetRewardResets = this.handleSetRewardResets.bind(this);
this.handleSetSeason = this.handleSetSeason.bind(this);
this.handleSetPreconDecks = this.handleSetPreconDecks.bind(this);
if (ipc) ipc.on("set_active_events", this.handleSetActiveEvents);
if (ipc) ipc.on("set_db", this.handleSetDb);
if (ipc) ipc.on("set_reward_resets", this.handleSetRewardResets);
if (ipc) ipc.on("set_season", this.handleSetSeason);
if (ipc) ipc.on("set_precon_decks", this.handleSetPreconDecks);

this.rewards_daily_ends = new Date();
this.rewards_weekly_ends = new Date();
this.activeEvents = [];
this.preconDecks = [];

const dbUri = `${__dirname}/../resources/database.json`;
const defaultDb = fs.readFileSync(dbUri, "utf8");
@@ -58,6 +61,18 @@ class Database {
}
}

handleSetPreconDecks(_event, arg) {
if (!arg || !arg.length) return;
try {
this.preconDecks = {};
arg.forEach(deck => (this.preconDecks[deck.id] = deck));
// console.log(this.preconDecks);
} catch (e) {
console.log("Error parsing JSON:", arg);
return false;
}
}

get abilities() {
return this.data.abilities;
}
@@ -213,6 +213,37 @@ function get_deck_colors(deck) {
return colorIndices;
}

function prettierDeckData(deckData) {
// many precon descriptions are total garbage
// manually update them with generic descriptions
const prettyDescriptions = {
"Decks/Precon/Precon_EPP_BG_Desc": "Golgari Swarm",
"Decks/Precon/Precon_EPP_BR_Desc": "Cult of Rakdos",
"Decks/Precon/Precon_EPP_GU_Desc": "Simic Combine",
"Decks/Precon/Precon_EPP_GW_Desc": "Selesnya Conclave",
"Decks/Precon/Precon_EPP_RG_Desc": "Gruul Clans",
"Decks/Precon/Precon_EPP_RW_Desc": "Boros Legion",
"Decks/Precon/Precon_EPP_UB_Desc": "House Dimir",
"Decks/Precon/Precon_EPP_UR_Desc": "Izzet League",
"Decks/Precon/Precon_EPP_WB_Desc": "Orzhov Syndicate",
"Decks/Precon/Precon_EPP_WU_Desc": "Azorius Senate",
"Decks/Precon/Precon_July_B": "Mono Black",
"Decks/Precon/Precon_July_U": "Mono Blue",
"Decks/Precon/Precon_July_G": "Mono Green",
"Decks/Precon/Precon_July_R": "Mono Red",
"Decks/Precon/Precon_July_W": "Mono White"
};
if (deckData.description in prettyDescriptions) {
deckData.description = prettyDescriptions[deckData.description];
}
if (deckData.name.includes("?=?Loc")) {
// precon deck names are garbage address locators
// mask them with description instead
deckData.name = deckData.description || "Preconstructed Deck";
}
return deckData;
}

class PlayerData {
constructor() {
if (PlayerData.instance) return PlayerData.instance;
@@ -329,12 +360,15 @@ class PlayerData {

deck(id) {
if (!this.deckExists(id)) return false;
return {
const preconData = db.preconDecks[id] || {};
const deckData = {
...preconData,
...this.decks[id],
colors: get_deck_colors(this.decks[id]),
custom: !this.static_decks.includes(id),
tags: this.decks_tags[id] || []
};
return prettierDeckData(deckData);
}

deckExists(id) {
@@ -373,7 +407,15 @@ class PlayerData {
match(id) {
if (!this.matchExists(id)) return false;
const matchData = this[id];
const playerDeck = { ...defaultDeck, ...matchData.playerDeck };
let preconData = {};
if (matchData.playerDeck && matchData.playerDeck.id in db.preconDecks) {
preconData = db.preconDecks[matchData.playerDeck.id];
}
const playerDeck = prettierDeckData({
...defaultDeck,
...preconData,
...matchData.playerDeck
});
playerDeck.colors = get_deck_colors(playerDeck);

const oppDeck = { ...defaultDeck, ...matchData.oppDeck };
@@ -56,6 +56,7 @@ const {
onLabelInEventGetCombinedRankInfo,
onLabelInDeckGetDeckLists,
onLabelInDeckGetDeckListsV3,
onLabelInDeckGetPreconDecks,
onLabelInEventGetPlayerCourses,
onLabelInEventGetPlayerCoursesV2,
onLabelInDeckUpdateDeck,
@@ -787,6 +788,13 @@ function onLogEntryFound(entry) {
}
break;

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

case "Deck.UpdateDeck":
if (entry.arrow == "<==") {
json = entry.json();
@@ -349,6 +349,12 @@ function onLabelInDeckGetDeckListsV3(entry, json) {
onLabelInDeckGetDeckLists(entry, json.map(d => convert_deck_from_v3(d)));
}

function onLabelInDeckGetPreconDecks(entry, json) {
if (!json) return;
ipc_send("set_precon_decks", json);
// console.log(json);
}

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

@@ -971,6 +977,7 @@ module.exports = {
onLabelInEventGetCombinedRankInfo,
onLabelInDeckGetDeckLists,
onLabelInDeckGetDeckListsV3,
onLabelInDeckGetPreconDecks,
onLabelInEventGetPlayerCourses,
onLabelInEventGetPlayerCoursesV2,
onLabelInDeckUpdateDeck,

0 comments on commit cd14be0

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