mirror of
https://github.com/sboulema/mtg-deck.git
synced 2026-07-22 06:50:39 +00:00
feat: Add per deck settings
This commit is contained in:
parent
763ea30995
commit
41ba01f3de
9 changed files with 109 additions and 18 deletions
2
.github/workflows/workflow.yml
vendored
2
.github/workflows/workflow.yml
vendored
|
|
@ -10,7 +10,7 @@ permissions:
|
|||
contents: read
|
||||
|
||||
env:
|
||||
version: '1.12.${{ github.run_number }}'
|
||||
version: '1.13.${{ github.run_number }}'
|
||||
nodeVersion: '22'
|
||||
|
||||
jobs:
|
||||
|
|
|
|||
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -1,10 +1,3 @@
|
|||
# vscode
|
||||
.vscode
|
||||
|
||||
# Intellij
|
||||
*.iml
|
||||
.idea
|
||||
|
||||
# npm
|
||||
node_modules
|
||||
|
||||
|
|
|
|||
16
.vscode/tasks.json
vendored
Normal file
16
.vscode/tasks.json
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "npm",
|
||||
"script": "build",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"label": "npm: build",
|
||||
"detail": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production"
|
||||
}
|
||||
]
|
||||
}
|
||||
25
README.md
25
README.md
|
|
@ -156,6 +156,31 @@ Open **Settings → MTG Deck** to configure the plugin:
|
|||
| **Card name column name** | The name of the CSV column used for card names |
|
||||
| **Card count column name** | The name of the CSV column used for card counts/quantity |
|
||||
|
||||
## Settings per deck
|
||||
|
||||
````markdown
|
||||
```mtg-deck-show:prices
|
||||
...
|
||||
```
|
||||
````
|
||||
|
||||
````markdown
|
||||
```mtg-deck-modern-show:prices,manacosts
|
||||
...
|
||||
```
|
||||
````
|
||||
|
||||
Supported show values:
|
||||
|
||||
| Value | Description |
|
||||
|---|---|
|
||||
| `prices` | Show card prices |
|
||||
| `manacosts` | Show mana cost symbols |
|
||||
| `previews` | Show card preview on hover |
|
||||
| `hyperlinks` | Show card names as hyperlinks |
|
||||
| `rarities` | Show rarity indicators |
|
||||
| `buylist` | Show buylist section |
|
||||
|
||||
# 📦 Collection Tracking
|
||||
|
||||
This plugin expects your collection to be stored as CSV files with the extension `.mtg.collection.csv` by default.
|
||||
|
|
|
|||
26
main.ts
26
main.ts
|
|
@ -8,7 +8,7 @@ import {
|
|||
import { renderDecklist } from "src/renderer";
|
||||
import { ObsidianPluginMtgSettings } from "src/settings";
|
||||
import { CardCounts } from "src/collection";
|
||||
import { FORMATS } from "src/validator";
|
||||
import { parseCodeBlockOptions, applyShowOverrides } from "src/code-block-options";
|
||||
|
||||
const DEFAULT_SETTINGS: ObsidianPluginMtgSettings = {
|
||||
collection: {
|
||||
|
|
@ -56,13 +56,25 @@ export default class ObsidianPluginMtg extends Plugin {
|
|||
this.cardCounts = await syncCounts(vault, this.settings);
|
||||
});
|
||||
|
||||
this.registerMarkdownCodeBlockProcessor("mtg-deck", async (source: string, el: HTMLElement) => {
|
||||
await this.renderDecklist(vault, source, el, null);
|
||||
});
|
||||
this.registerMarkdownPostProcessor((element) => {
|
||||
const codeBlocks = element.querySelectorAll("code[class*='language-mtg-deck']");
|
||||
|
||||
FORMATS.forEach(({ name }) => {
|
||||
this.registerMarkdownCodeBlockProcessor(`mtg-deck-${name}`, async (source: string, el: HTMLElement) => {
|
||||
await this.renderDecklist(vault, source, el, name);
|
||||
codeBlocks.forEach(async (codeBlock) => {
|
||||
const className = Array.from(codeBlock.classList)
|
||||
.find(cls => cls.startsWith("language-mtg-deck")) ?? "";
|
||||
|
||||
const infoString = className.replace("language-", "");
|
||||
const { format, showOverrides } = parseCodeBlockOptions(infoString);
|
||||
const effectiveSettings = applyShowOverrides(this.settings, showOverrides);
|
||||
|
||||
const source = codeBlock.textContent ?? "";
|
||||
const pre = codeBlock.parentElement;
|
||||
|
||||
if (pre) {
|
||||
const container = createDiv();
|
||||
pre.replaceWith(container);
|
||||
await renderDecklist(container, source, this.cardCounts, effectiveSettings, format);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "mtg-deck",
|
||||
"name": "MTG Deck",
|
||||
"version": "1.12.88",
|
||||
"version": "1.13.104",
|
||||
"minAppVersion": "1.1.0",
|
||||
"description": "Display your MTG decks and card lists in your notes.",
|
||||
"author": "Samir Boulema",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mtg-deck",
|
||||
"version": "1.12.88",
|
||||
"version": "1.13.104",
|
||||
"description": "Display your MTG decks and card lists in your notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
|||
44
src/code-block-options.ts
Normal file
44
src/code-block-options.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { ObsidianPluginMtgSettings } from "./settings";
|
||||
|
||||
export interface CodeBlockOptions {
|
||||
format: string | null;
|
||||
showOverrides: string[];
|
||||
}
|
||||
|
||||
export const parseCodeBlockOptions = (infoString: string): CodeBlockOptions => {
|
||||
const stripped = infoString
|
||||
.replace(/^mtg-deck-?/, "")
|
||||
.trim();
|
||||
|
||||
const showMatch = stripped.match(/show:([^\s]+)/);
|
||||
const showOverrides = showMatch
|
||||
? showMatch[1].split(",").map(s => s.trim())
|
||||
: [];
|
||||
|
||||
const format = stripped
|
||||
.replace(/show:[^\s]+/, "")
|
||||
.replace(/-$/, "")
|
||||
.trim() || null;
|
||||
|
||||
return { format, showOverrides };
|
||||
};
|
||||
|
||||
export const applyShowOverrides = (
|
||||
settings: ObsidianPluginMtgSettings,
|
||||
showOverrides: string[]
|
||||
): ObsidianPluginMtgSettings => {
|
||||
if (showOverrides.length === 0) return settings;
|
||||
|
||||
return {
|
||||
...settings,
|
||||
decklist: {
|
||||
...settings.decklist,
|
||||
showCardPrices: showOverrides.includes("prices") || settings.decklist.showCardPrices,
|
||||
showManaCosts: showOverrides.includes("manacosts") || settings.decklist.showManaCosts,
|
||||
showCardPreviews: showOverrides.includes("previews") || settings.decklist.showCardPreviews,
|
||||
showCardNamesAsHyperlinks: showOverrides.includes("hyperlinks") || settings.decklist.showCardNamesAsHyperlinks,
|
||||
showCardRarities: showOverrides.includes("rarities") || settings.decklist.showCardRarities,
|
||||
showBuylist: showOverrides.includes("buylist") || settings.decklist.showBuylist,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
|
@ -25,5 +25,6 @@
|
|||
"1.11.78": "0.15.0",
|
||||
"1.11.79": "0.15.0",
|
||||
"1.11.80": "0.15.0",
|
||||
"1.12.88": "1.1.0"
|
||||
"1.12.88": "1.1.0",
|
||||
"1.13.104": "1.1.0"
|
||||
}
|
||||
Loading…
Reference in a new issue