Skip to content
Permalink
Browse files

set completion tables

  • Loading branch information...
Manuel-777 committed Oct 12, 2019
1 parent a92c69b commit a927a41206a1aba0b29569c846f3e4e36e67c3e2
Showing with 191 additions and 9 deletions.
  1. +27 −7 shared/colors.js
  2. +2 −0 shared/constants.js
  3. +7 −0 shared/shared.css
  4. +76 −0 window_main/collection.js
  5. +79 −2 window_main/index.css
@@ -1,4 +1,12 @@
const { WHITE, BLUE, BLACK, RED, GREEN } = require("../shared/constants.js");
const {
WHITE,
BLUE,
BLACK,
RED,
GREEN,
MULTI,
COLORLESS
} = require("../shared/constants.js");

class Colors {
/**
@@ -50,6 +58,18 @@ class Colors {
return _arr;
}

/**
* Return the color, multicolor or colorless.
*/
getBaseColor() {
if (this.length > 1) {
return MULTI;
} else if (this.length == 0) {
return COLORLESS;
}
return this.get()[0];
}

/**
* Returns the number of colors
*/
@@ -68,16 +88,16 @@ class Colors {
* Adds a string mana cost to this class.
*/
addFromCost(cost) {
cost.forEach(cost => {
if (cost === "w") {
cost.forEach(_c => {
if (_c == "w") {
this._w += 1;
} else if (cost === "u") {
} else if (_c == "u") {
this._u += 1;
} else if (cost === "b") {
} else if (_c == "b") {
this._b += 1;
} else if (cost === "r") {
} else if (_c == "r") {
this._r += 1;
} else if (cost === "g") {
} else if (_c == "g") {
this._g += 1;
}
});
@@ -8,6 +8,8 @@ exports.BLUE = 2;
exports.BLACK = 3;
exports.RED = 4;
exports.GREEN = 5;
exports.COLORLESS = 6;
exports.MULTI = 7;

// Magic constant to represent auth token in form
exports.HIDDEN_PW = "********";

Some generated files are not rendered by default. Learn more.

@@ -21,6 +21,17 @@ const {
replaceAll
} = require("../shared/util");

const Colors = require("../shared/colors");
const {
MULTI,
COLORLESS,
WHITE,
BLUE,
BLACK,
GREEN,
RED
} = require("../shared/constants.js");

const {
hideLoadingBars,
changeBackground,
@@ -139,6 +150,7 @@ function collectionSortName(a, b) {
class SetStats {
constructor(set) {
this.set = set;
this.cards = [];
this.common = new CountStats();
this.uncommon = new CountStats();
this.rare = new CountStats();
@@ -176,6 +188,10 @@ function get_collection_stats() {
db.cardList.forEach(card => {
if (!card.collectible || card.rarity === "land") return;
if (!(card.set in stats)) return;
let obj = {
id: card.id,
owned: 0
};
let collation = db.sets[card.set].collation;
// add to totals
if (card.booster || !collation) {
@@ -188,6 +204,8 @@ function get_collection_stats() {
// add cards we own
if (pd.cards.cards[card.id] !== undefined) {
const owned = pd.cards.cards[card.id];
obj.owned = owned;

if (card.booster || !collation) {
stats[card.set][card.rarity].owned += owned;
stats[card.set][card.rarity].uniqueOwned += 1;
@@ -204,6 +222,10 @@ function get_collection_stats() {
}
}

let col = new Colors();
col.addFromCost(card.cost);
let colorIndex = col.getBaseColor();

// count cards we know we want across decks
const wanted = Math.max(
...pd.deckList
@@ -216,6 +238,13 @@ function get_collection_stats() {
// count unique cards we know we want across decks
stats[card.set][card.rarity].uniqueWanted += Math.min(1, wanted);
stats.complete[card.rarity].uniqueWanted += Math.min(1, wanted);

obj.wanted = wanted;
if (!stats[card.set].cards[colorIndex])
stats[card.set].cards[colorIndex] = {};
if (!stats[card.set].cards[colorIndex][card.rarity])
stats[card.set].cards[colorIndex][card.rarity] = [];
stats[card.set].cards[colorIndex][card.rarity].push(obj);
});

return stats;
@@ -615,6 +644,7 @@ function printStats() {
mainDiv.innerHTML = "";
mainDiv.classList.remove("flex_item");
const stats = get_collection_stats();
console.log(stats);

let top = createDiv(["decklist_top"]);
top.appendChild(createDiv(["button", "back"]));
@@ -710,6 +740,52 @@ function renderSetStats(setStats, setIconCode, setName) {
label.innerHTML = setName + " completion";
substats.appendChild(label);

// Draw completion table for this set
let table = createDiv(["completion_table"]);
for (var c = 0; c < 7; c++) {
let tile = "";
if (c + 1 == MULTI) tile = "mana_multi";
if (c + 1 == COLORLESS) tile = "mana_colorless";
if (c + 1 == WHITE) tile = "mana_white";
if (c + 1 == BLUE) tile = "mana_blue";
if (c + 1 == BLACK) tile = "mana_black";
if (c + 1 == RED) tile = "mana_red";
if (c + 1 == GREEN) tile = "mana_green";

let cell = createDiv(["completion_table_color_title", tile]);
cell.style.gridArea = `1 / ${c * 5 + 1} / auto / ${c * 5 + 6}`;
table.appendChild(cell);

for (var r = 0; r < 4; r++) {
let rarity = CARD_RARITIES[r];
let cell = createDiv(["completion_table_rarity_title", rarity]);
cell.title = rarity;
cell.style.gridArea = `2 / ${c * 5 + 1 + r} / auto / ${c * 5 + 1 + r}`;
table.appendChild(cell);

// A little hacky to use "c + 1"..
if (setStats.cards[c + 1]) {
let cardsArray = setStats.cards[c + 1][rarity];
if (cardsArray) {
cardsArray.forEach((card, index) => {
let classes = ["completion_table_card", "n" + card.owned];
if (card.wanted > 0) classes.push("wanted");
let cell = createDiv(classes, card.owned);
cell.style.gridArea = `${index + 3} / ${c * 5 +
1 +
r} / auto / ${c * 5 + 1 + r}`;
table.appendChild(cell);

let dbCard = db.card(card.id);
addCardHover(cell, dbCard);
});
}
}
}
}

substats.appendChild(table);

let wanted = {};
let missing = {};
CARD_RARITIES.forEach(rarity => {
@@ -1453,12 +1453,17 @@ a:hover {


.main_stats {
margin: 16px;
width: 50%;
margin: 16px 16px 16px 32px;
min-width: 320px;
display: block;
text-align: center;
}

.main_stats.sub_stats {
margin: 16px;
width: -webkit-fill-available;
}

.stats_set_completion {
cursor: pointer;
max-width: 320px;
@@ -3564,3 +3569,75 @@ a:hover {
color: var(--color-light);
margin: auto;
}

.completion_table {
width: 100%;
max-width: 600px;
margin: 16px auto;
text-align: center;
display: grid;
line-height: 24px;
font-size: 14px;
grid-template-columns: repeat(35, 1fr);
color: var(--color-light);
}

.completion_table_color_title {
height: 24px;
margin-right: 20%;
margin-bottom: 4px;
background-size: contain;
background-position: center;
background-repeat: no-repeat;
}

.completion_table_rarity_title {
height: 8px;
margin-bottom: 2px;
}

.completion_table_rarity_title.common {
background-color: var(--color-common);
}
.completion_table_rarity_title.uncommon {
background-color: var(--color-uncommon);
}
.completion_table_rarity_title.rare {
background-color: var(--color-rare);
}
.completion_table_rarity_title.mythic {
background-color: var(--color-mythic);
}

.completion_table_card {
font-family: var(--sub-font-name-bold);
color: var(--color-back);
height: 24px;
line-height: 24px;
}

.completion_table_card:hover {
opacity: 0.8;
border: 1px white solid;
margin: -1px;
z-index: 1;
}

.completion_table_card.n0 {
background-color: #af593c;
}
.completion_table_card.n1 {
background-color: #dc8a6e;
}
.completion_table_card.n2 {
background-color: #ffdf9e;
}
.completion_table_card.n3 {
background-color: #e9ff92;
}
.completion_table_card.n4 {
background-color: #d3ebb0;
}
.completion_table_card.wanted {
opacity: 0.5;
}

0 comments on commit a927a41

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