[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

@ -19,7 +19,7 @@ class GameMetaInfo;
class GameReplay;
class GameState;
class PlayerManager;
class CardState;
class AbstractGame : public QObject
{
Q_OBJECT

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());

View file

@ -8,7 +8,6 @@
#ifndef COCKATRICE_PLAYER_ACTIONS_H
#define COCKATRICE_PLAYER_ACTIONS_H
#include "../../game_graphics/board/card_item.h" // IWYU pragma: keep - moc instantiates the metatype for QList<CardItem *>, which Qt 6.4 needs complete
#include "../board/card_list.h"
#include "card_menu_action_type.h"
#include "card_move_request.h"
@ -37,6 +36,7 @@ class Message;
}
} // namespace google
class CardState;
class CardZoneLogic;
class Command_MoveCard;
class PendingCommand;
@ -84,14 +84,14 @@ public:
* @param cards Cards the view wants toggled.
* @param tapped Desired tapped state.
*/
void actToggleTapped(const QString &zoneName, const QList<CardItem *> &cards, bool tapped);
void actToggleTapped(const QString &zoneName, const QList<CardState *> &cards, bool tapped);
/**
* @brief Attaches one card to another on the table on behalf of a view.
* @param startCard Card being attached.
* @param targetCard Card being attached to.
*/
void attachCards(CardItem *startCard, const CardItem *targetCard);
void attachCards(CardState *startCard, const CardState *targetCard);
/**
* @brief Draws an arrow from a card to another card or a player on behalf of a view.
@ -103,9 +103,9 @@ public:
* @param arrow Arrow endpoints and color, as resolved by the view.
* @param deleteInPhase Phase the arrow expires in, 0 to keep it until removed.
*/
void createArrow(CardItem *startCard, const ArrowData &arrow, int deleteInPhase);
void createArrow(CardState *startCard, const ArrowData &arrow, int deleteInPhase);
void moveOneCardUntil(CardItem *card);
void moveOneCardUntil(CardState *card);
void stopMoveTopCardsUntil();
[[nodiscard]] bool isMovingCardsUntil() const
@ -134,7 +134,7 @@ signals:
void requestDrawBottomCardsDialog(int defaultNumberBottomCards, int maxCards);
void requestRollDieDialog();
void requestCreateTokenDialog(const QStringList &predefinedTokens);
void requestCreateRelatedFromRelationDialog(const CardItem *sourceCard, const CardRelation *cardRelation);
void requestCreateRelatedFromRelationDialog(const CardState *sourceCard, const CardRelation *cardRelation);
void requestMoveCardXCardsFromTopDialog(int defaultNumberTopCardsToPlaceBelow, int deckSize);
void requestSetPTDialog(const QString &oldPT);
void requestSetAnnotationDialog(const QString &oldAnnotation);
@ -147,8 +147,8 @@ signals:
public slots:
void setLastToken(CardInfoPtr cardInfo);
void setLastTokenInfo(CardInfoPtr cardInfo);
void playCard(CardItem *c, bool faceDown);
void playCardToTable(const CardItem *c, bool faceDown);
void playCard(CardState *c, bool faceDown);
void playCardToTable(const CardState *c, bool faceDown);
void actUntapAll();
void actRequestRollDieDialog();
@ -157,9 +157,9 @@ public slots:
void actRequestCreateTokenDialog(const QStringList &predefinedTokens);
void actCreateToken(TokenInfo tokenToCreate);
void actCreateAnotherToken();
void actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard, const CardRelation *cardRelation);
bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation, int variableCount);
void onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation);
void actRequestCreateRelatedFromRelationDialog(const CardState *sourceCard, const CardRelation *cardRelation);
bool createRelatedFromRelation(const CardState *sourceCard, const CardRelation *cardRelation, int variableCount);
void onRelatedCardCreated(const CardState *sourceCard, const CardRelation *cardRelation);
void setLastRelatedCreationSucceeded(bool succeeded)
{
lastRelatedCreationSucceeded = succeeded;
@ -179,9 +179,9 @@ public slots:
void actMulliganMinusOne();
void doMulligan(int number);
void actPlay(QList<CardItem *> selectedCards);
void actPlayFacedown(QList<CardItem *> selectedCards);
void actHide(QList<CardItem *> selectedCards);
void actPlay(QList<CardState *> selectedCards);
void actPlayFacedown(QList<CardState *> selectedCards);
void actHide(QList<CardState *> selectedCards);
void actMoveTopCardToPlay();
void actMoveTopCardToPlayFaceDown();
@ -230,29 +230,29 @@ public slots:
void actOpenDeckInDeckEditor();
void actCreatePredefinedToken();
void actCreateRelatedCard(const CardItem *sourceCard, int index);
void actCreateAllRelatedCards(const CardItem *sourceCard);
void actCreateRelatedCard(const CardState *sourceCard, int index);
void actCreateAllRelatedCards(const CardState *sourceCard);
void actRequestMoveCardXCardsFromTopDialog();
void actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, int number);
void actRemoveCardCounter(QList<CardItem *> selectedCards, int counterId);
void actAddCardCounter(QList<CardItem *> selectedCards, int counterId);
void actRequestSetCardCounterDialog(QList<CardItem *> selectedCards, int counterId);
void actSetCardCounter(QList<CardItem *> selectedCards, int counterId, const QString &counterValue);
void actIncrementAllCardCounters(QList<CardItem *> cardsToUpdate);
void actUnattach(QList<CardItem *> selectedCards);
void actIncPT(QList<CardItem *> selectedCards, int deltaP, int deltaT);
void actResetPT(QList<CardItem *> selectedCards);
void actRequestSetPTDialog(QList<CardItem *> selectedCards);
void actSetPT(QList<CardItem *> selectedCards, const QString &pt);
void actIncP(QList<CardItem *> selectedCards);
void actDecP(QList<CardItem *> selectedCards);
void actIncT(QList<CardItem *> selectedCards);
void actDecT(QList<CardItem *> selectedCards);
void actIncPT(QList<CardItem *> selectedCards);
void actDecPT(QList<CardItem *> selectedCards);
void actFlowP(QList<CardItem *> selectedCards);
void actFlowT(QList<CardItem *> selectedCards);
void actMoveCardXCardsFromTop(QList<CardState *> selectedCards, int number);
void actRemoveCardCounter(QList<CardState *> selectedCards, int counterId);
void actAddCardCounter(QList<CardState *> selectedCards, int counterId);
void actRequestSetCardCounterDialog(QList<CardState *> selectedCards, int counterId);
void actSetCardCounter(QList<CardState *> selectedCards, int counterId, const QString &counterValue);
void actIncrementAllCardCounters(QList<CardState *> cardsToUpdate);
void actUnattach(QList<CardState *> selectedCards);
void actIncPT(QList<CardState *> selectedCards, int deltaP, int deltaT);
void actResetPT(QList<CardState *> selectedCards);
void actRequestSetPTDialog(QList<CardState *> selectedCards);
void actSetPT(QList<CardState *> selectedCards, const QString &pt);
void actIncP(QList<CardState *> selectedCards);
void actDecP(QList<CardState *> selectedCards);
void actIncT(QList<CardState *> selectedCards);
void actDecT(QList<CardState *> selectedCards);
void actIncPT(QList<CardState *> selectedCards);
void actDecPT(QList<CardState *> selectedCards);
void actFlowP(QList<CardState *> selectedCards);
void actFlowT(QList<CardState *> selectedCards);
/** @brief Adjusts a player counter by a signed delta. */
void actIncrementCounter(int counterId, int delta);
@ -260,18 +260,18 @@ public slots:
/** @brief Sets a player counter to an absolute value. */
void actSetCounter(int counterId, int value);
void actReduceLifeByPower(QList<CardItem *> selectedCards);
void actReduceLifeByPower(QList<CardState *> selectedCards);
void actRequestSetAnnotationDialog(QList<CardItem *> selectedCards);
void actSetAnnotation(QList<CardItem *> selectedCards, const QString &annotation);
void actReveal(QList<CardItem *> selectedCards, QAction *action);
void actRequestSetAnnotationDialog(QList<CardState *> selectedCards);
void actSetAnnotation(QList<CardState *> selectedCards, const QString &annotation);
void actReveal(QList<CardState *> selectedCards, QAction *action);
void actRevealHand(int revealToPlayerId);
void actRevealRandomHandCard(int revealToPlayerId);
void actRevealLibrary(int revealToPlayerId);
void actSortHand();
void cardMenuAction(QList<CardItem *> selectedCards, CardMenuActionType type);
void cardMenuAction(QList<CardState *> selectedCards, CardMenuActionType type);
private:
PlayerLogic *player;
@ -292,18 +292,18 @@ private:
bool lastRelatedCreationSucceeded = false;
void createCard(const CardItem *sourceCard,
void createCard(const CardState *sourceCard,
const QString &dbCardName,
CardRelationType attach = CardRelationType::DoesNotAttach,
bool persistent = false,
bool faceDown = false);
void playSelectedCards(QList<CardItem *> selectedCards, bool faceDown = false);
void playSelectedCards(QList<CardState *> selectedCards, bool faceDown = false);
void cmdSetTopCard(Command_MoveCard &cmd);
void cmdSetBottomCard(Command_MoveCard &cmd);
void offsetCardCounter(QList<CardItem *> selectedCards, int counterId, int offset);
void offsetCardCounter(QList<CardState *> selectedCards, int counterId, int offset);
};
#endif // COCKATRICE_PLAYER_ACTIONS_H

View file

@ -396,7 +396,7 @@ void PlayerEventHandler::eventMoveCard(const Event_MoveCard &event, const GameEv
if (player->getPlayerActions()->isMovingCardsUntil() && startZoneString == ZoneNames::DECK &&
targetZone->getName() == ZoneNames::STACK) {
player->getPlayerActions()->moveOneCardUntil(toCardItem(card));
player->getPlayerActions()->moveOneCardUntil(card);
}
}

View file

@ -1,11 +1,7 @@
#include "pile_zone_logic.h"
#include "../board/card_list.h"
#include "../board/card_state.h"
class PlayerLogic;
class QObject;
PileZoneLogic::PileZoneLogic(PlayerLogic *_player,
const QString &_name,
bool _hasCardAttr,

View file

@ -1,14 +1,9 @@
#include "table_zone_logic.h"
#include "../board/card_list.h"
#include "../board/card_state.h"
#include "libcockatrice/card/card_info.h"
#include <QPoint>
class PlayerLogic;
class QObject;
TableZoneLogic::TableZoneLogic(PlayerLogic *_player,
const QString &_name,
bool _hasCardAttr,

View file

@ -1,7 +1,6 @@
#include "view_zone_logic.h"
#include "../../client/settings/cache_settings.h"
#include "../board/card_list.h"
#include "../board/card_state.h"
#include "../player/player_actions.h"
#include "../player/player_logic.h"

View file

@ -444,7 +444,7 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
startCard->playCard(false);
}
player->getPlayerActions()->createArrow(startCard, arrow, deleteInPhase);
player->getPlayerActions()->createArrow(startCard->getState(), arrow, deleteInPhase);
}
delArrow();
@ -536,7 +536,7 @@ void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
auto *startCard = qgraphicsitem_cast<CardItem *>(startItem);
auto *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
if (startCard && targetCard) {
player->getPlayerActions()->attachCards(startCard, targetCard);
player->getPlayerActions()->attachCards(startCard->getState(), targetCard->getState());
}
}

View file

@ -442,7 +442,7 @@ void CardItem::playCard(bool faceDown)
emit playSelected(this);
}
} else {
state->getZone()->getPlayer()->getPlayerActions()->playCard(this, faceDown);
state->getZone()->getPlayer()->getPlayerActions()->playCard(state, faceDown);
}
}
}

View file

@ -113,6 +113,15 @@ void GameScene::retranslateUi()
}
}
QList<CardState *> GameScene::selectedCardStates() const
{
QList<CardState *> selectedStates;
for (auto *card : selectedCards()) {
selectedStates.append(card->getState());
}
return selectedStates;
}
QList<CardItem *> GameScene::selectedCards() const
{
QList<CardItem *> selectedCards;
@ -235,7 +244,7 @@ void GameScene::playSelected(AbstractCardItem *card)
if (!card->getOwner()) {
return;
}
card->getOwner()->getPlayerActions()->actPlay(selectedCards());
card->getOwner()->getPlayerActions()->actPlay(selectedCardStates());
}
void GameScene::playSelectedFaceDown(AbstractCardItem *card)
@ -246,7 +255,7 @@ void GameScene::playSelectedFaceDown(AbstractCardItem *card)
if (!card->getOwner()) {
return;
}
card->getOwner()->getPlayerActions()->actPlayFacedown(selectedCards());
card->getOwner()->getPlayerActions()->actPlayFacedown(selectedCardStates());
}
void GameScene::hideSelected(AbstractCardItem *card)
@ -257,7 +266,7 @@ void GameScene::hideSelected(AbstractCardItem *card)
if (!card->getOwner()) {
return;
}
card->getOwner()->getPlayerActions()->actHide(selectedCards());
card->getOwner()->getPlayerActions()->actHide(selectedCardStates());
}
/**

View file

@ -113,6 +113,7 @@ public:
/** @brief Gets all selected CardItems. */
QList<CardItem *> selectedCards() const;
QList<CardState *> selectedCardStates() const;
/** @brief Selects every card sharing the zone of @p card. */
void selectAllInZone(const CardItem *card);

View file

@ -86,7 +86,7 @@ CardMenu::CardMenu(PlayerGraphicsItem *_player, CardItem *_card, bool _shortcuts
auto *gameScene = player->getGameScene();
// Single selection resolver used by all lambdas — called at trigger time
auto sel = [gameScene]() { return gameScene->selectedCards(); };
auto sel = [gameScene]() { return gameScene->selectedCardStates(); };
// Unified dispatcher for card menu actions
auto invoke = [actions, sel](CardMenuActionType type) {
@ -337,7 +337,7 @@ void CardMenu::createHandOrCustomZoneMenu(bool canModifyCard)
initContextualPlayersMenu(revealMenu, aRevealToAll);
connect(revealMenu, &QMenu::triggered, this, [this](QAction *action) {
player->getLogic()->getPlayerActions()->actReveal(player->getGameScene()->selectedCards(), action);
player->getLogic()->getPlayerActions()->actReveal(player->getGameScene()->selectedCardStates(), action);
});
addSeparator();
@ -486,8 +486,9 @@ void CardMenu::addRelatedCardActions()
auto *createRelated = new QAction(text, this);
const int relatedIndex = index++;
connect(createRelated, &QAction::triggered, this,
[this, playerActions, relatedIndex] { playerActions->actCreateRelatedCard(card, relatedIndex); });
connect(createRelated, &QAction::triggered, this, [this, playerActions, relatedIndex] {
playerActions->actCreateRelatedCard(card->getState(), relatedIndex);
});
addAction(createRelated);
}
@ -497,7 +498,7 @@ void CardMenu::addRelatedCardActions()
SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens"));
}
connect(createRelatedCards, &QAction::triggered, this,
[this, playerActions] { playerActions->actCreateAllRelatedCards(card); });
[this, playerActions] { playerActions->actCreateAllRelatedCards(card->getState()); });
addAction(createRelatedCards);
}
}

View file

@ -30,7 +30,7 @@ MoveMenu::MoveMenu(PlayerGraphicsItem *player) : QMenu(tr("Move to"))
auto invoke = [player](CardMenuActionType type) {
return [type, player]() {
player->getLogic()->getPlayerActions()->cardMenuAction(player->getGameScene()->selectedCards(), type);
player->getLogic()->getPlayerActions()->cardMenuAction(player->getGameScene()->selectedCardStates(), type);
};
};

View file

@ -15,34 +15,35 @@ PtMenu::PtMenu(PlayerGraphicsItem *player) : QMenu(tr("Power / toughness"))
aIncP = new QAction(this);
connect(aIncP, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actIncP(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actIncP(player->getGameScene()->selectedCardStates()); });
aDecP = new QAction(this);
connect(aDecP, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actDecP(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actDecP(player->getGameScene()->selectedCardStates()); });
aIncT = new QAction(this);
connect(aIncT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actIncT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actIncT(player->getGameScene()->selectedCardStates()); });
aDecT = new QAction(this);
connect(aDecT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actDecT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actDecT(player->getGameScene()->selectedCardStates()); });
aIncPT = new QAction(this);
connect(aIncPT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actIncPT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actIncPT(player->getGameScene()->selectedCardStates()); });
aDecPT = new QAction(this);
connect(aDecPT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actDecPT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actDecPT(player->getGameScene()->selectedCardStates()); });
aFlowP = new QAction(this);
connect(aFlowP, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actFlowP(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actFlowP(player->getGameScene()->selectedCardStates()); });
aFlowT = new QAction(this);
connect(aFlowT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actFlowT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actFlowT(player->getGameScene()->selectedCardStates()); });
aSetPT = new QAction(this);
connect(aSetPT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actRequestSetPTDialog(player->getGameScene()->selectedCards()); });
connect(aSetPT, &QAction::triggered, playerActions, [player, playerActions] {
playerActions->actRequestSetPTDialog(player->getGameScene()->selectedCardStates());
});
aResetPT = new QAction(this);
connect(aResetPT, &QAction::triggered, playerActions,
[player, playerActions] { playerActions->actResetPT(player->getGameScene()->selectedCards()); });
[player, playerActions] { playerActions->actResetPT(player->getGameScene()->selectedCardStates()); });
addAction(aIncP);
addAction(aDecP);

View file

@ -44,7 +44,7 @@ UtilityMenu::UtilityMenu(PlayerGraphicsItem *_player, QMenu *playerMenu) : QMenu
aIncrementAllCardCounters = new QAction(this);
connect(aIncrementAllCardCounters, &QAction::triggered, playerActions, [this]() {
player->getLogic()->getPlayerActions()->actIncrementAllCardCounters(
player->getGameScene()->selectedCards());
player->getGameScene()->selectedCardStates());
});
createPredefinedTokenMenu = new QMenu(QString());

View file

@ -197,7 +197,7 @@ void PlayerDialogs::onRollDieDialogRequested()
playerActions->actRollDie(dlg.getDieSideCount(), dlg.getDiceToRollCount());
}
void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard,
void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardState *sourceCard,
const CardRelation *cardRelation)
{
if (sourceCard == nullptr || cardRelation == nullptr) {
@ -252,14 +252,14 @@ void PlayerDialogs::onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopC
number -= 1; // indexes start at 0
if (ok) {
playerActions->actMoveCardXCardsFromTop(player->getGameScene()->selectedCards(), number);
playerActions->actMoveCardXCardsFromTop(player->getGameScene()->selectedCardStates(), number);
}
}
void PlayerDialogs::onSetPTDialogRequested(const QString &oldPT)
{
bool ok;
auto cards = player->getGameScene()->selectedCards();
auto cards = player->getGameScene()->selectedCardStates();
emit requestDialogSemaphore(true);
QString pt = getTextWithMax(dialogParent(), tr("Change power/toughness"), tr("Change stats to:"), QLineEdit::Normal,
oldPT, &ok);
@ -274,7 +274,7 @@ void PlayerDialogs::onSetPTDialogRequested(const QString &oldPT)
void PlayerDialogs::onSetAnnotationDialogRequested(const QString &oldAnnotation)
{
auto cards = player->getGameScene()->selectedCards();
auto cards = player->getGameScene()->selectedCardStates();
emit requestDialogSemaphore(true);
AnnotationDialog *dialog = new AnnotationDialog(dialogParent());
dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
@ -292,7 +292,7 @@ void PlayerDialogs::onSetAnnotationDialogRequested(const QString &oldAnnotation)
void PlayerDialogs::onSetCardCounterDialogRequested(int counterId, const QString &oldValueForDlg)
{
auto cards = player->getGameScene()->selectedCards();
auto cards = player->getGameScene()->selectedCardStates();
emit requestDialogSemaphore(true);
auto &cardCounterSettings = SettingsCache::instance().cardCounters();

View file

@ -52,7 +52,7 @@ public slots:
bool faceDown);
void onDrawBottomCardsDialogRequested(int defaultNumberBottomCards, int maxCards);
void onRollDieDialogRequested();
void onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard, const CardRelation *cardRelation);
void onCreateRelatedFromRelationDialogRequested(const CardState *sourceCard, const CardRelation *cardRelation);
void onCreateTokenDialogRequested(const QStringList &predefinedTokens);
void onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopCardsToPlaceBelow, int deckSize);
void onSetPTDialogRequested(const QString &oldPT);

View file

@ -266,16 +266,16 @@ void TableZone::reorganizeCards()
void TableZone::toggleTapped()
{
QList<CardItem *> selectedCards;
QList<CardState *> selectedCards;
for (auto *item : scene()->selectedItems()) {
auto *card = qgraphicsitem_cast<CardItem *>(item);
if (card && card->getZone()->getName() == ZoneNames::TABLE) {
selectedCards.append(card);
selectedCards.append(card->getState());
}
}
const bool tapAll = std::any_of(selectedCards.begin(), selectedCards.end(),
[](const CardItem *card) { return !card->getTapped(); });
[](const CardState *card) { return !card->getTapped(); });
getLogic()->getPlayer()->getPlayerActions()->actToggleTapped(getLogic()->getName(), selectedCards, tapAll);
}