Permalink
Browse files

Numbers in decklist separators

  • Loading branch information...
Manuel-777 committed Jan 1, 2019
1 parent 051b7f5 commit 77d2d5a945a42d90fa001a6fe0327d76756a2913
Showing with 56 additions and 9 deletions.
  1. +45 −2 shared/util.js
  2. +11 −7 window_main/renderer.js
@@ -248,7 +248,7 @@ function get_rank_index_16(_rank) {
}

//
function addCardSeparator(i, element) {
function addCardSeparator(i, element, number = 0) {
var str = "";
switch (i) {
case 1: str = "Creature"; break;
@@ -263,7 +263,11 @@ function addCardSeparator(i, element) {
default: str = i; break;
}

var cont = $('<div class="card_tile_separator">'+str+'</div>');
if (number > 0) {
str += ` (${number})`;
}

var cont = $(`<div class="card_tile_separator">${str}</div>`);
element.append(cont);
}

@@ -335,6 +339,36 @@ function get_card_type_sort(a) {
return 0;
}

//
function deck_count_types(deck, type, side) {
if (type.includes("Land", 0)) type = "Land";
else if (type.includes("Creature", 0)) type = "Creature";
else if (type.includes("Artifact", 0)) type = "Artifact";
else if (type.includes("Enchantment", 0)) type = "Enchantment";
else if (type.includes("Instant", 0)) type = "Instant";
else if (type.includes("Sorcery", 0)) type = "Sorcery";
else if (type.includes("Planeswalker", 0)) type = "Planeswalker";

let count = 0;
deck.mainDeck.forEach((card) => {
let c = cardsDb.get(card.id);
if (c.type.includes(type, 0)) {
count+=card.quantity;
}
});

if (side) {
deck.sideboard.forEach((card) => {
let c = cardsDb.get(card.id);
if (c.type.includes(type, 0)) {
count+=card.quantity;
}
});
}

return count;
}

//
function compare_cards(a, b) {
// Yeah this is lazy.. I know
@@ -1172,4 +1206,13 @@ String.prototype.capitalize = function() {
//
function add(a, b) {
return a + b;
}

//
Array.prototype.sum = function(prop) {
var total = 0
for ( var i = 0, _len = this.length; i < _len; i++ ) {
total += this[i][prop]
}
return total
}
@@ -19,7 +19,8 @@ global
compare_colors,
compare_cards,
windowBackground,
windowRenderer
windowRenderer,
deck_count_types
*/

const electron = require('electron');
@@ -1149,14 +1150,17 @@ function drawDeck(div, deck) {
div.html('');
var prevIndex = 0;
deck.mainDeck.forEach(function(card) {
var grpId = card.id;
var type = cardsDb.get(grpId).type;
let grpId = card.id;
let type = cardsDb.get(grpId).type;
let cardTypeSort = get_card_type_sort(type);
if (prevIndex == 0) {
addCardSeparator(get_card_type_sort(type), div);
let q = deck_count_types(deck, type, false);
addCardSeparator(cardTypeSort, div, q);
}
else if (prevIndex != 0) {
if (get_card_type_sort(type) != get_card_type_sort(cardsDb.get(prevIndex).type)) {
addCardSeparator(get_card_type_sort(type), div);
if (cardTypeSort != get_card_type_sort(cardsDb.get(prevIndex).type)) {
let q = deck_count_types(deck, type, false);
addCardSeparator(cardTypeSort, div, q);
}
}

@@ -1169,7 +1173,7 @@ function drawDeck(div, deck) {

if (deck.sideboard != undefined) {
if (deck.sideboard.length > 0) {
addCardSeparator(99, div);
addCardSeparator(99, div, deck.sideboard.sum('quantity'));
prevIndex = 0;
deck.sideboard.forEach(function(card) {
var grpId = card.id;

0 comments on commit 77d2d5a

Please sign in to comment.