mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-18 12:53:54 -07:00
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:
parent
8180d2e3b0
commit
9bb399606c
6 changed files with 226 additions and 26 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue