[Refactor] Move table row mapping from TableZone into TableZoneLogic

This commit is contained in:
Lukas Brübach 2026-10-06 12:39:15 +02:00 • committed by GitHub
parent c02576b827
commit c7605a51e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 43 additions and 38 deletions

View file

@ -3,7 +3,6 @@
#include "../../client/settings/cache_settings.h" #include "../../client/settings/cache_settings.h"
#include "../../game_graphics/board/card_item.h" #include "../../game_graphics/board/card_item.h"
#include "../../game_graphics/dialogs/dlg_create_token.h" #include "../../game_graphics/dialogs/dlg_create_token.h"
#include "../../game_graphics/zones/table_zone.h"
#include "../../interface/deck_loader/loaded_deck.h" #include "../../interface/deck_loader/loaded_deck.h"
#include "../abstract_game.h" #include "../abstract_game.h"
#include "../board/counter_state.h" #include "../board/counter_state.h"
@ -121,7 +120,7 @@ void PlayerActions::playCard(CardItem *card, bool faceDown)
cmd.set_y(0); cmd.set_y(0);
} else { } else {
tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow)); QPoint gridPoint = QPoint(-1, TableZoneLogic::tableRowToGridY(tableRow));
cardToMove->set_face_down(faceDown); cardToMove->set_face_down(faceDown);
if (!faceDown) { if (!faceDown) {
cardToMove->set_pt(info.getPowTough().toStdString()); cardToMove->set_pt(info.getPowTough().toStdString());
@ -161,7 +160,7 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown)
const CardInfo &info = exactCard.getInfo(); const CardInfo &info = exactCard.getInfo();
int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow; int tableRow = faceDown ? 2 : info.getUiAttributes().tableRow;
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(tableRow)); QPoint gridPoint = QPoint(-1, TableZoneLogic::tableRowToGridY(tableRow));
cardToMove->set_face_down(faceDown); cardToMove->set_face_down(faceDown);
if (!faceDown) { if (!faceDown) {
cardToMove->set_pt(info.getPowTough().toStdString()); cardToMove->set_pt(info.getPowTough().toStdString());
@ -925,7 +924,7 @@ void PlayerActions::actCreateToken(TokenInfo tokenToCreate)
if (correctedCard) { if (correctedCard) {
lastTokenInfo.name = correctedCard.getName(); lastTokenInfo.name = correctedCard.getName();
int tableRow = lastTokenInfo.faceDown ? 2 : correctedCard.getInfo().getUiAttributes().tableRow; int tableRow = lastTokenInfo.faceDown ? 2 : correctedCard.getInfo().getUiAttributes().tableRow;
lastTokenTableRow = TableZone::tableRowToGridY(tableRow); lastTokenTableRow = TableZoneLogic::tableRowToGridY(tableRow);
if (lastTokenInfo.pt.isEmpty()) { if (lastTokenInfo.pt.isEmpty()) {
lastTokenInfo.pt = correctedCard.getInfo().getPowTough(); lastTokenInfo.pt = correctedCard.getInfo().getPowTough();
} }
@ -979,7 +978,7 @@ void PlayerActions::setLastTokenInfo(CardInfoPtr cardInfo)
.destroy = true, .destroy = true,
.providerId = SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())}; .providerId = SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName())};
lastTokenTableRow = TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow); lastTokenTableRow = TableZoneLogic::tableRowToGridY(cardInfo->getUiAttributes().tableRow);
emit requestEnableAndSetCreateAnotherTokenAction(lastTokenInfo.name); emit requestEnableAndSetCreateAnotherTokenAction(lastTokenInfo.name);
} }
@ -1191,7 +1190,7 @@ void PlayerActions::createCard(const CardItem *sourceCard,
return; return;
} }
QPoint gridPoint = QPoint(-1, TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow)); QPoint gridPoint = QPoint(-1, TableZoneLogic::tableRowToGridY(cardInfo->getUiAttributes().tableRow));
// create the token for the related card // create the token for the related card
Command_CreateToken cmd; Command_CreateToken cmd;
@ -1977,7 +1976,7 @@ void PlayerActions::cardMenuAction(QList<CardItem *> selectedCards, CardMenuActi
ctm->set_tapped(info.getUiAttributes().cipt); ctm->set_tapped(info.getUiAttributes().cipt);
} }
cmd->set_y(TableZone::tableRowToGridY(tableRow)); cmd->set_y(TableZoneLogic::tableRowToGridY(tableRow));
commandList.append(cmd); commandList.append(cmd);
} }
break; break;

View file

@ -41,3 +41,22 @@ CardItem *TableZoneLogic::takeCard(int position, int cardId, bool toNewZone)
} }
return result; return result;
} }
int TableZoneLogic::clampValidTableRow(const int row)
{
if (row < 0) {
return 0;
}
if (row >= ROW_COUNT) {
return ROW_COUNT - 1;
}
return row;
}
int TableZoneLogic::tableRowToGridY(int tableRow)
{
if (tableRow > 2) {
tableRow = 1;
}
return clampValidTableRow(2 - tableRow);
}

View file

@ -29,6 +29,21 @@ public:
bool _contentsKnown, bool _contentsKnown,
QObject *parent = nullptr); QObject *parent = nullptr);
/** @brief Number of rows in the table zone grid (0=creatures, 1=noncreatures, 2=lands). */
static const int ROW_COUNT = 3;
/**
* Clamps a grid row index into [0, ROW_COUNT - 1].
*/
static int clampValidTableRow(const int row);
/**
* Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands)
* to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g.,
* instants/sorceries) default to the noncreatures row.
*/
static int tableRowToGridY(int tableRow);
protected: protected:
void addCardImpl(CardItem *card, int x, int y) override; void addCardImpl(CardItem *card, int x, int y) override;

View file

@ -423,7 +423,7 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const
const int gridPointHeight = CardDimensions::HEIGHT + PADDING_Y; const int gridPointHeight = CardDimensions::HEIGHT + PADDING_Y;
int gridPointY = (y + PADDING_Y / 2) / gridPointHeight; int gridPointY = (y + PADDING_Y / 2) / gridPointHeight;
gridPointY = clampValidTableRow(gridPointY); gridPointY = TableZoneLogic::clampValidTableRow(gridPointY);
if (isInverted()) { if (isInverted()) {
gridPointY = TABLEROWS - 1 - gridPointY; gridPointY = TABLEROWS - 1 - gridPointY;
@ -471,22 +471,3 @@ QPointF TableZone::closestGridPoint(const QPointF &point)
} }
return mapFromGrid(gridPoint); return mapFromGrid(gridPoint);
} }
int TableZone::clampValidTableRow(const int row)
{
if (row < 0) {
return 0;
}
if (row >= TABLEROWS) {
return TABLEROWS - 1;
}
return row;
}
int TableZone::tableRowToGridY(int tableRow)
{
if (tableRow > 2) {
tableRow = 1;
}
return clampValidTableRow(2 - tableRow);
}

View file

@ -42,7 +42,7 @@ signals:
void sizeChanged(); void sizeChanged();
private: private:
static const int TABLEROWS = 3; static const int TABLEROWS = TableZoneLogic::ROW_COUNT;
/* /*
Margins between table edges and cards, paddings between cards Margins between table edges and cards, paddings between cards
@ -181,15 +181,6 @@ public:
QPointF closestGridPoint(const QPointF &point) override; QPointF closestGridPoint(const QPointF &point) override;
static int clampValidTableRow(const int row);
/**
* Converts a card's logical table row (0=creatures, 1=noncreatures, 2=lands)
* to the corresponding grid Y coordinate. Cards with tableRow > 2 (e.g.,
* instants/sorceries) default to the noncreatures row.
*/
static int tableRowToGridY(int tableRow);
/** /**
Resizes the TableZone in case CardItems are within or Resizes the TableZone in case CardItems are within or
outside of the TableZone constraints. outside of the TableZone constraints.