refactor: extract shared card insertion algorithm from hand/stack zones (#6701)

Hand and stack zones had near-identical addCardImpl() implementations, differing only in whether resetState() preserves annotations.
Extract the shared pattern into a template function (CardZoneAlgorithms::addCardToList) to eliminate duplication and enable isolated testing without Qt dependencies.
Pile, table, and zone-view logic are intentionally excluded — their post-add behavior (signals, coordinate placement, hidden cards) is materially different.
This commit is contained in:
DawnFire42 2026-03-15 03:39:44 -04:00 committed by GitHub
parent 8180d2e3b0
commit 9bb399606c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 226 additions and 26 deletions

View file

@ -1,6 +1,7 @@
#include "stack_zone_logic.h"
#include "../../board/card_item.h"
#include "card_zone_algorithms.h"
StackZoneLogic::StackZoneLogic(Player *_player,
const QString &_name,
@ -14,16 +15,5 @@ StackZoneLogic::StackZoneLogic(Player *_player,
void StackZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
{
// if x is negative set it to add at end
if (x < 0 || x >= cards.size()) {
x = static_cast<int>(cards.size());
}
cards.insert(x, card);
if (!cards.getContentsKnown()) {
card->setId(-1);
card->setCardRef({});
}
card->resetState(true);
card->setVisible(true);
}
CardZoneAlgorithms::addCardToList(cards, card, x, true);
}