diff --git a/jest/fixtures/content.ts b/jest/fixtures/content.ts index d9d8d1e..ff94cca 100644 --- a/jest/fixtures/content.ts +++ b/jest/fixtures/content.ts @@ -23,7 +23,7 @@ Sideboard: 4 Ertai's Scorn`; export const EXAMPLE_DECK_1_HTML = ` -
| Delver of Secrets // Insectile Aberration | $1.23 / $1.64 | ||
| Haughty Djinn | $4.80 / $6.40 | ||
| 3 | Tolarian Terror | $0.69 | |
| 4 | Consider | $7.24 | |
| 4 | Essence Scatter | $0.20 | |
| 4 | Fading Hope | $2.36 | |
| 4 | Make Disappear | consider Negate instead | $0.44 |
| Slip Out the Back | $0.00 / $6.80 | ||
| 3 | Spell Pierce | $0.27 | |
| 3 | Thirst for Discovery | $0.48 | |
| # Lands | |||
| 20 | Island | $1.80 | |
| 1 | Otawara, Soaring City | $12.74 | |
| Otherworldly Gaze | $0.00 / $0.24 | ||
| Reckoner Bankbuster | $0.00 / $3.93 | ||
| 2 | Disdainful Stroke | $0.18 | |
| 4 | Negate | $0.36 | |
| 4 | Out of the Way | $0.20 | |
| Reckoner Bankbuster | $0.00 / $3.93 | ||
| Ertai's Scorn | $0.00 / $0.52 |
1 Delver of Secrets // Insectile Aberration +Deck
Delver of Secrets // Insectile Aberration $1.23 / $1.64 Haughty Djinn $4.80 / $6.40 3 Tolarian Terror $0.69 4 Consider $7.24 4 Essence Scatter $0.20 4 Fading Hope $2.36 4 Make Disappear consider Negate instead $0.44 Slip Out the Back $0.00 / $6.80 3 Spell Pierce $0.27 3 Thirst for Discovery $0.48 # Lands 20 Island $1.80 1 Otawara, Soaring City $12.74 Otherworldly Gaze $0.00 / $0.24 Reckoner Bankbuster $0.00 / $3.93 52 / 60cards$32.25 / $45.23Sideboard:
2 Disdainful Stroke $0.18 4 Negate $0.36 4 Out of the Way $0.20 Reckoner Bankbuster $0.00 / $3.93 Ertai's Scorn $0.00 / $0.52 10 / 15cards$0.74 / $5.19`; export const EXAMPLE_DECK_1_HTML_WITHOUT_PRICES = ` -Buylist:
1 Delver of Secrets // Insectile Aberration 1 Haughty Djinn 4 Slip Out the Back 1 Otherworldly Gaze @@ -32,7 +32,7 @@ export const EXAMPLE_DECK_1_HTML = `13 cards$17.43Deck
52 / 60cardsBuylist:
1 Delver of Secrets // Insectile Aberration +Deck
52 / 60cardsBuylist:
1 Delver of Secrets // Insectile Aberration 1 Haughty Djinn 4 Slip Out the Back 1 Otherworldly Gaze diff --git a/src/renderer.ts b/src/renderer.ts index 82d7240..151215b 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -266,14 +266,21 @@ export const renderDecklist = async ( const sectionHeadingEl = sectionContainer.createEl("h3", { cls: "decklist__section-heading" }); // Create container for the table rows - const sectionList = sectionContainer.createEl("table", { cls: "decklist__section-list" }); + const sectionList = sectionContainer.createEl("table"); + const sectionListHead = sectionList.createEl("thead"); + const sectionListHeadRow = sectionListHead.createEl("tr"); + sectionListHeadRow.createEl("th", { text: "Count" }); + sectionListHeadRow.createEl("th", { text: "Name" }); + if (!settings.decklist.hidePrices) { + sectionListHeadRow.createEl("th", { text: "Price" }); + } const sectionListBody = sectionList.createEl("tbody"); const sectionMissingCardCounts: CardCounts = {}; // Create line item elements linesBySection[section].forEach((line: Line) => { - const lineEl = sectionListBody.createEl("tr", { cls: "decklist__section-list-item" }); + const lineEl = sectionListBody.createEl("tr"); if (line.lineType === "card") { const cardCountCell = lineEl.createEl("td"); @@ -281,12 +288,26 @@ export const renderDecklist = async ( const cardNameCell = lineEl.createEl("td"); const cardNameEl = cardNameCell.createSpan({ cls: "card-name" }); + const cardCommentsEl = cardNameCell.createSpan({ + cls: "comment", + text: line.comments?.join("#") || "", + }); - const cardCommentsCell = lineEl.createEl("td"); - const cardCommentsEl = cardCommentsCell.createSpan({ cls: "comment" }); + let cardPrice; + let cardPriceEl; - const cardPriceCell = lineEl.createEl("td"); - const cardPriceEl = cardPriceCell.createSpan({ cls: "card-price" }); + if (!settings.decklist.hidePrices) { + const cardPriceCell = lineEl.createEl("td"); + cardPriceEl = cardPriceCell.createSpan({ cls: "card-price" }); + + if (line.cardName) { + cardPrice = getCardPrice( + line.cardName, + cardDataByCardId, + settings + ); + } + } // Add hyperlink when possible if (line.cardName) { @@ -316,17 +337,6 @@ export const renderDecklist = async ( }); } - cardCommentsEl.textContent = line.comments?.join("#") || ""; - - let cardPrice; - if (line.cardName) { - cardPrice = getCardPrice( - line.cardName, - cardDataByCardId, - settings - ); - } - const lineCardCount = line.cardCount || 0; const lineGlobalCount = line.globalCount === null ? -1 : line.globalCount || 0; @@ -355,14 +365,14 @@ export const renderDecklist = async ( (lineCardCount - lineGlobalCount); if (cardPrice) { - cardPriceEl.classList.add("insufficient-count"); + cardPriceEl!.classList.add("insufficient-count"); const totalPrice: number = lineCardCount * parseFloat(cardPrice); const amountOwned: number = lineGlobalCount * parseFloat(cardPrice); - cardPriceEl.createSpan({ + cardPriceEl!.createSpan({ cls: "error", text: `${ currencyMapping[ @@ -371,7 +381,7 @@ export const renderDecklist = async ( }${amountOwned.toFixed(2)}`, }); - cardPriceEl.createSpan({ + cardPriceEl!.createSpan({ text: ` / ${ currencyMapping[ settings.decklist.preferredCurrency @@ -392,7 +402,8 @@ export const renderDecklist = async ( const displayPrice = `${ currencyMapping[settings.decklist.preferredCurrency] }${totalPrice.toFixed(2)}`; - cardPriceEl.textContent = displayPrice; + + cardPriceEl!.textContent = displayPrice; // Add cost to total sectionTotalCost[section] = @@ -439,8 +450,7 @@ export const renderDecklist = async ( } } else if (line.lineType === "comment") { // Comments - const commentCell = lineEl.createEl("td", { attr: { colspan: "4" } }); - commentCell.createSpan({ + lineEl.createSpan({ cls: "comment", text: line.comments?.join(" ") || "", }); diff --git a/styles.css b/styles.css index ef8e1b3..5225ac7 100644 --- a/styles.css +++ b/styles.css @@ -11,39 +11,6 @@ If your plugin does not need CSS, delete this file. padding: 8px; } -table.decklist__section-list { - border-collapse: collapse; - margin: 0; - padding: 0; - width: 100%; -} - -table.decklist__section-list td { - padding: 0; - vertical-align: top; -} - -.decklist__section-totals { - display: flex; -} - -.decklist__section-totals span { - flex: 1; -} - -span.decklist__section-totals__count { - flex: 1; -} - -tr.decklist__section-list-item { - font-weight: 400; -} - -tr.decklist__section-list-item span { - display: block; - width: 100%; -} - .count { flex: 1; } @@ -63,21 +30,11 @@ span.comment { flex: 2; } -.card-price { -} - .error { color: #a33; font-style: italic; } -.decklist__section-heading { - font-weight: 800; -} - -.footer { -} - .card-image { height: 400px; } @@ -94,10 +51,6 @@ span.comment { flex: 1; } -/* decklist__section-totals { - font-weight: 800; -} */ - .decklist__section-totals .card-name { flex: 4; } diff --git a/tsconfig.json b/tsconfig.json index 5390bce..b310df9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,8 @@ { "compilerOptions": { - "paths": { - "src/*": ["./src/*"] - }, + "paths": { + "src/*": ["./src/*"] + }, "inlineSourceMap": true, "inlineSources": true, "module": "ESNext",