Fixed no-op, added documentation

This commit is contained in:
Jurriaan van den Berg 2026-10-20 13:26:10 +02:00
parent 39474e286d
commit 560ca53b94
2 changed files with 20 additions and 4 deletions

View file

@ -234,14 +234,29 @@ QModelIndex DeckStateManager::decrementCard(const ExactCard &card, const QString
return {};
}
QString zone = card.getInfo().getIsToken() ? DECK_ZONE_TOKENS : zoneName;
QString zone = zoneName;
QString providerId = card.getPrinting().getUuid();
QString collectorNumber = card.getPrinting().getProperty("num");
QModelIndex idx = deckListModel->findCard(card.getName(), zone, providerId, collectorNumber);
if (!idx.isValid()) {
return {};
// Tokens are usually added to the token zone, but it is possible for imported/hand-edited
// decks to contain them in the main or sideboards. This is why we only try to remove the
// token from the token zone if it does not exist in the given zone, allowing us to still
// remove it from there.
if (card.getInfo().getIsToken()) {
zone = DECK_ZONE_TOKENS;
idx = deckListModel->findCard(card.getName(), zone, providerId, collectorNumber);
if (!idx.isValid()) {
return {};
}
} else {
return {};
}
}
bool success = offsetCountAtIndex(idx, -1);

View file

@ -187,17 +187,18 @@ public:
///@}
/**
* @brief Adds the given card to the given zone.
* @brief Adds the given card to the given zone. Tokens always go to DECK_ZONE_TOKENS, ignoring the given zone.
* Saves the operation to history if successful.
*
* @param card The card to add
* @param zoneName The zone to add the card to
* @param zoneName The zone to add the card to if the card is not a token
* @return The index of the added card
*/
QModelIndex addCard(const ExactCard &card, const QString &zoneName);
/**
* @brief Removes 1 copy of the given card from the given zone.
* If the card is a token and is not in the given zone, then it is removed from DECK_ZONE_TOKENS instead.
* Saves the operation to history if successful.
*
* @param card The card to remove