[Refactor] Retype PlayerActions onto CardState (#7435)

* [Refactor] Retype card containers and zone logic onto CardState

* [Refactor] Retype PlayerActions onto CardState

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-31 18:44:14 +01:00 • committed by GitHub
parent 65e9f1b370
commit 7ca23430cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 138 additions and 136 deletions

View file

@ -5,6 +5,7 @@
#include "../../game_graphics/dialogs/dlg_create_token.h"
#include "../abstract_game.h"
#include "../board/arrow_data.h"
#include "../board/card_state.h"
#include "../board/counter_state.h"
#include "../game_event_handler.h"
#include "../zones/card_zone_logic.h"
@ -91,7 +92,7 @@ PlayerActions::PlayerActions(PlayerLogic *_player)
connect(moveTopCardTimer, &QTimer::timeout, [this]() { actMoveTopCardToPlay(); });
}
void PlayerActions::playCard(CardItem *card, bool faceDown)
void PlayerActions::playCard(CardState *card, bool faceDown)
{
if (card == nullptr) {
return;
@ -144,7 +145,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
* Like {@link PlayerActions::playCard}, but forces the card to be played to the table zone.
* Cards with tablerow 3 (the stack) will be played to tablerow 1 (the noncreatures row).
*/
void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
void PlayerActions::playCardToTable(const CardState *card, bool faceDown)
{
if (card == nullptr) {
return;
@ -177,7 +178,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
sendGameCommand(cmd);
}
void PlayerActions::attachCards(CardItem *startCard, const CardItem *targetCard)
void PlayerActions::attachCards(CardState *startCard, const CardState *targetCard)
{
if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
return;
@ -197,7 +198,7 @@ void PlayerActions::attachCards(CardItem *startCard, const CardItem *targetCard)
sendGameCommand(cmd);
}
void PlayerActions::createArrow(CardItem *startCard, const ArrowData &arrow, int deleteInPhase)
void PlayerActions::createArrow(CardState *startCard, const ArrowData &arrow, int deleteInPhase)
{
Command_CreateArrow cmd;
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(arrow.color));
@ -603,7 +604,7 @@ void PlayerActions::moveTopCardsUntil(const QString &expr, MoveTopCardsUntilOpti
}
}
void PlayerActions::moveOneCardUntil(CardItem *card)
void PlayerActions::moveOneCardUntil(CardState *card)
{
moveTopCardTimer->stop();
@ -1000,7 +1001,7 @@ void PlayerActions::actCreatePredefinedToken()
actCreateAnotherToken();
}
void PlayerActions::actCreateRelatedCard(const CardItem *sourceCard, int index)
void PlayerActions::actCreateRelatedCard(const CardState *sourceCard, int index)
{
if (!sourceCard) {
return;
@ -1012,7 +1013,7 @@ void PlayerActions::actCreateRelatedCard(const CardItem *sourceCard, int index)
actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
}
void PlayerActions::actCreateAllRelatedCards(const CardItem *sourceCard)
void PlayerActions::actCreateAllRelatedCards(const CardState *sourceCard)
{
if (!sourceCard) {
return;
@ -1099,13 +1100,13 @@ void PlayerActions::actCreateAllRelatedCards(const CardItem *sourceCard)
}
}
void PlayerActions::actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard,
void PlayerActions::actRequestCreateRelatedFromRelationDialog(const CardState *sourceCard,
const CardRelation *cardRelation)
{
emit requestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
}
bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard,
bool PlayerActions::createRelatedFromRelation(const CardState *sourceCard,
const CardRelation *cardRelation,
int variableCount)
{
@ -1157,7 +1158,7 @@ bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard,
return true;
}
void PlayerActions::onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation)
void PlayerActions::onRelatedCardCreated(const CardState *sourceCard, const CardRelation *cardRelation)
{
if (sourceCard == nullptr || cardRelation == nullptr) {
return;
@ -1177,7 +1178,7 @@ void PlayerActions::onRelatedCardCreated(const CardItem *sourceCard, const CardR
setLastToken(relatedCard.getCardPtr());
}
void PlayerActions::createCard(const CardItem *sourceCard,
void PlayerActions::createCard(const CardState *sourceCard,
const QString &dbCardName,
CardRelationType attachType,
bool persistent,
@ -1263,7 +1264,7 @@ void PlayerActions::actRequestMoveCardXCardsFromTopDialog()
emit requestMoveCardXCardsFromTopDialog(defaultNumberTopCardsToPlaceBelow, deckSize);
}
void PlayerActions::actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, int number)
void PlayerActions::actMoveCardXCardsFromTop(QList<CardState *> selectedCards, int number)
{
defaultNumberTopCardsToPlaceBelow = number;
@ -1297,7 +1298,7 @@ void PlayerActions::actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, in
}
}
void PlayerActions::actIncPT(QList<CardItem *> selectedCards, int deltaP, int deltaT)
void PlayerActions::actIncPT(QList<CardState *> selectedCards, int deltaP, int deltaT)
{
int playerid = player->getPlayerInfo()->getId();
@ -1330,7 +1331,7 @@ void PlayerActions::actIncPT(QList<CardItem *> selectedCards, int deltaP, int de
player->getGame()->getGameEventHandler()->sendGameCommand(prepareGameCommand(commandList), playerid);
}
void PlayerActions::actResetPT(QList<CardItem *> selectedCards)
void PlayerActions::actResetPT(QList<CardState *> selectedCards)
{
int playerid = player->getPlayerInfo()->getId();
QList<const ::google::protobuf::Message *> commandList;
@ -1363,7 +1364,7 @@ void PlayerActions::actResetPT(QList<CardItem *> selectedCards)
}
}
void PlayerActions::actRequestSetPTDialog(QList<CardItem *> selectedCards)
void PlayerActions::actRequestSetPTDialog(QList<CardState *> selectedCards)
{
QString oldPT;
@ -1376,7 +1377,7 @@ void PlayerActions::actRequestSetPTDialog(QList<CardItem *> selectedCards)
emit requestSetPTDialog(oldPT);
}
void PlayerActions::actSetPT(QList<CardItem *> selectedCards, const QString &pt)
void PlayerActions::actSetPT(QList<CardState *> selectedCards, const QString &pt)
{
int playerid = player->getPlayerInfo()->getId();
@ -1416,42 +1417,42 @@ void PlayerActions::actSetPT(QList<CardItem *> selectedCards, const QString &pt)
player->getGame()->getGameEventHandler()->sendGameCommand(prepareGameCommand(commandList), playerid);
}
void PlayerActions::actIncP(QList<CardItem *> selectedCards)
void PlayerActions::actIncP(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, 1, 0);
}
void PlayerActions::actDecP(QList<CardItem *> selectedCards)
void PlayerActions::actDecP(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, -1, 0);
}
void PlayerActions::actIncT(QList<CardItem *> selectedCards)
void PlayerActions::actIncT(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, 0, 1);
}
void PlayerActions::actDecT(QList<CardItem *> selectedCards)
void PlayerActions::actDecT(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, 0, -1);
}
void PlayerActions::actIncPT(QList<CardItem *> selectedCards)
void PlayerActions::actIncPT(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, 1, 1);
}
void PlayerActions::actDecPT(QList<CardItem *> selectedCards)
void PlayerActions::actDecPT(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, -1, -1);
}
void PlayerActions::actFlowP(QList<CardItem *> selectedCards)
void PlayerActions::actFlowP(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, 1, -1);
}
void PlayerActions::actFlowT(QList<CardItem *> selectedCards)
void PlayerActions::actFlowT(QList<CardState *> selectedCards)
{
actIncPT(selectedCards, -1, 1);
}
@ -1474,7 +1475,7 @@ void PlayerActions::actSetCounter(int counterId, int value)
sendGameCommand(cmd);
}
void PlayerActions::actReduceLifeByPower(QList<CardItem *> selectedCards)
void PlayerActions::actReduceLifeByPower(QList<CardState *> selectedCards)
{
// find life counter
auto lifeCounter = player->getLifeCounter();
@ -1499,7 +1500,7 @@ void PlayerActions::actReduceLifeByPower(QList<CardItem *> selectedCards)
sendGameCommand(prepareGameCommand(cmd));
}
void PlayerActions::actRequestSetAnnotationDialog(QList<CardItem *> selectedCards)
void PlayerActions::actRequestSetAnnotationDialog(QList<CardState *> selectedCards)
{
QString oldAnnotation;
for (auto card : selectedCards) {
@ -1511,7 +1512,7 @@ void PlayerActions::actRequestSetAnnotationDialog(QList<CardItem *> selectedCard
emit requestSetAnnotationDialog(oldAnnotation);
}
void PlayerActions::actSetAnnotation(QList<CardItem *> selectedCards, const QString &annotation)
void PlayerActions::actSetAnnotation(QList<CardState *> selectedCards, const QString &annotation)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
@ -1525,7 +1526,7 @@ void PlayerActions::actSetAnnotation(QList<CardItem *> selectedCards, const QStr
sendGameCommand(prepareGameCommand(commandList));
}
void PlayerActions::actUnattach(QList<CardItem *> selectedCards)
void PlayerActions::actUnattach(QList<CardState *> selectedCards)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
@ -1541,17 +1542,17 @@ void PlayerActions::actUnattach(QList<CardItem *> selectedCards)
sendGameCommand(prepareGameCommand(commandList));
}
void PlayerActions::actAddCardCounter(QList<CardItem *> selectedCards, int counterId)
void PlayerActions::actAddCardCounter(QList<CardState *> selectedCards, int counterId)
{
offsetCardCounter(selectedCards, counterId, 1);
}
void PlayerActions::actRemoveCardCounter(QList<CardItem *> selectedCards, int counterId)
void PlayerActions::actRemoveCardCounter(QList<CardState *> selectedCards, int counterId)
{
offsetCardCounter(selectedCards, counterId, -1);
}
void PlayerActions::offsetCardCounter(QList<CardItem *> selectedCards, int counterId, int offset)
void PlayerActions::offsetCardCounter(QList<CardState *> selectedCards, int counterId, int offset)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
@ -1577,7 +1578,7 @@ void PlayerActions::offsetCardCounter(QList<CardItem *> selectedCards, int count
sendGameCommand(prepareGameCommand(commandList));
}
void PlayerActions::actRequestSetCardCounterDialog(QList<CardItem *> selectedCards, int counterId)
void PlayerActions::actRequestSetCardCounterDialog(QList<CardState *> selectedCards, int counterId)
{
// If a single card is selected, we show the old value in the dialog. Otherwise, we show "x"
QString oldValueForDlg = "x";
@ -1589,7 +1590,7 @@ void PlayerActions::actRequestSetCardCounterDialog(QList<CardItem *> selectedCar
emit requestSetCardCounterDialog(counterId, oldValueForDlg);
}
void PlayerActions::actSetCardCounter(QList<CardItem *> selectedCards, int counterId, const QString &counterValue)
void PlayerActions::actSetCardCounter(QList<CardState *> selectedCards, int counterId, const QString &counterValue)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
@ -1610,12 +1611,12 @@ void PlayerActions::actSetCardCounter(QList<CardItem *> selectedCards, int count
sendGameCommand(prepareGameCommand(commandList));
}
void PlayerActions::actIncrementAllCardCounters(QList<CardItem *> cardsToUpdate)
void PlayerActions::actIncrementAllCardCounters(QList<CardState *> cardsToUpdate)
{
if (cardsToUpdate.isEmpty()) {
// If no cards selected, update all cards on table
for (auto *state : player->getTableZone()->getCards()) {
cardsToUpdate.append(qobject_cast<CardItem *>(state->parent()));
cardsToUpdate.append(state);
}
}
@ -1659,7 +1660,7 @@ static bool isUnwritableRevealZone(CardZoneLogic *zone)
return false;
}
void PlayerActions::playSelectedCards(QList<CardItem *> selectedCards, const bool faceDown)
void PlayerActions::playSelectedCards(QList<CardState *> selectedCards, const bool faceDown)
{
// CardIds will get shuffled downwards when cards leave the deck.
// We need to iterate through the cards in reverse order so cardIds don't get changed out from under us as we play
@ -1674,27 +1675,26 @@ void PlayerActions::playSelectedCards(QList<CardItem *> selectedCards, const boo
}
}
void PlayerActions::actPlay(QList<CardItem *> selectedCards)
void PlayerActions::actPlay(QList<CardState *> selectedCards)
{
playSelectedCards(selectedCards, false);
}
void PlayerActions::actPlayFacedown(QList<CardItem *> selectedCards)
void PlayerActions::actPlayFacedown(QList<CardState *> selectedCards)
{
playSelectedCards(selectedCards, true);
}
void PlayerActions::actHide(QList<CardItem *> selectedCards)
void PlayerActions::actHide(QList<CardState *> selectedCards)
{
for (const auto &item : selectedCards) {
auto *card = static_cast<CardItem *>(item);
if (card && isUnwritableRevealZone(card->getZone())) {
card->getZone()->removeCard(card->getState());
for (const auto &card : selectedCards) {
if (isUnwritableRevealZone(card->getZone())) {
card->getZone()->removeCard(card);
}
}
}
void PlayerActions::actReveal(QList<CardItem *> selectedCards, QAction *action)
void PlayerActions::actReveal(QList<CardState *> selectedCards, QAction *action)
{
const int otherPlayerId = action->data().toInt();
@ -1785,9 +1785,9 @@ void PlayerActions::actRevealRandomGraveyardCard(int revealToPlayerId)
sendGameCommand(cmd);
}
void PlayerActions::cardMenuAction(QList<CardItem *> selectedCards, CardMenuActionType type)
void PlayerActions::cardMenuAction(QList<CardState *> selectedCards, CardMenuActionType type)
{
QList<CardItem *> cardList = selectedCards;
QList<CardState *> cardList = selectedCards;
QList<const ::google::protobuf::Message *> commandList;
if (type <= cmClone) {
@ -2079,10 +2079,10 @@ PendingCommand *PlayerActions::prepareZoneDump(CardZoneLogic *zone, int numberCa
return prepareGameCommand(cmd);
}
void PlayerActions::actToggleTapped(const QString &zoneName, const QList<CardItem *> &cards, bool tapped)
void PlayerActions::actToggleTapped(const QString &zoneName, const QList<CardState *> &cards, bool tapped)
{
QList<const ::google::protobuf::Message *> cmdList;
for (CardItem *card : cards) {
for (CardState *card : cards) {
if (card->getTapped() != tapped) {
auto *cmd = new Command_SetCardAttr;
cmd->set_zone(zoneName.toStdString());