Skip to content
Permalink
Browse files

new flat card tile style

not enabled on this commit
  • Loading branch information...
Manuel-777 committed May 26, 2019
1 parent 8aaa329 commit 0ebc67da2c88f57ce5a2a4d4f5e02f7a44bcb8e9
Showing with 169 additions and 2 deletions.
  1. +3 −0 shared/constants.js
  2. +115 −2 shared/deck-drawer.js
  3. +51 −0 shared/shared.css
@@ -670,3 +670,6 @@ exports.MANA = {
exports.PACK_SIZES = { "Ravnica Allegiance": 14, "Guilds of Ravnica": 14 };

exports.DEFAULT_TILE = 67003;

exports.CARD_TILE_ARENA = 1;
exports.CARD_TILE_FLAT = 2;
@@ -10,6 +10,8 @@ global

const _ = require("lodash");

const { CARD_TILE_FLAT } = require("./constants.js");

//
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
@@ -73,6 +75,7 @@ exports.cardSeparator = function(str) {
};

exports.cardTile = function(
style,
grpId,
indent,
quantity,
@@ -90,8 +93,32 @@ exports.cardTile = function(
card = cardsDb.get(grpId);
}

const cont = createDivision(["card_tile_container", "click-on"]);
// Default to Arena style
let drawFunc = drawCardTileArena;
if (style == CARD_TILE_FLAT) {
drawFunc = drawCardTileFlat;
}
return drawFunc(
card,
grpId,
indent,
quantity,
showWildcards,
deck,
isSideboard
);
};

function drawCardTileArena(
card,
grpId,
indent,
quantity,
showWildcards,
deck,
isSideboard
) {
const cont = createDivision(["card_tile_container", "click-on"]);
cont.dataset["grpId"] = grpId;
cont.dataset["id"] = indent;
cont.dataset["quantity"] = quantity;
@@ -209,4 +236,90 @@ exports.cardTile = function(
}
}
return cont;
};
}

function drawCardTileFlat(
card,
grpId,
indent,
quantity,
showWildcards,
deck,
isSideboard
) {
const cont = createDivision(["card_tile_container_flat", "click-on"]);
cont.dataset["grpId"] = grpId;
cont.dataset["id"] = indent;
cont.dataset["quantity"] = quantity;

if (!isNumber(quantity)) {
// Text quantity
const col = rankingClassName(quantity);
const quantityDiv = createDivision(["card_tile_odds_flat", col], quantity);
cont.appendChild(quantityDiv);
} else if (quantity == 9999) {
// Undefined Quantity
const quantityDiv = createDivision(["card_tile_quantity_flat"], 1);
cont.appendChild(quantityDiv);
} else {
// Normal Quantity
const quantityDiv = createDivision(["card_tile_quantity_flat"], quantity);
cont.appendChild(quantityDiv);
}

const cardTile = createDivision(["card_tile_crop_flat"]);
try {
cardTile.style.backgroundImage = `url(https://img.scryfall.com/cards${
card.images["art_crop"]
})`;
} catch (e) {
console.log(e);
}
cont.appendChild(cardTile);

let name = card ? card.name : "Unknown";
let cardName = createDivision(["card_tile_name_flat"], name);
cont.appendChild(cardName);

const cardCost = createDivision(["cart_tile_mana_flat"]);
if (card) {
let prevc = true;
const hasSplitCost = card.dfc === "SplitHalf";

card.cost.forEach(cost => {
if (hasSplitCost) {
if (/^(x|\d)+$/.test(cost) && prevc === false) {
cardCost.innerHTML += "//";
}
prevc = /^\d+$/.test(cost);
}
cardCost.appendChild(
createDivision(["mana_s16", "flex_end", `mana_${cost}`])
);
});
}
cont.appendChild(cardCost);

if (card) {
addCardHover(cont, card);
cont.addEventListener("mouseenter", () => {
cont.style.backgroundColor = "rgba(65, 50, 40, 0.75)";
});
cont.addEventListener("mouseleave", () => {
cont.style.backgroundColor = "rgba(0, 0, 0, 0.75)";
});

cont.addEventListener("click", () => {
if (card.dfc == "SplitHalf") {
card = cardsDb.get(card.dfcId);
}
shell.openExternal(
`https://scryfall.com/card/${get_set_scryfall(card.set)}/${card.cid}/${
card.name
}`
);
});
}

return cont;
}
@@ -725,6 +725,57 @@ span {
background: url(../images/not_owned.png) center no-repeat;
}


.card_tile_container_flat {
display: flex;
height: 31px;
margin-bottom: 1px;
background-color: rgba(0,0,0,0.75);
-webkit-transition: all .15s ease-in;
cursor: pointer;
}

.card_tile_odds_flat {
font-size: 14px;
min-width: 32px;
color: white;
line-height: 31px;
text-align: center;
}

.card_tile_quantity_flat {
font-size: 14px;
min-width: 32px;
color: white;
line-height: 31px;
text-align: center;
}

.card_tile_crop_flat {
min-width: 32px;
height: 100%;
background-size: cover;
background-position: center;
}

.card_tile_name_flat {
font-size: 14px;
margin-left: 8px;
margin-right: 8px;
color: white;
text-align: center;
line-height: 31px;
overflow: hidden;
text-overflow: ellipsis;
white-space: pre;
}

.cart_tile_mana_flat {
display: flex;
align-items: center;
margin: 0 6px 0 auto;
}

.not_owned_sprite {
margin-top: 2px;
min-width: 24px;

0 comments on commit 0ebc67d

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