mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-07 05:53:59 -07:00
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.
This commit is contained in:
parent
be140bd1d6
commit
c50fb0d137
4 changed files with 27 additions and 24 deletions
|
|
@ -61,15 +61,15 @@ void Player::forwardActionSignalsToEventHandler()
|
|||
|
||||
void Player::initializeZones()
|
||||
{
|
||||
addZone(new PileZoneLogic(this, "deck", false, true, false, this));
|
||||
addZone(new PileZoneLogic(this, "grave", false, false, true, this));
|
||||
addZone(new PileZoneLogic(this, "rfg", false, false, true, this));
|
||||
addZone(new PileZoneLogic(this, "sb", false, false, false, this));
|
||||
addZone(new TableZoneLogic(this, "table", true, false, true, this));
|
||||
addZone(new StackZoneLogic(this, "stack", true, false, true, this));
|
||||
addZone(new PileZoneLogic(this, ZoneNames::DECK, false, true, false, this));
|
||||
addZone(new PileZoneLogic(this, ZoneNames::GRAVE, false, false, true, this));
|
||||
addZone(new PileZoneLogic(this, ZoneNames::EXILE, false, false, true, this));
|
||||
addZone(new PileZoneLogic(this, ZoneNames::SIDEBOARD, false, false, false, this));
|
||||
addZone(new TableZoneLogic(this, ZoneNames::TABLE, true, false, true, this));
|
||||
addZone(new StackZoneLogic(this, ZoneNames::STACK, true, false, true, this));
|
||||
bool visibleHand = playerInfo->getLocalOrJudge() ||
|
||||
(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()
|
||||
|
|
@ -119,13 +119,13 @@ void Player::setZoneId(int _zoneId)
|
|||
void Player::processPlayerInfo(const ServerInfo_Player &info)
|
||||
{
|
||||
static QSet<QString> builtinZones{/* PileZones */
|
||||
"deck", "grave", "rfg", "sb",
|
||||
ZoneNames::DECK, ZoneNames::GRAVE, ZoneNames::EXILE, ZoneNames::SIDEBOARD,
|
||||
/* TableZone */
|
||||
"table",
|
||||
ZoneNames::TABLE,
|
||||
/* StackZone */
|
||||
"stack",
|
||||
ZoneNames::STACK,
|
||||
/* HandZone */
|
||||
"hand"};
|
||||
ZoneNames::HAND};
|
||||
clearCounters();
|
||||
clearArrows();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <libcockatrice/filters/filter_string.h>
|
||||
#include <libcockatrice/protocol/pb/card_attributes.pb.h>
|
||||
#include <libcockatrice/protocol/pb/game_event.pb.h>
|
||||
#include <libcockatrice/utility/zone_names.h>
|
||||
|
||||
inline Q_LOGGING_CATEGORY(PlayerLog, "player");
|
||||
|
||||
|
|
@ -155,37 +156,37 @@ public:
|
|||
|
||||
PileZoneLogic *getDeckZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("deck"));
|
||||
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::DECK));
|
||||
}
|
||||
|
||||
PileZoneLogic *getGraveZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("grave"));
|
||||
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::GRAVE));
|
||||
}
|
||||
|
||||
PileZoneLogic *getRfgZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("rfg"));
|
||||
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::EXILE));
|
||||
}
|
||||
|
||||
PileZoneLogic *getSideboardZone()
|
||||
{
|
||||
return qobject_cast<PileZoneLogic *>(zones.value("sb"));
|
||||
return qobject_cast<PileZoneLogic *>(zones.value(ZoneNames::SIDEBOARD));
|
||||
}
|
||||
|
||||
TableZoneLogic *getTableZone()
|
||||
{
|
||||
return qobject_cast<TableZoneLogic *>(zones.value("table"));
|
||||
return qobject_cast<TableZoneLogic *>(zones.value(ZoneNames::TABLE));
|
||||
}
|
||||
|
||||
StackZoneLogic *getStackZone()
|
||||
{
|
||||
return qobject_cast<StackZoneLogic *>(zones.value("stack"));
|
||||
return qobject_cast<StackZoneLogic *>(zones.value(ZoneNames::STACK));
|
||||
}
|
||||
|
||||
HandZoneLogic *getHandZone()
|
||||
{
|
||||
return qobject_cast<HandZoneLogic *>(zones.value("hand"));
|
||||
return qobject_cast<HandZoneLogic *>(zones.value(ZoneNames::HAND));
|
||||
}
|
||||
|
||||
AbstractCounter *addCounter(const ServerInfo_Counter &counter);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include <QDebug>
|
||||
#include <libcockatrice/card/database/card_database_manager.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
|
||||
|
|
@ -174,9 +175,9 @@ void CardZoneLogic::clearContents()
|
|||
QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) const
|
||||
{
|
||||
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));
|
||||
else if (name == "deck")
|
||||
else if (name == ZoneNames::DECK)
|
||||
switch (gc) {
|
||||
case CaseLookAtZone:
|
||||
return (theirOwn ? tr("their library", "look at zone")
|
||||
|
|
@ -192,11 +193,11 @@ QString CardZoneLogic::getTranslatedName(bool theirOwn, GrammaticalCase gc) cons
|
|||
default:
|
||||
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));
|
||||
else if (name == "rfg")
|
||||
else if (name == ZoneNames::EXILE)
|
||||
return (theirOwn ? tr("their exile", "nominative") : tr("%1's exile", "nominative").arg(ownerName));
|
||||
else if (name == "sb")
|
||||
else if (name == ZoneNames::SIDEBOARD)
|
||||
switch (gc) {
|
||||
case CaseLookAtZone:
|
||||
return (theirOwn ? tr("their sideboard", "look at zone")
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#include <libcockatrice/card/card_info.h>
|
||||
#include <libcockatrice/protocol/pb/command_move_card.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::FADE_MASK = QColor(0, 0, 0, 80);
|
||||
|
|
@ -195,7 +196,7 @@ void TableZone::toggleTapped()
|
|||
|
||||
auto isCardOnTable = [](const QGraphicsItem *item) {
|
||||
if (auto card = qgraphicsitem_cast<const CardItem *>(item)) {
|
||||
return card->getZone()->getName() == "table";
|
||||
return card->getZone()->getName() == ZoneNames::TABLE;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue