Refactor zone names (#6686)

* Add ZoneNames constants for protocol zone identifiers. Introduce a centralized ZoneNames namespace providing constexpr constants for zone identifiers used in the client-server protocol. This establishes a single source of truth for zone names like TABLE, GRAVE, EXILE, HAND, DECK, SIDEBOARD, and STACK. The protocol values remain unchanged (e.g., EXILE maps to rfg for backwards compatibility) while providing meaningful constant names.

* refactor(server): use ZoneNames constants in server game logic

 Replace hardcoded zone name strings with ZoneNames:: constants in:
 - server_player.cpp: zone setup, draw, shuffle, mulligan operations
 - server_abstract_player.cpp: card movement and token destruction
 - server_game.cpp: returning cards when players leave

 No functional changes - purely mechanical string literal replacement.

* refactor(client): use ZoneNames constants in core player/zone logic

 Update the foundational player and zone classes to use ZoneNames::
 constants instead of string literals. Changes include:
 - player.h/cpp: zone initialization and builtinZones set
 - card_zone_logic.cpp: zone name translation for UI display
 - table_zone.cpp: table zone operations

 No functional changes - purely mechanical string literal replacement.

* refactor(client): use ZoneNames constants in player actions and events

 Replace zone name strings with ZoneNames:: constants in the player
 action and event handling code. player_actions.cpp contains the most
 extensive changes (~90+ replacements) covering all card movement
 commands.

 No functional changes - purely mechanical string literal replacement.

* refactor(client): use ZoneNames constants in zone menu handlers

 Update all zone-specific menu files to use ZoneNames:: constants
 for QAction data values and zone targeting. This covers context menus
 for cards, graveyard, hand, and exile (RFG) zones.

 No functional changes - purely mechanical string literal replacement.

* refactor(client): use ZoneNames constants in game scene components

 Update remaining game scene components to use ZoneNames:: constants:
 - arrow_item.cpp: arrow drawing between cards
 - game_scene.cpp: zone view positioning
 - message_log_widget.cpp: removes duplicate local static constants
   that were previously defining zone names redundantly
 - phases_toolbar.cpp: phase actions (untap all)

 Notable: message_log_widget.cpp previously had its own local constants
 (TABLE_ZONE_NAME, GRAVE_ZONE_NAME, etc.) which are now removed in favor
 of the centralized ZoneNames:: constants.

* formatting fix
This commit is contained in:
DawnFire42
2026-03-11 19:34:05 -04:00
committed by GitHub
parent 42cec10457
commit 9e2276a59f
19 changed files with 207 additions and 173 deletions

View File

@@ -19,6 +19,7 @@
#include <libcockatrice/protocol/pb/command_create_arrow.pb.h> #include <libcockatrice/protocol/pb/command_create_arrow.pb.h>
#include <libcockatrice/protocol/pb/command_delete_arrow.pb.h> #include <libcockatrice/protocol/pb/command_delete_arrow.pb.h>
#include <libcockatrice/utility/color.h> #include <libcockatrice/utility/color.h>
#include <libcockatrice/utility/zone_names.h>
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color) ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false), : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), targetLocked(false),
@@ -239,16 +240,16 @@ void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
} }
// if the card is in hand then we will move the card to stack or table as part of drawing the arrow // if the card is in hand then we will move the card to stack or table as part of drawing the arrow
if (startZone->getName() == "hand") { if (startZone->getName() == ZoneNames::HAND) {
startCard->playCard(false); startCard->playCard(false);
CardInfoPtr ci = startCard->getCard().getCardPtr(); CardInfoPtr ci = startCard->getCard().getCardPtr();
bool playToStack = SettingsCache::instance().getPlayToStack(); bool playToStack = SettingsCache::instance().getPlayToStack();
if (ci && if (ci && ((!playToStack && ci->getUiAttributes().tableRow == 3) ||
((!playToStack && ci->getUiAttributes().tableRow == 3) || (playToStack && ci->getUiAttributes().tableRow != 0 &&
(playToStack && ci->getUiAttributes().tableRow != 0 && startCard->getZone()->getName() != "stack"))) startCard->getZone()->getName() != ZoneNames::STACK)))
cmd.set_start_zone("stack"); cmd.set_start_zone(ZoneNames::STACK);
else else
cmd.set_start_zone(playToStack ? "stack" : "table"); cmd.set_start_zone(playToStack ? ZoneNames::STACK : ZoneNames::TABLE);
} }
if (deleteInPhase != 0) { if (deleteInPhase != 0) {
@@ -318,7 +319,7 @@ void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard) void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCard)
{ {
// do nothing if target is already attached to another card or is not in play // do nothing if target is already attached to another card or is not in play
if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != "table") { if (targetCard->getAttachedTo() || targetCard->getZone()->getName() != ZoneNames::TABLE) {
return; return;
} }
@@ -326,12 +327,12 @@ void ArrowAttachItem::attachCards(CardItem *startCard, const CardItem *targetCar
CardZoneLogic *targetZone = targetCard->getZone(); CardZoneLogic *targetZone = targetCard->getZone();
// move card onto table first if attaching from some other zone // move card onto table first if attaching from some other zone
if (startZone->getName() != "table") { if (startZone->getName() != ZoneNames::TABLE) {
player->getPlayerActions()->playCardToTable(startCard, false); player->getPlayerActions()->playCardToTable(startCard, false);
} }
Command_AttachCard cmd; Command_AttachCard cmd;
cmd.set_start_zone("table"); cmd.set_start_zone(ZoneNames::TABLE);
cmd.set_card_id(startCard->getId()); cmd.set_card_id(startCard->getId());
cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId()); cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId());
cmd.set_target_zone(targetZone->getName().toStdString()); cmd.set_target_zone(targetZone->getName().toStdString());

View File

@@ -14,6 +14,7 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QSet> #include <QSet>
#include <QtMath> #include <QtMath>
#include <libcockatrice/utility/zone_names.h>
#include <numeric> #include <numeric>
/** /**
@@ -410,9 +411,9 @@ void GameScene::toggleZoneView(Player *player, const QString &zoneName, int numb
connect(item, &ZoneViewWidget::closePressed, this, &GameScene::removeZoneView); connect(item, &ZoneViewWidget::closePressed, this, &GameScene::removeZoneView);
addItem(item); addItem(item);
if (zoneName == "grave") if (zoneName == ZoneNames::GRAVE)
item->setPos(360, 100); item->setPos(360, 100);
else if (zoneName == "rfg") else if (zoneName == ZoneNames::EXILE)
item->setPos(380, 120); item->setPos(380, 120);
else else
item->setPos(340, 80); item->setPos(340, 80);

View File

@@ -10,16 +10,9 @@
#include <../../client/settings/card_counter_settings.h> #include <../../client/settings/card_counter_settings.h>
#include <libcockatrice/protocol/pb/context_move_card.pb.h> #include <libcockatrice/protocol/pb/context_move_card.pb.h>
#include <libcockatrice/protocol/pb/context_mulligan.pb.h> #include <libcockatrice/protocol/pb/context_mulligan.pb.h>
#include <libcockatrice/utility/zone_names.h>
#include <utility> #include <utility>
static const QString TABLE_ZONE_NAME = "table";
static const QString GRAVE_ZONE_NAME = "grave";
static const QString EXILE_ZONE_NAME = "rfg";
static const QString HAND_ZONE_NAME = "hand";
static const QString DECK_ZONE_NAME = "deck";
static const QString SIDEBOARD_ZONE_NAME = "sb";
static const QString STACK_ZONE_NAME = "stack";
static QString sanitizeHtml(QString dirty) static QString sanitizeHtml(QString dirty)
{ {
return dirty.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;"); return dirty.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace("\"", "&quot;");
@@ -37,15 +30,15 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position
QString fromStr; QString fromStr;
QString zoneName = zone->getName(); QString zoneName = zone->getName();
if (zoneName == TABLE_ZONE_NAME) { if (zoneName == ZoneNames::TABLE) {
fromStr = tr(" from play"); fromStr = tr(" from play");
} else if (zoneName == GRAVE_ZONE_NAME) { } else if (zoneName == ZoneNames::GRAVE) {
fromStr = tr(" from their graveyard"); fromStr = tr(" from their graveyard");
} else if (zoneName == EXILE_ZONE_NAME) { } else if (zoneName == ZoneNames::EXILE) {
fromStr = tr(" from exile"); fromStr = tr(" from exile");
} else if (zoneName == HAND_ZONE_NAME) { } else if (zoneName == ZoneNames::HAND) {
fromStr = tr(" from their hand"); fromStr = tr(" from their hand");
} else if (zoneName == DECK_ZONE_NAME) { } else if (zoneName == ZoneNames::DECK) {
if (position == 0) { if (position == 0) {
if (cardName.isEmpty()) { if (cardName.isEmpty()) {
if (ownerChange) { if (ownerChange) {
@@ -83,9 +76,9 @@ MessageLogWidget::getFromStr(CardZoneLogic *zone, QString cardName, int position
fromStr = tr(" from their library"); fromStr = tr(" from their library");
} }
} }
} else if (zoneName == SIDEBOARD_ZONE_NAME) { } else if (zoneName == ZoneNames::SIDEBOARD) {
fromStr = tr(" from sideboard"); fromStr = tr(" from sideboard");
} else if (zoneName == STACK_ZONE_NAME) { } else if (zoneName == ZoneNames::STACK) {
fromStr = tr(" from the stack"); fromStr = tr(" from the stack");
} else { } else {
fromStr = tr(" from custom zone '%1'").arg(zoneName); fromStr = tr(" from custom zone '%1'").arg(zoneName);
@@ -275,9 +268,9 @@ void MessageLogWidget::logMoveCard(Player *player,
bool ownerChanged = startZone->getPlayer() != targetZone->getPlayer(); bool ownerChanged = startZone->getPlayer() != targetZone->getPlayer();
// do not log if moved within the same zone // do not log if moved within the same zone
if ((startZoneName == TABLE_ZONE_NAME && targetZoneName == TABLE_ZONE_NAME && !ownerChanged) || if ((startZoneName == ZoneNames::TABLE && targetZoneName == ZoneNames::TABLE && !ownerChanged) ||
(startZoneName == HAND_ZONE_NAME && targetZoneName == HAND_ZONE_NAME) || (startZoneName == ZoneNames::HAND && targetZoneName == ZoneNames::HAND) ||
(startZoneName == EXILE_ZONE_NAME && targetZoneName == EXILE_ZONE_NAME)) { (startZoneName == ZoneNames::EXILE && targetZoneName == ZoneNames::EXILE)) {
return; return;
} }
@@ -306,28 +299,28 @@ void MessageLogWidget::logMoveCard(Player *player,
QString finalStr; QString finalStr;
std::optional<QString> fourthArg; std::optional<QString> fourthArg;
if (targetZoneName == TABLE_ZONE_NAME) { if (targetZoneName == ZoneNames::TABLE) {
soundEngine->playSound("play_card"); soundEngine->playSound("play_card");
if (card->getFaceDown()) { if (card->getFaceDown()) {
finalStr = tr("%1 puts %2 into play%3 face down."); finalStr = tr("%1 puts %2 into play%3 face down.");
} else { } else {
finalStr = tr("%1 puts %2 into play%3."); finalStr = tr("%1 puts %2 into play%3.");
} }
} else if (targetZoneName == GRAVE_ZONE_NAME) { } else if (targetZoneName == ZoneNames::GRAVE) {
if (card->getFaceDown()) { if (card->getFaceDown()) {
finalStr = tr("%1 puts %2%3 into their graveyard face down."); finalStr = tr("%1 puts %2%3 into their graveyard face down.");
} else { } else {
finalStr = tr("%1 puts %2%3 into their graveyard."); finalStr = tr("%1 puts %2%3 into their graveyard.");
} }
} else if (targetZoneName == EXILE_ZONE_NAME) { } else if (targetZoneName == ZoneNames::EXILE) {
if (card->getFaceDown()) { if (card->getFaceDown()) {
finalStr = tr("%1 exiles %2%3 face down."); finalStr = tr("%1 exiles %2%3 face down.");
} else { } else {
finalStr = tr("%1 exiles %2%3."); finalStr = tr("%1 exiles %2%3.");
} }
} else if (targetZoneName == HAND_ZONE_NAME) { } else if (targetZoneName == ZoneNames::HAND) {
finalStr = tr("%1 moves %2%3 to their hand."); finalStr = tr("%1 moves %2%3 to their hand.");
} else if (targetZoneName == DECK_ZONE_NAME) { } else if (targetZoneName == ZoneNames::DECK) {
if (newX == -1) { if (newX == -1) {
finalStr = tr("%1 puts %2%3 into their library."); finalStr = tr("%1 puts %2%3 into their library.");
} else if (newX >= targetZone->getCards().size()) { } else if (newX >= targetZone->getCards().size()) {
@@ -339,9 +332,9 @@ void MessageLogWidget::logMoveCard(Player *player,
fourthArg = QString::number(newX); fourthArg = QString::number(newX);
finalStr = tr("%1 puts %2%3 into their library %4 cards from the top."); finalStr = tr("%1 puts %2%3 into their library %4 cards from the top.");
} }
} else if (targetZoneName == SIDEBOARD_ZONE_NAME) { } else if (targetZoneName == ZoneNames::SIDEBOARD) {
finalStr = tr("%1 moves %2%3 to sideboard."); finalStr = tr("%1 moves %2%3 to sideboard.");
} else if (targetZoneName == STACK_ZONE_NAME) { } else if (targetZoneName == ZoneNames::STACK) {
soundEngine->playSound("play_card"); soundEngine->playSound("play_card");
if (card->getFaceDown()) { if (card->getFaceDown()) {
finalStr = tr("%1 plays %2%3 face down."); finalStr = tr("%1 plays %2%3 face down.");

View File

@@ -11,6 +11,7 @@
#include <libcockatrice/protocol/pb/command_next_turn.pb.h> #include <libcockatrice/protocol/pb/command_next_turn.pb.h>
#include <libcockatrice/protocol/pb/command_set_active_phase.pb.h> #include <libcockatrice/protocol/pb/command_set_active_phase.pb.h>
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h> #include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
#include <libcockatrice/utility/zone_names.h>
PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable) PhaseButton::PhaseButton(const QString &_name, QGraphicsItem *parent, QAction *_doubleClickAction, bool _highlightable)
: QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable), : QObject(), QGraphicsItem(parent), name(_name), active(false), highlightable(_highlightable),
@@ -259,7 +260,7 @@ void PhasesToolbar::actNextTurn()
void PhasesToolbar::actUntapAll() void PhasesToolbar::actUntapAll()
{ {
Command_SetCardAttr cmd; Command_SetCardAttr cmd;
cmd.set_zone("table"); cmd.set_zone(ZoneNames::TABLE);
cmd.set_attribute(AttrTapped); cmd.set_attribute(AttrTapped);
cmd.set_attr_value("0"); cmd.set_attr_value("0");

View File

@@ -12,6 +12,7 @@
#include <libcockatrice/card/database/card_database_manager.h> #include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/card/relation/card_relation.h> #include <libcockatrice/card/relation/card_relation.h>
#include <libcockatrice/utility/zone_names.h>
CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive) CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive)
: player(_player), card(_card), shortcutsActive(_shortcutsActive) : player(_player), card(_card), shortcutsActive(_shortcutsActive)
@@ -115,11 +116,12 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
} else if (writeableCard) { } else if (writeableCard) {
if (card->getZone()) { if (card->getZone()) {
if (card->getZone()->getName() == "table") { if (card->getZone()->getName() == ZoneNames::TABLE) {
createTableMenu(); createTableMenu();
} else if (card->getZone()->getName() == "stack") { } else if (card->getZone()->getName() == ZoneNames::STACK) {
createStackMenu(); createStackMenu();
} else if (card->getZone()->getName() == "rfg" || card->getZone()->getName() == "grave") { } else if (card->getZone()->getName() == ZoneNames::EXILE ||
card->getZone()->getName() == ZoneNames::GRAVE) {
createGraveyardOrExileMenu(); createGraveyardOrExileMenu();
} else { } else {
createHandOrCustomZoneMenu(); createHandOrCustomZoneMenu();
@@ -128,7 +130,7 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive
addMenu(new MoveMenu(player)); addMenu(new MoveMenu(player));
} }
} else { } else {
if (card->getZone() && card->getZone()->getName() != "hand") { if (card->getZone() && card->getZone()->getName() != ZoneNames::HAND) {
addAction(aDrawArrow); addAction(aDrawArrow);
addSeparator(); addSeparator();
addRelatedCardView(); addRelatedCardView();
@@ -285,7 +287,7 @@ void CardMenu::createHandOrCustomZoneMenu()
addMenu(new MoveMenu(player)); addMenu(new MoveMenu(player));
// actions that are really wonky when done from deck or sideboard // actions that are really wonky when done from deck or sideboard
if (card->getZone()->getName() == "hand") { if (card->getZone()->getName() == ZoneNames::HAND) {
addSeparator(); addSeparator();
addAction(aAttach); addAction(aAttach);
addAction(aDrawArrow); addAction(aDrawArrow);
@@ -298,7 +300,7 @@ void CardMenu::createHandOrCustomZoneMenu()
} }
addRelatedCardView(); addRelatedCardView();
if (card->getZone()->getName() == "hand") { if (card->getZone()->getName() == ZoneNames::HAND) {
addRelatedCardActions(); addRelatedCardActions();
} }
} }

View File

@@ -6,6 +6,7 @@
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
#include <libcockatrice/utility/zone_names.h>
GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player) GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
{ {
@@ -39,16 +40,16 @@ void GraveyardMenu::createMoveActions()
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
aMoveGraveToTopLibrary = new QAction(this); aMoveGraveToTopLibrary = new QAction(this);
aMoveGraveToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveGraveToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
aMoveGraveToBottomLibrary = new QAction(this); aMoveGraveToBottomLibrary = new QAction(this);
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveGraveToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
aMoveGraveToHand = new QAction(this); aMoveGraveToHand = new QAction(this);
aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0); aMoveGraveToHand->setData(QList<QVariant>() << ZoneNames::HAND << 0);
aMoveGraveToRfg = new QAction(this); aMoveGraveToRfg = new QAction(this);
aMoveGraveToRfg->setData(QList<QVariant>() << "rfg" << 0); aMoveGraveToRfg->setData(QList<QVariant>() << ZoneNames::EXILE << 0);
connect(aMoveGraveToTopLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); connect(aMoveGraveToTopLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);
connect(aMoveGraveToBottomLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); connect(aMoveGraveToBottomLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone);

View File

@@ -9,6 +9,7 @@
#include <QAction> #include <QAction>
#include <QMenu> #include <QMenu>
#include <libcockatrice/utility/zone_names.h>
HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player) HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player)
{ {
@@ -76,13 +77,13 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
aMoveHandToTopLibrary = new QAction(this); aMoveHandToTopLibrary = new QAction(this);
aMoveHandToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveHandToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
aMoveHandToBottomLibrary = new QAction(this); aMoveHandToBottomLibrary = new QAction(this);
aMoveHandToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveHandToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
aMoveHandToGrave = new QAction(this); aMoveHandToGrave = new QAction(this);
aMoveHandToGrave->setData(QList<QVariant>() << "grave" << 0); aMoveHandToGrave->setData(QList<QVariant>() << ZoneNames::GRAVE << 0);
aMoveHandToRfg = new QAction(this); aMoveHandToRfg = new QAction(this);
aMoveHandToRfg->setData(QList<QVariant>() << "rfg" << 0); aMoveHandToRfg->setData(QList<QVariant>() << ZoneNames::EXILE << 0);
auto hand = player->getHandZone(); auto hand = player->getHandZone();

View File

@@ -3,6 +3,8 @@
#include "../player.h" #include "../player.h"
#include "../player_actions.h" #include "../player_actions.h"
#include <libcockatrice/utility/zone_names.h>
RfgMenu::RfgMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player) RfgMenu::RfgMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
{ {
createMoveActions(); createMoveActions();
@@ -30,13 +32,13 @@ void RfgMenu::createMoveActions()
auto rfg = player->getRfgZone(); auto rfg = player->getRfgZone();
aMoveRfgToTopLibrary = new QAction(this); aMoveRfgToTopLibrary = new QAction(this);
aMoveRfgToTopLibrary->setData(QList<QVariant>() << "deck" << 0); aMoveRfgToTopLibrary->setData(QList<QVariant>() << ZoneNames::DECK << 0);
aMoveRfgToBottomLibrary = new QAction(this); aMoveRfgToBottomLibrary = new QAction(this);
aMoveRfgToBottomLibrary->setData(QList<QVariant>() << "deck" << -1); aMoveRfgToBottomLibrary->setData(QList<QVariant>() << ZoneNames::DECK << -1);
aMoveRfgToHand = new QAction(this); aMoveRfgToHand = new QAction(this);
aMoveRfgToHand->setData(QList<QVariant>() << "hand" << 0); aMoveRfgToHand->setData(QList<QVariant>() << ZoneNames::HAND << 0);
aMoveRfgToGrave = new QAction(this); aMoveRfgToGrave = new QAction(this);
aMoveRfgToGrave->setData(QList<QVariant>() << "grave" << 0); aMoveRfgToGrave->setData(QList<QVariant>() << ZoneNames::GRAVE << 0);
connect(aMoveRfgToTopLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); connect(aMoveRfgToTopLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);
connect(aMoveRfgToBottomLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); connect(aMoveRfgToBottomLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone);

View File

@@ -61,15 +61,15 @@ void Player::forwardActionSignalsToEventHandler()
void Player::initializeZones() void Player::initializeZones()
{ {
addZone(new PileZoneLogic(this, "deck", false, true, false, this)); addZone(new PileZoneLogic(this, ZoneNames::DECK, false, true, false, this));
addZone(new PileZoneLogic(this, "grave", false, false, true, this)); addZone(new PileZoneLogic(this, ZoneNames::GRAVE, false, false, true, this));
addZone(new PileZoneLogic(this, "rfg", false, false, true, this)); addZone(new PileZoneLogic(this, ZoneNames::EXILE, false, false, true, this));
addZone(new PileZoneLogic(this, "sb", false, false, false, this)); addZone(new PileZoneLogic(this, ZoneNames::SIDEBOARD, false, false, false, this));
addZone(new TableZoneLogic(this, "table", true, false, true, this)); addZone(new TableZoneLogic(this, ZoneNames::TABLE, true, false, true, this));
addZone(new StackZoneLogic(this, "stack", true, false, true, this)); addZone(new StackZoneLogic(this, ZoneNames::STACK, true, false, true, this));
bool visibleHand = playerInfo->getLocalOrJudge() || bool visibleHand = playerInfo->getLocalOrJudge() ||
(game->getPlayerManager()->isSpectator() && game->getGameMetaInfo()->spectatorsOmniscient()); (game->getPlayerManager()->isSpectator() && game->getGameMetaInfo()->spectatorsOmniscient());
addZone(new HandZoneLogic(this, "hand", false, false, visibleHand, this)); addZone(new HandZoneLogic(this, ZoneNames::HAND, false, false, visibleHand, this));
} }
Player::~Player() Player::~Player()
@@ -119,13 +119,13 @@ void Player::setZoneId(int _zoneId)
void Player::processPlayerInfo(const ServerInfo_Player &info) void Player::processPlayerInfo(const ServerInfo_Player &info)
{ {
static QSet<QString> builtinZones{/* PileZones */ static QSet<QString> builtinZones{/* PileZones */
"deck", "grave", "rfg", "sb", ZoneNames::DECK, ZoneNames::GRAVE, ZoneNames::EXILE, ZoneNames::SIDEBOARD,
/* TableZone */ /* TableZone */
"table", ZoneNames::TABLE,
/* StackZone */ /* StackZone */
"stack", ZoneNames::STACK,
/* HandZone */ /* HandZone */
"hand"}; ZoneNames::HAND};
clearCounters(); clearCounters();
clearArrows(); clearArrows();

View File

@@ -27,6 +27,7 @@
#include <libcockatrice/filters/filter_string.h> #include <libcockatrice/filters/filter_string.h>
#include <libcockatrice/protocol/pb/card_attributes.pb.h> #include <libcockatrice/protocol/pb/card_attributes.pb.h>
#include <libcockatrice/protocol/pb/game_event.pb.h> #include <libcockatrice/protocol/pb/game_event.pb.h>
#include <libcockatrice/utility/zone_names.h>
inline Q_LOGGING_CATEGORY(PlayerLog, "player"); inline Q_LOGGING_CATEGORY(PlayerLog, "player");
@@ -155,37 +156,37 @@ public:
PileZoneLogic *getDeckZone() PileZoneLogic *getDeckZone()
{ {
return qobject_cast<PileZoneLogic *>(zones.value("deck")); return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::DECK));
} }
PileZoneLogic *getGraveZone() PileZoneLogic *getGraveZone()
{ {
return qobject_cast<PileZoneLogic *>(zones.value("grave")); return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::GRAVE));
} }
PileZoneLogic *getRfgZone() PileZoneLogic *getRfgZone()
{ {
return qobject_cast<PileZoneLogic *>(zones.value("rfg")); return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::EXILE));
} }
PileZoneLogic *getSideboardZone() PileZoneLogic *getSideboardZone()
{ {
return qobject_cast<PileZoneLogic *>(zones.value("sb")); return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::SIDEBOARD));
} }
TableZoneLogic *getTableZone() TableZoneLogic *getTableZone()
{ {
return qobject_cast<TableZoneLogic *>(zones.value("table")); return qobject_cast<TableZoneLogic *>(zones.value(ZoneNames::TABLE));
} }
StackZoneLogic *getStackZone() StackZoneLogic *getStackZone()
{ {
return qobject_cast<StackZoneLogic *>(zones.value("stack")); return qobject_cast<StackZoneLogic *>(zones.value(ZoneNames::STACK));
} }
HandZoneLogic *getHandZone() HandZoneLogic *getHandZone()
{ {
return qobject_cast<HandZoneLogic *>(zones.value("hand")); return qobject_cast<HandZoneLogic *>(zones.value(ZoneNames::HAND));
} }
AbstractCounter *addCounter(const ServerInfo_Counter &counter); AbstractCounter *addCounter(const ServerInfo_Counter &counter);

View File

@@ -28,6 +28,7 @@
#include <libcockatrice/protocol/pb/command_undo_draw.pb.h> #include <libcockatrice/protocol/pb/command_undo_draw.pb.h>
#include <libcockatrice/protocol/pb/context_move_card.pb.h> #include <libcockatrice/protocol/pb/context_move_card.pb.h>
#include <libcockatrice/utility/trice_limits.h> #include <libcockatrice/utility/trice_limits.h>
#include <libcockatrice/utility/zone_names.h>
// milliseconds in between triggers of the move top cards until action // milliseconds in between triggers of the move top cards until action
static constexpr int MOVE_TOP_CARD_UNTIL_INTERVAL = 100; static constexpr int MOVE_TOP_CARD_UNTIL_INTERVAL = 100;
@@ -63,13 +64,13 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
int tableRow = info.getUiAttributes().tableRow; int tableRow = info.getUiAttributes().tableRow;
bool playToStack = SettingsCache::instance().getPlayToStack(); bool playToStack = SettingsCache::instance().getPlayToStack();
QString currentZone = card->getZone()->getName(); QString currentZone = card->getZone()->getName();
if (currentZone == "stack" && tableRow == 3) { if (currentZone == ZoneNames::STACK && tableRow == 3) {
cmd.set_target_zone("grave"); cmd.set_target_zone(ZoneNames::GRAVE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
} else if (!faceDown && } else if (!faceDown && ((!playToStack && tableRow == 3) ||
((!playToStack && tableRow == 3) || ((playToStack && tableRow != 0) && currentZone != "stack"))) { ((playToStack && tableRow != 0) && currentZone != ZoneNames::STACK))) {
cmd.set_target_zone("stack"); cmd.set_target_zone(ZoneNames::STACK);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
} else { } else {
@@ -81,7 +82,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
} }
cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt); cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt);
if (tableRow != 3) if (tableRow != 3)
cmd.set_target_zone("table"); cmd.set_target_zone(ZoneNames::TABLE);
cmd.set_x(gridPoint.x()); cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y()); cmd.set_y(gridPoint.y());
} }
@@ -124,7 +125,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
cardToMove->set_pt(info.getPowTough().toStdString()); cardToMove->set_pt(info.getPowTough().toStdString());
} }
cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt); cardToMove->set_tapped(!faceDown && info.getUiAttributes().cipt);
cmd.set_target_zone("table"); cmd.set_target_zone(ZoneNames::TABLE);
cmd.set_x(gridPoint.x()); cmd.set_x(gridPoint.x());
cmd.set_y(gridPoint.y()); cmd.set_y(gridPoint.y());
sendGameCommand(cmd); sendGameCommand(cmd);
@@ -132,12 +133,12 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
void PlayerActions::actViewLibrary() void PlayerActions::actViewLibrary()
{ {
player->getGameScene()->toggleZoneView(player, "deck", -1); player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, -1);
} }
void PlayerActions::actViewHand() void PlayerActions::actViewHand()
{ {
player->getGameScene()->toggleZoneView(player, "hand", -1); player->getGameScene()->toggleZoneView(player, ZoneNames::HAND, -1);
} }
/** /**
@@ -181,7 +182,7 @@ void PlayerActions::actViewTopCards()
deckSize, 1, &ok); deckSize, 1, &ok);
if (ok) { if (ok) {
defaultNumberTopCards = number; defaultNumberTopCards = number;
player->getGameScene()->toggleZoneView(player, "deck", number); player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, number);
} }
} }
@@ -194,14 +195,14 @@ void PlayerActions::actViewBottomCards()
deckSize, 1, &ok); deckSize, 1, &ok);
if (ok) { if (ok) {
defaultNumberBottomCards = number; defaultNumberBottomCards = number;
player->getGameScene()->toggleZoneView(player, "deck", number, true); player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, number, true);
} }
} }
void PlayerActions::actAlwaysRevealTopCard() void PlayerActions::actAlwaysRevealTopCard()
{ {
Command_ChangeZoneProperties cmd; Command_ChangeZoneProperties cmd;
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_always_reveal_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysRevealTopCardChecked()); cmd.set_always_reveal_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysRevealTopCardChecked());
sendGameCommand(cmd); sendGameCommand(cmd);
@@ -210,7 +211,7 @@ void PlayerActions::actAlwaysRevealTopCard()
void PlayerActions::actAlwaysLookAtTopCard() void PlayerActions::actAlwaysLookAtTopCard()
{ {
Command_ChangeZoneProperties cmd; Command_ChangeZoneProperties cmd;
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_always_look_at_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysLookAtTopCardChecked()); cmd.set_always_look_at_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysLookAtTopCardChecked());
sendGameCommand(cmd); sendGameCommand(cmd);
@@ -223,17 +224,17 @@ void PlayerActions::actOpenDeckInDeckEditor()
void PlayerActions::actViewGraveyard() void PlayerActions::actViewGraveyard()
{ {
player->getGameScene()->toggleZoneView(player, "grave", -1); player->getGameScene()->toggleZoneView(player, ZoneNames::GRAVE, -1);
} }
void PlayerActions::actViewRfg() void PlayerActions::actViewRfg()
{ {
player->getGameScene()->toggleZoneView(player, "rfg", -1); player->getGameScene()->toggleZoneView(player, ZoneNames::EXILE, -1);
} }
void PlayerActions::actViewSideboard() void PlayerActions::actViewSideboard()
{ {
player->getGameScene()->toggleZoneView(player, "sb", -1); player->getGameScene()->toggleZoneView(player, ZoneNames::SIDEBOARD, -1);
} }
void PlayerActions::actShuffle() void PlayerActions::actShuffle()
@@ -263,7 +264,7 @@ void PlayerActions::actShuffleTop()
defaultNumberTopCards = number; defaultNumberTopCards = number;
Command_Shuffle cmd; Command_Shuffle cmd;
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_start(0); cmd.set_start(0);
cmd.set_end(number - 1); // inclusive, the indexed card at end will be shuffled cmd.set_end(number - 1); // inclusive, the indexed card at end will be shuffled
@@ -292,7 +293,7 @@ void PlayerActions::actShuffleBottom()
defaultNumberBottomCards = number; defaultNumberBottomCards = number;
Command_Shuffle cmd; Command_Shuffle cmd;
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_start(-number); cmd.set_start(-number);
cmd.set_end(-1); cmd.set_end(-1);
@@ -376,7 +377,7 @@ void PlayerActions::actUndoDraw()
void PlayerActions::cmdSetTopCard(Command_MoveCard &cmd) void PlayerActions::cmdSetTopCard(Command_MoveCard &cmd)
{ {
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
auto *cardToMove = cmd.mutable_cards_to_move()->add_card(); auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(0); cardToMove->set_card_id(0);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
@@ -386,7 +387,7 @@ void PlayerActions::cmdSetBottomCard(Command_MoveCard &cmd)
{ {
CardZoneLogic *zone = player->getDeckZone(); CardZoneLogic *zone = player->getDeckZone();
int lastCard = zone->getCards().size() - 1; int lastCard = zone->getCards().size() - 1;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
auto *cardToMove = cmd.mutable_cards_to_move()->add_card(); auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(lastCard); cardToMove->set_card_id(lastCard);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
@@ -400,7 +401,7 @@ void PlayerActions::actMoveTopCardToGrave()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetTopCard(cmd); cmdSetTopCard(cmd);
cmd.set_target_zone("grave"); cmd.set_target_zone(ZoneNames::GRAVE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -415,7 +416,7 @@ void PlayerActions::actMoveTopCardToExile()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetTopCard(cmd); cmdSetTopCard(cmd);
cmd.set_target_zone("rfg"); cmd.set_target_zone(ZoneNames::EXILE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -424,22 +425,22 @@ void PlayerActions::actMoveTopCardToExile()
void PlayerActions::actMoveTopCardsToGrave() void PlayerActions::actMoveTopCardsToGrave()
{ {
moveTopCardsTo("grave", tr("grave"), false); moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), false);
} }
void PlayerActions::actMoveTopCardsToGraveFaceDown() void PlayerActions::actMoveTopCardsToGraveFaceDown()
{ {
moveTopCardsTo("grave", tr("grave"), true); moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), true);
} }
void PlayerActions::actMoveTopCardsToExile() void PlayerActions::actMoveTopCardsToExile()
{ {
moveTopCardsTo("rfg", tr("exile"), false); moveTopCardsTo(ZoneNames::EXILE, tr("exile"), false);
} }
void PlayerActions::actMoveTopCardsToExileFaceDown() void PlayerActions::actMoveTopCardsToExileFaceDown()
{ {
moveTopCardsTo("rfg", tr("exile"), true); moveTopCardsTo(ZoneNames::EXILE, tr("exile"), true);
} }
void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown) void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown)
@@ -463,7 +464,7 @@ void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zon
defaultNumberTopCards = number; defaultNumberTopCards = number;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
cmd.set_target_zone(targetZone.toStdString()); cmd.set_target_zone(targetZone.toStdString());
cmd.set_x(0); cmd.set_x(0);
@@ -549,7 +550,7 @@ void PlayerActions::actMoveTopCardToBottom()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetTopCard(cmd); cmdSetTopCard(cmd);
cmd.set_target_zone("deck"); cmd.set_target_zone(ZoneNames::DECK);
cmd.set_x(-1); // bottom of deck cmd.set_x(-1); // bottom of deck
cmd.set_y(0); cmd.set_y(0);
@@ -564,7 +565,7 @@ void PlayerActions::actMoveTopCardToPlay()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetTopCard(cmd); cmdSetTopCard(cmd);
cmd.set_target_zone("stack"); cmd.set_target_zone(ZoneNames::STACK);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
@@ -578,12 +579,12 @@ void PlayerActions::actMoveTopCardToPlayFaceDown()
} }
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card(); CardToMove *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(0); cardToMove->set_card_id(0);
cardToMove->set_face_down(true); cardToMove->set_face_down(true);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
cmd.set_target_zone("table"); cmd.set_target_zone(ZoneNames::TABLE);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
@@ -598,7 +599,7 @@ void PlayerActions::actMoveBottomCardToGrave()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetBottomCard(cmd); cmdSetBottomCard(cmd);
cmd.set_target_zone("grave"); cmd.set_target_zone(ZoneNames::GRAVE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -613,7 +614,7 @@ void PlayerActions::actMoveBottomCardToExile()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetBottomCard(cmd); cmdSetBottomCard(cmd);
cmd.set_target_zone("rfg"); cmd.set_target_zone(ZoneNames::EXILE);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -622,22 +623,22 @@ void PlayerActions::actMoveBottomCardToExile()
void PlayerActions::actMoveBottomCardsToGrave() void PlayerActions::actMoveBottomCardsToGrave()
{ {
moveBottomCardsTo("grave", tr("grave"), false); moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), false);
} }
void PlayerActions::actMoveBottomCardsToGraveFaceDown() void PlayerActions::actMoveBottomCardsToGraveFaceDown()
{ {
moveBottomCardsTo("grave", tr("grave"), true); moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), true);
} }
void PlayerActions::actMoveBottomCardsToExile() void PlayerActions::actMoveBottomCardsToExile()
{ {
moveBottomCardsTo("rfg", tr("exile"), false); moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), false);
} }
void PlayerActions::actMoveBottomCardsToExileFaceDown() void PlayerActions::actMoveBottomCardsToExileFaceDown()
{ {
moveBottomCardsTo("rfg", tr("exile"), true); moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), true);
} }
void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown) void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown)
@@ -661,7 +662,7 @@ void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &
defaultNumberBottomCards = number; defaultNumberBottomCards = number;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
cmd.set_target_zone(targetZone.toStdString()); cmd.set_target_zone(targetZone.toStdString());
cmd.set_x(0); cmd.set_x(0);
@@ -686,7 +687,7 @@ void PlayerActions::actMoveBottomCardToTop()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetBottomCard(cmd); cmdSetBottomCard(cmd);
cmd.set_target_zone("deck"); cmd.set_target_zone(ZoneNames::DECK);
cmd.set_x(0); // top of deck cmd.set_x(0); // top of deck
cmd.set_y(0); cmd.set_y(0);
@@ -756,7 +757,7 @@ void PlayerActions::actDrawBottomCard()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetBottomCard(cmd); cmdSetBottomCard(cmd);
cmd.set_target_zone("hand"); cmd.set_target_zone(ZoneNames::HAND);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -782,9 +783,9 @@ void PlayerActions::actDrawBottomCards()
defaultNumberBottomCards = number; defaultNumberBottomCards = number;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
cmd.set_target_zone("hand"); cmd.set_target_zone(ZoneNames::HAND);
cmd.set_x(0); cmd.set_x(0);
cmd.set_y(0); cmd.set_y(0);
@@ -803,7 +804,7 @@ void PlayerActions::actMoveBottomCardToPlay()
Command_MoveCard cmd; Command_MoveCard cmd;
cmdSetBottomCard(cmd); cmdSetBottomCard(cmd);
cmd.set_target_zone("stack"); cmd.set_target_zone(ZoneNames::STACK);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
@@ -820,13 +821,13 @@ void PlayerActions::actMoveBottomCardToPlayFaceDown()
int lastCard = zone->getCards().size() - 1; int lastCard = zone->getCards().size() - 1;
Command_MoveCard cmd; Command_MoveCard cmd;
cmd.set_start_zone("deck"); cmd.set_start_zone(ZoneNames::DECK);
auto *cardToMove = cmd.mutable_cards_to_move()->add_card(); auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
cardToMove->set_card_id(lastCard); cardToMove->set_card_id(lastCard);
cardToMove->set_face_down(true); cardToMove->set_face_down(true);
cmd.set_target_player_id(player->getPlayerInfo()->getId()); cmd.set_target_player_id(player->getPlayerInfo()->getId());
cmd.set_target_zone("table"); cmd.set_target_zone(ZoneNames::TABLE);
cmd.set_x(-1); cmd.set_x(-1);
cmd.set_y(0); cmd.set_y(0);
@@ -836,7 +837,7 @@ void PlayerActions::actMoveBottomCardToPlayFaceDown()
void PlayerActions::actUntapAll() void PlayerActions::actUntapAll()
{ {
Command_SetCardAttr cmd; Command_SetCardAttr cmd;
cmd.set_zone("table"); cmd.set_zone(ZoneNames::TABLE);
cmd.set_attribute(AttrTapped); cmd.set_attribute(AttrTapped);
cmd.set_attr_value("0"); cmd.set_attr_value("0");
@@ -886,7 +887,7 @@ void PlayerActions::actCreateAnotherToken()
} }
Command_CreateToken cmd; Command_CreateToken cmd;
cmd.set_zone("table"); cmd.set_zone(ZoneNames::TABLE);
cmd.set_card_name(lastTokenInfo.name.toStdString()); cmd.set_card_name(lastTokenInfo.name.toStdString());
cmd.set_card_provider_id(lastTokenInfo.providerId.toStdString()); cmd.set_card_provider_id(lastTokenInfo.providerId.toStdString());
cmd.set_color(lastTokenInfo.color.toStdString()); cmd.set_color(lastTokenInfo.color.toStdString());
@@ -1067,7 +1068,7 @@ bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const
// move card onto table first if attaching from some other zone // move card onto table first if attaching from some other zone
// we only do this for AttachTo because cross-zone TransformInto is already handled server-side // we only do this for AttachTo because cross-zone TransformInto is already handled server-side
if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != "table") { if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != ZoneNames::TABLE) {
playCardToTable(sourceCard, false); playCardToTable(sourceCard, false);
} }
@@ -1093,7 +1094,7 @@ void PlayerActions::createCard(const CardItem *sourceCard,
// create the token for the related card // create the token for the related card
Command_CreateToken cmd; Command_CreateToken cmd;
cmd.set_zone("table"); cmd.set_zone(ZoneNames::TABLE);
cmd.set_card_name(cardInfo->getName().toStdString()); cmd.set_card_name(cardInfo->getName().toStdString());
switch (cardInfo->getColors().size()) { switch (cardInfo->getColors().size()) {
case 0: case 0:
@@ -1122,12 +1123,12 @@ void PlayerActions::createCard(const CardItem *sourceCard,
switch (attachType) { switch (attachType) {
case CardRelationType::DoesNotAttach: case CardRelationType::DoesNotAttach:
cmd.set_target_zone("table"); cmd.set_target_zone(ZoneNames::TABLE);
cmd.set_card_provider_id(relatedCard.getPrinting().getUuid().toStdString()); cmd.set_card_provider_id(relatedCard.getPrinting().getUuid().toStdString());
break; break;
case CardRelationType::AttachTo: case CardRelationType::AttachTo:
cmd.set_target_zone("table"); // We currently only support creating tokens on the table cmd.set_target_zone(ZoneNames::TABLE); // We currently only support creating tokens on the table
cmd.set_card_provider_id(relatedCard.getPrinting().getUuid().toStdString()); cmd.set_card_provider_id(relatedCard.getPrinting().getUuid().toStdString());
cmd.set_target_card_id(sourceCard->getId()); cmd.set_target_card_id(sourceCard->getId());
cmd.set_target_mode(Command_CreateToken::ATTACH_TO); cmd.set_target_mode(Command_CreateToken::ATTACH_TO);
@@ -1135,7 +1136,7 @@ void PlayerActions::createCard(const CardItem *sourceCard,
case CardRelationType::TransformInto: case CardRelationType::TransformInto:
// allow cards to directly transform on stack // allow cards to directly transform on stack
cmd.set_zone(sourceCard->getZone()->getName() == "stack" ? "stack" : "table"); cmd.set_zone(sourceCard->getZone()->getName() == ZoneNames::STACK ? ZoneNames::STACK : ZoneNames::TABLE);
// Transform card zone changes are handled server-side // Transform card zone changes are handled server-side
cmd.set_target_zone(sourceCard->getZone()->getName().toStdString()); cmd.set_target_zone(sourceCard->getZone()->getName().toStdString());
cmd.set_target_card_id(sourceCard->getId()); cmd.set_target_card_id(sourceCard->getId());
@@ -1250,7 +1251,7 @@ void PlayerActions::actMoveCardXCardsFromTop()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("deck"); cmd->set_target_zone(ZoneNames::DECK);
cmd->set_x(number); cmd->set_x(number);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
@@ -1639,7 +1640,7 @@ void PlayerActions::playSelectedCards(const bool faceDown)
[](const auto &card1, const auto &card2) { return card1->getId() > card2->getId(); }); [](const auto &card1, const auto &card2) { return card1->getId() > card2->getId(); });
for (auto &card : selectedCards) { for (auto &card : selectedCards) {
if (card && !isUnwritableRevealZone(card->getZone()) && card->getZone()->getName() != "table") { if (card && !isUnwritableRevealZone(card->getZone()) && card->getZone()->getName() != ZoneNames::TABLE) {
playCard(card, faceDown); playCard(card, faceDown);
} }
} }
@@ -1692,7 +1693,7 @@ void PlayerActions::actRevealHand(int revealToPlayerId)
if (revealToPlayerId != -1) { if (revealToPlayerId != -1) {
cmd.set_player_id(revealToPlayerId); cmd.set_player_id(revealToPlayerId);
} }
cmd.set_zone_name("hand"); cmd.set_zone_name(ZoneNames::HAND);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
@@ -1703,7 +1704,7 @@ void PlayerActions::actRevealRandomHandCard(int revealToPlayerId)
if (revealToPlayerId != -1) { if (revealToPlayerId != -1) {
cmd.set_player_id(revealToPlayerId); cmd.set_player_id(revealToPlayerId);
} }
cmd.set_zone_name("hand"); cmd.set_zone_name(ZoneNames::HAND);
cmd.add_card_id(RANDOM_CARD_FROM_ZONE); cmd.add_card_id(RANDOM_CARD_FROM_ZONE);
sendGameCommand(cmd); sendGameCommand(cmd);
@@ -1715,7 +1716,7 @@ void PlayerActions::actRevealLibrary(int revealToPlayerId)
if (revealToPlayerId != -1) { if (revealToPlayerId != -1) {
cmd.set_player_id(revealToPlayerId); cmd.set_player_id(revealToPlayerId);
} }
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
@@ -1726,7 +1727,7 @@ void PlayerActions::actLendLibrary(int lendToPlayerId)
if (lendToPlayerId != -1) { if (lendToPlayerId != -1) {
cmd.set_player_id(lendToPlayerId); cmd.set_player_id(lendToPlayerId);
} }
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_grant_write_access(true); cmd.set_grant_write_access(true);
sendGameCommand(cmd); sendGameCommand(cmd);
@@ -1739,7 +1740,7 @@ void PlayerActions::actRevealTopCards(int revealToPlayerId, int amount)
cmd.set_player_id(revealToPlayerId); cmd.set_player_id(revealToPlayerId);
} }
cmd.set_zone_name("deck"); cmd.set_zone_name(ZoneNames::DECK);
cmd.set_top_cards(amount); cmd.set_top_cards(amount);
// backward compatibility: servers before #1051 only permits to reveal the first card // backward compatibility: servers before #1051 only permits to reveal the first card
cmd.add_card_id(0); cmd.add_card_id(0);
@@ -1753,7 +1754,7 @@ void PlayerActions::actRevealRandomGraveyardCard(int revealToPlayerId)
if (revealToPlayerId != -1) { if (revealToPlayerId != -1) {
cmd.set_player_id(revealToPlayerId); cmd.set_player_id(revealToPlayerId);
} }
cmd.set_zone_name("grave"); cmd.set_zone_name(ZoneNames::GRAVE);
cmd.add_card_id(RANDOM_CARD_FROM_ZONE); cmd.add_card_id(RANDOM_CARD_FROM_ZONE);
sendGameCommand(cmd); sendGameCommand(cmd);
} }
@@ -1816,7 +1817,7 @@ void PlayerActions::cardMenuAction()
} }
case cmClone: { case cmClone: {
auto *cmd = new Command_CreateToken; auto *cmd = new Command_CreateToken;
cmd->set_zone("table"); cmd->set_zone(ZoneNames::TABLE);
cmd->set_card_name(card->getName().toStdString()); cmd->set_card_name(card->getName().toStdString());
cmd->set_card_provider_id(card->getProviderId().toStdString()); cmd->set_card_provider_id(card->getProviderId().toStdString());
cmd->set_color(card->getColor().toStdString()); cmd->set_color(card->getColor().toStdString());
@@ -1858,13 +1859,13 @@ void PlayerActions::cardMenuAction()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("deck"); cmd->set_target_zone(ZoneNames::DECK);
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
if (idList.card_size() > 1) { if (idList.card_size() > 1) {
auto *scmd = new Command_Shuffle; auto *scmd = new Command_Shuffle;
scmd->set_zone_name("deck"); scmd->set_zone_name(ZoneNames::DECK);
scmd->set_start(0); scmd->set_start(0);
scmd->set_end(idList.card_size() - 1); // inclusive, the indexed card at end will be shuffled scmd->set_end(idList.card_size() - 1); // inclusive, the indexed card at end will be shuffled
// Server process events backwards, so... // Server process events backwards, so...
@@ -1880,13 +1881,13 @@ void PlayerActions::cardMenuAction()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("deck"); cmd->set_target_zone(ZoneNames::DECK);
cmd->set_x(-1); cmd->set_x(-1);
cmd->set_y(0); cmd->set_y(0);
if (idList.card_size() > 1) { if (idList.card_size() > 1) {
auto *scmd = new Command_Shuffle; auto *scmd = new Command_Shuffle;
scmd->set_zone_name("deck"); scmd->set_zone_name(ZoneNames::DECK);
scmd->set_start(-idList.card_size()); scmd->set_start(-idList.card_size());
scmd->set_end(-1); scmd->set_end(-1);
// Server process events backwards, so... // Server process events backwards, so...
@@ -1902,7 +1903,7 @@ void PlayerActions::cardMenuAction()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("hand"); cmd->set_target_zone(ZoneNames::HAND);
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
@@ -1914,7 +1915,7 @@ void PlayerActions::cardMenuAction()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("grave"); cmd->set_target_zone(ZoneNames::GRAVE);
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);
@@ -1926,7 +1927,7 @@ void PlayerActions::cardMenuAction()
cmd->set_start_zone(startZone.toStdString()); cmd->set_start_zone(startZone.toStdString());
cmd->mutable_cards_to_move()->CopyFrom(idList); cmd->mutable_cards_to_move()->CopyFrom(idList);
cmd->set_target_player_id(player->getPlayerInfo()->getId()); cmd->set_target_player_id(player->getPlayerInfo()->getId());
cmd->set_target_zone("rfg"); cmd->set_target_zone(ZoneNames::EXILE);
cmd->set_x(0); cmd->set_x(0);
cmd->set_y(0); cmd->set_y(0);
commandList.append(cmd); commandList.append(cmd);

View File

@@ -30,6 +30,7 @@
#include <libcockatrice/protocol/pb/event_set_card_counter.pb.h> #include <libcockatrice/protocol/pb/event_set_card_counter.pb.h>
#include <libcockatrice/protocol/pb/event_set_counter.pb.h> #include <libcockatrice/protocol/pb/event_set_counter.pb.h>
#include <libcockatrice/protocol/pb/event_shuffle.pb.h> #include <libcockatrice/protocol/pb/event_shuffle.pb.h>
#include <libcockatrice/utility/zone_names.h>
PlayerEventHandler::PlayerEventHandler(Player *_player) : player(_player) PlayerEventHandler::PlayerEventHandler(Player *_player) : player(_player)
{ {
@@ -321,8 +322,8 @@ void PlayerEventHandler::eventMoveCard(const Event_MoveCard &event, const GameEv
} }
player->getPlayerMenu()->updateCardMenu(card); player->getPlayerMenu()->updateCardMenu(card);
if (player->getPlayerActions()->isMovingCardsUntil() && startZoneString == "deck" && if (player->getPlayerActions()->isMovingCardsUntil() && startZoneString == ZoneNames::DECK &&
targetZone->getName() == "stack") { targetZone->getName() == ZoneNames::STACK) {
player->getPlayerActions()->moveOneCardUntil(card); player->getPlayerActions()->moveOneCardUntil(card);
} }
} }

View File

@@ -10,6 +10,7 @@
#include <QDebug> #include <QDebug>
#include <libcockatrice/card/database/card_database_manager.h> #include <libcockatrice/card/database/card_database_manager.h>
#include <libcockatrice/protocol/pb/command_move_card.pb.h> #include <libcockatrice/protocol/pb/command_move_card.pb.h>
#include <libcockatrice/utility/zone_names.h>
/** /**
* @param _player the player that the zone belongs to * @param _player the player that the zone belongs to
@@ -174,9 +175,9 @@ void CardZoneLogic::clearContents()
QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) const QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) const
{ {
QString ownerName = player->getPlayerInfo()->getName(); QString ownerName = player->getPlayerInfo()->getName();
if (name == "hand") if (name == ZoneNames::HAND)
return (theirOwn ? tr("their hand", "nominative") : tr("%1's hand", "nominative").arg(ownerName)); return (theirOwn ? tr("their hand", "nominative") : tr("%1's hand", "nominative").arg(ownerName));
else if (name == "deck") else if (name == ZoneNames::DECK)
switch (gc) { switch (gc) {
case CaseLookAtZone: case CaseLookAtZone:
return (theirOwn ? tr("their library", "look at zone") return (theirOwn ? tr("their library", "look at zone")
@@ -192,11 +193,11 @@ QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) cons
default: default:
return (theirOwn ? tr("their library", "nominative") : tr("%1's library", "nominative").arg(ownerName)); return (theirOwn ? tr("their library", "nominative") : tr("%1's library", "nominative").arg(ownerName));
} }
else if (name == "grave") else if (name == ZoneNames::GRAVE)
return (theirOwn ? tr("their graveyard", "nominative") : tr("%1's graveyard", "nominative").arg(ownerName)); return (theirOwn ? tr("their graveyard", "nominative") : tr("%1's graveyard", "nominative").arg(ownerName));
else if (name == "rfg") else if (name == ZoneNames::EXILE)
return (theirOwn ? tr("their exile", "nominative") : tr("%1's exile", "nominative").arg(ownerName)); return (theirOwn ? tr("their exile", "nominative") : tr("%1's exile", "nominative").arg(ownerName));
else if (name == "sb") else if (name == ZoneNames::SIDEBOARD)
switch (gc) { switch (gc) {
case CaseLookAtZone: case CaseLookAtZone:
return (theirOwn ? tr("their sideboard", "look at zone") return (theirOwn ? tr("their sideboard", "look at zone")

View File

@@ -15,6 +15,7 @@
#include <libcockatrice/card/card_info.h> #include <libcockatrice/card/card_info.h>
#include <libcockatrice/protocol/pb/command_move_card.pb.h> #include <libcockatrice/protocol/pb/command_move_card.pb.h>
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h> #include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
#include <libcockatrice/utility/zone_names.h>
const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100); const QColor TableZone::BACKGROUND_COLOR = QColor(100, 100, 100);
const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80); const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80);
@@ -195,7 +196,7 @@ void TableZone::toggleTapped()
auto isCardOnTable = [](const QGraphicsItem *item) { auto isCardOnTable = [](const QGraphicsItem *item) {
if (auto card = qgraphicsitem_cast<const CardItem *>(item)) { if (auto card = qgraphicsitem_cast<const CardItem *>(item)) {
return card->getZone()->getName() == "table"; return card->getZone()->getName() == ZoneNames::TABLE;
} }
return false; return false;
}; };

View File

@@ -48,6 +48,7 @@
#include <libcockatrice/protocol/pb/serverinfo_user.pb.h> #include <libcockatrice/protocol/pb/serverinfo_user.pb.h>
#include <libcockatrice/rng/rng_abstract.h> #include <libcockatrice/rng/rng_abstract.h>
#include <libcockatrice/utility/trice_limits.h> #include <libcockatrice/utility/trice_limits.h>
#include <libcockatrice/utility/zone_names.h>
Server_AbstractPlayer::Server_AbstractPlayer(Server_Game *_game, Server_AbstractPlayer::Server_AbstractPlayer(Server_Game *_game,
int _playerId, int _playerId,
@@ -190,8 +191,8 @@ shouldDestroyOnMove(const Server_Card *card, const Server_CardZone *startZone, c
} }
// Allow tokens on the stack // Allow tokens on the stack
if ((startZone->getName() == "table" || startZone->getName() == "stack") && if ((startZone->getName() == ZoneNames::TABLE || startZone->getName() == ZoneNames::STACK) &&
(targetZone->getName() == "table" || targetZone->getName() == "stack")) { (targetZone->getName() == ZoneNames::TABLE || targetZone->getName() == ZoneNames::STACK)) {
return false; return false;
} }
@@ -264,7 +265,7 @@ Response::ResponseCode Server_AbstractPlayer::moveCard(GameEventStorage &ges,
} }
// do not allow attached cards to move around on the table // do not allow attached cards to move around on the table
if (card->getParentCard() && targetzone->getName() == "table") { if (card->getParentCard() && targetzone->getName() == ZoneNames::TABLE) {
continue; continue;
} }
@@ -347,7 +348,7 @@ Response::ResponseCode Server_AbstractPlayer::moveCard(GameEventStorage &ges,
newX = targetzone->getFreeGridColumn(newX, yCoord, card->getName(), faceDown); newX = targetzone->getFreeGridColumn(newX, yCoord, card->getName(), faceDown);
} else { } else {
yCoord = 0; yCoord = 0;
card->resetState(targetzone->getName() == "stack"); card->resetState(targetzone->getName() == ZoneNames::STACK);
} }
targetzone->insertCard(card, newX, yCoord); targetzone->insertCard(card, newX, yCoord);

View File

@@ -51,6 +51,7 @@
#include <libcockatrice/protocol/pb/event_set_active_phase.pb.h> #include <libcockatrice/protocol/pb/event_set_active_phase.pb.h>
#include <libcockatrice/protocol/pb/event_set_active_player.pb.h> #include <libcockatrice/protocol/pb/event_set_active_player.pb.h>
#include <libcockatrice/protocol/pb/game_replay.pb.h> #include <libcockatrice/protocol/pb/game_replay.pb.h>
#include <libcockatrice/utility/zone_names.h>
Server_Game::Server_Game(const ServerInfo_User &_creatorInfo, Server_Game::Server_Game(const ServerInfo_User &_creatorInfo,
int _gameId, int _gameId,
@@ -832,7 +833,7 @@ void Server_Game::returnCardsFromPlayer(GameEventStorage &ges, Server_AbstractPl
QMutexLocker locker(&gameMutex); QMutexLocker locker(&gameMutex);
// Return cards to their rightful owners before conceding the game // Return cards to their rightful owners before conceding the game
static const QRegularExpression ownerRegex{"Owner: ?([^\n]+)"}; static const QRegularExpression ownerRegex{"Owner: ?([^\n]+)"};
const auto &playerTable = player->getZones().value("table"); const auto &playerTable = player->getZones().value(ZoneNames::TABLE);
for (const auto &card : playerTable->getCards()) { for (const auto &card : playerTable->getCards()) {
if (card == nullptr) { if (card == nullptr) {
continue; continue;
@@ -858,7 +859,7 @@ void Server_Game::returnCardsFromPlayer(GameEventStorage &ges, Server_AbstractPl
continue; continue;
} }
const auto &targetZone = otherPlayer->getZones().value("table"); const auto &targetZone = otherPlayer->getZones().value(ZoneNames::TABLE);
if (playerTable == nullptr || targetZone == nullptr) { if (playerTable == nullptr || targetZone == nullptr) {
continue; continue;

View File

@@ -47,6 +47,7 @@
#include <libcockatrice/rng/rng_abstract.h> #include <libcockatrice/rng/rng_abstract.h>
#include <libcockatrice/utility/color.h> #include <libcockatrice/utility/color.h>
#include <libcockatrice/utility/trice_limits.h> #include <libcockatrice/utility/trice_limits.h>
#include <libcockatrice/utility/zone_names.h>
Server_Player::Server_Player(Server_Game *_game, Server_Player::Server_Player(Server_Game *_game,
int _playerId, int _playerId,
@@ -80,15 +81,15 @@ void Server_Player::setupZones()
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Create zones // Create zones
auto *deckZone = new Server_CardZone(this, "deck", false, ServerInfo_Zone::HiddenZone); auto *deckZone = new Server_CardZone(this, ZoneNames::DECK, false, ServerInfo_Zone::HiddenZone);
addZone(deckZone); addZone(deckZone);
auto *sbZone = new Server_CardZone(this, "sb", false, ServerInfo_Zone::HiddenZone); auto *sbZone = new Server_CardZone(this, ZoneNames::SIDEBOARD, false, ServerInfo_Zone::HiddenZone);
addZone(sbZone); addZone(sbZone);
addZone(new Server_CardZone(this, "table", true, ServerInfo_Zone::PublicZone)); addZone(new Server_CardZone(this, ZoneNames::TABLE, true, ServerInfo_Zone::PublicZone));
addZone(new Server_CardZone(this, "hand", false, ServerInfo_Zone::PrivateZone)); addZone(new Server_CardZone(this, ZoneNames::HAND, false, ServerInfo_Zone::PrivateZone));
addZone(new Server_CardZone(this, "stack", false, ServerInfo_Zone::PublicZone)); addZone(new Server_CardZone(this, ZoneNames::STACK, false, ServerInfo_Zone::PublicZone));
addZone(new Server_CardZone(this, "grave", false, ServerInfo_Zone::PublicZone)); addZone(new Server_CardZone(this, ZoneNames::GRAVE, false, ServerInfo_Zone::PublicZone));
addZone(new Server_CardZone(this, "rfg", false, ServerInfo_Zone::PublicZone)); addZone(new Server_CardZone(this, ZoneNames::EXILE, false, ServerInfo_Zone::PublicZone));
addCounter(new Server_Counter(0, "life", makeColor(255, 255, 255), 25, game->getStartingLifeTotal())); addCounter(new Server_Counter(0, "life", makeColor(255, 255, 255), 25, game->getStartingLifeTotal()));
addCounter(new Server_Counter(1, "w", makeColor(255, 255, 150), 20, 0)); addCounter(new Server_Counter(1, "w", makeColor(255, 255, 150), 20, 0));
@@ -164,8 +165,8 @@ void Server_Player::addCounter(Server_Counter *counter)
Response::ResponseCode Server_Player::drawCards(GameEventStorage &ges, int number) Response::ResponseCode Server_Player::drawCards(GameEventStorage &ges, int number)
{ {
Server_CardZone *deckZone = zones.value("deck"); Server_CardZone *deckZone = zones.value(ZoneNames::DECK);
Server_CardZone *handZone = zones.value("hand"); Server_CardZone *handZone = zones.value(ZoneNames::HAND);
if (deckZone->getCards().size() < number) { if (deckZone->getCards().size() < number) {
number = deckZone->getCards().size(); number = deckZone->getCards().size();
} }
@@ -210,7 +211,7 @@ void Server_Player::onCardBeingMoved(GameEventStorage &ges,
// "Undo draw" should only remain valid if the just-drawn card stays within the user's hand (e.g., they only // "Undo draw" should only remain valid if the just-drawn card stays within the user's hand (e.g., they only
// reorder their hand). If a just-drawn card leaves the hand then remove cards before it from the list // reorder their hand). If a just-drawn card leaves the hand then remove cards before it from the list
// (Ignore the case where the card is currently being un-drawn.) // (Ignore the case where the card is currently being un-drawn.)
if (startzone->getName() == "hand" && targetzone->getName() != "hand" && !undoingDraw) { if (startzone->getName() == ZoneNames::HAND && targetzone->getName() != ZoneNames::HAND && !undoingDraw) {
int index = lastDrawList.lastIndexOf(card->getId()); int index = lastDrawList.lastIndexOf(card->getId());
if (index != -1) { if (index != -1) {
lastDrawList.erase(lastDrawList.begin(), lastDrawList.begin() + index); lastDrawList.erase(lastDrawList.begin(), lastDrawList.begin() + index);
@@ -326,11 +327,11 @@ Server_Player::cmdShuffle(const Command_Shuffle &cmd, ResponseContainer & /*rc*/
return Response::RespContextError; return Response::RespContextError;
} }
if (cmd.has_zone_name() && cmd.zone_name() != "deck") { if (cmd.has_zone_name() && cmd.zone_name() != ZoneNames::DECK) {
return Response::RespFunctionNotAllowed; return Response::RespFunctionNotAllowed;
} }
Server_CardZone *zone = zones.value("deck"); Server_CardZone *zone = zones.value(ZoneNames::DECK);
if (!zone) { if (!zone) {
return Response::RespNameNotFound; return Response::RespNameNotFound;
} }
@@ -357,8 +358,8 @@ Server_Player::cmdMulligan(const Command_Mulligan &cmd, ResponseContainer & /*rc
return Response::RespContextError; return Response::RespContextError;
} }
Server_CardZone *hand = zones.value("hand"); Server_CardZone *hand = zones.value(ZoneNames::HAND);
Server_CardZone *_deck = zones.value("deck"); Server_CardZone *_deck = zones.value(ZoneNames::DECK);
int number = cmd.number(); int number = cmd.number();
if (!hand->getCards().isEmpty()) { if (!hand->getCards().isEmpty()) {
@@ -414,8 +415,8 @@ Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer &
Response::ResponseCode retVal; Response::ResponseCode retVal;
auto *cardToMove = new CardToMove; auto *cardToMove = new CardToMove;
cardToMove->set_card_id(lastDrawList.takeLast()); cardToMove->set_card_id(lastDrawList.takeLast());
retVal = moveCard(ges, zones.value("hand"), QList<const CardToMove *>() << cardToMove, zones.value("deck"), 0, 0, retVal = moveCard(ges, zones.value(ZoneNames::HAND), QList<const CardToMove *>() << cardToMove,
false, true); zones.value(ZoneNames::DECK), 0, 0, false, true);
delete cardToMove; delete cardToMove;
return retVal; return retVal;

View File

@@ -10,8 +10,13 @@ set(UTILITY_SOURCES libcockatrice/utility/expression.cpp libcockatrice/utility/l
) )
set(UTILITY_HEADERS set(UTILITY_HEADERS
libcockatrice/utility/color.h libcockatrice/utility/expression.h libcockatrice/utility/levenshtein.h libcockatrice/utility/color.h
libcockatrice/utility/macros.h libcockatrice/utility/passwordhasher.h libcockatrice/utility/trice_limits.h libcockatrice/utility/expression.h
libcockatrice/utility/levenshtein.h
libcockatrice/utility/macros.h
libcockatrice/utility/passwordhasher.h
libcockatrice/utility/trice_limits.h
libcockatrice/utility/zone_names.h
) )
add_library(libcockatrice_utility STATIC ${UTILITY_SOURCES} ${UTILITY_HEADERS}) add_library(libcockatrice_utility STATIC ${UTILITY_SOURCES} ${UTILITY_HEADERS})

View File

@@ -0,0 +1,19 @@
#ifndef ZONE_NAMES_H
#define ZONE_NAMES_H
namespace ZoneNames
{
// Protocol-level zone identifiers shared between client and server.
// These must match exactly across all components.
constexpr const char *TABLE = "table";
constexpr const char *GRAVE = "grave";
constexpr const char *EXILE = "rfg"; // "removed from game"
constexpr const char *HAND = "hand";
constexpr const char *DECK = "deck";
constexpr const char *SIDEBOARD = "sb";
constexpr const char *STACK = "stack";
} // namespace ZoneNames
#endif // ZONE_NAMES_H