Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions assets/js/ui.deckimport.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
} else if (name.match(/^(\d+)x? (.*)/)) {
qty = parseInt(RegExp.$1, 10);
name = RegExp.$2.trim();
} else if (name.match(/^([^(]+) \(([^)]+)\)/)) {
name = RegExp.$1.trim();
packName = RegExp.$2.trim();
} else {
if (firstLine) {
$name.val(token);
Expand Down
7 changes: 7 additions & 0 deletions src/Services/DeckImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class DeckImportService
// <card name>
const SINGLE_CARD_WITHOUT_PACK_INFO_REGEXP = '/^([^(]+)/';

// <card name> (<pack code|name>)
const SINGLE_CARD_WITH_PACK_INFO_REGEXP = '/^([^\(]+) \(([^)]+)/u';

protected EntityManagerInterface $em;

protected TranslatorInterface $translator;
Expand Down Expand Up @@ -150,6 +153,10 @@ protected function parseOneTextImport(array $lines, array $packsByName, array $p
} elseif (preg_match(self::CARD_WITHOUT_PACK_INFO_ALT2_REGEXP, $line, $matches)) {
$quantity = intval($matches[2]);
$name = trim($matches[1]);
} elseif (preg_match(self::SINGLE_CARD_WITH_PACK_INFO_REGEXP, $line, $matches)) {
$quantity = 1;
$name = trim($matches[1]);
$packNameOrCode = trim($matches[2]);
} elseif (preg_match(self::SINGLE_CARD_WITHOUT_PACK_INFO_REGEXP, $line, $matches)) {
$quantity = 1;
$name = trim($matches[1]);
Expand Down
2 changes: 2 additions & 0 deletions tests/Services/DeckImportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public function testParseTextImportForCardWithPackNameProvider(): array
"Watchers on the Wall",
"House Baratheon",
],
["House Stark\nSea of Blood (Redesigns)", 1, 'Sea of Blood', "Redesigns", "House Stark"],
];
}

Expand Down Expand Up @@ -164,6 +165,7 @@ public function testParseTextImportForCardWithPackCodeProvider(): array
["House Martell\n1 Burning on the Sand (TIMC)", 1, "Burning on the Sand", "TIMC", "House Martell"],
["House Martell\n1 Secret Schemes (TRW)", 1, "Secret Schemes", "TRW", "House Martell"],
["House Stark\n2 \"The Last of the Giants\" (WotW)", 2, '"The Last of the Giants"', "WotW", "House Stark"],
["House Stark\nSea of Blood (R)", 1, 'Sea of Blood', "R", "House Stark"],
];
}

Expand Down