[Refactor] Move card item creation out of game logic

This commit is contained in:
Lukas Brübach 2026-10-07 10:08:54 +02:00 • committed by GitHub
parent e0d2f158e9
commit 16caae5e5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 121 additions and 82 deletions

View file

@ -1,8 +1,9 @@
#include "player_logic.h"
#include "../../game_graphics/board/card_item.h"
#include "../abstract_game.h"
#include "../board/arrow_data.h"
#include "../board/card_list.h"
#include "../board/card_state.h"
#include "../board/counter_state.h"
#include "../game_meta_info.h"
#include "../zones/hand_zone_logic.h"
@ -177,22 +178,20 @@ void PlayerLogic::processPlayerInfo(const ServerInfo_Player &info)
const int cardListSize = zoneInfo.card_list_size();
if (!cardListSize) {
for (int j = 0; j < zoneInfo.card_count(); ++j) {
zone->addCard((new CardItem(this))->getState(), false, -1);
emit zone->requestCreateCard(ServerInfo_Card(), false);
}
} else {
for (int j = 0; j < cardListSize; ++j) {
const ServerInfo_Card &cardInfo = zoneInfo.card_list(j);
auto *card = new CardItem(this);
card->processCardInfo(cardInfo);
ServerInfo_Card cardInfo = zoneInfo.card_list(j);
// Zones without coordinates (hand, piles, stack) preserve the order
// they arrive in on the server in the positions of their cards list.
// The x coordinate of such cards is always 0, so inserting at it
// would reverse the list on reconnect. Append instead.
if (zoneInfo.with_coords()) {
zone->addCard(card->getState(), false, cardInfo.x(), cardInfo.y());
} else {
zone->addCard(card->getState(), false, -1);
if (!zoneInfo.with_coords()) {
cardInfo.set_x(-1);
cardInfo.set_y(-1);
}
emit zone->requestCreateCard(cardInfo, false);
}
}
if (zoneInfo.has_always_reveal_top_card()) {
@ -250,7 +249,7 @@ void PlayerLogic::processCardAttachment(const ServerInfo_Player &info)
}
}
void PlayerLogic::addCard(CardItem *card)
void PlayerLogic::addCard(AbstractCardItem *card)
{
emit newCardAdded(card);
}