Player refactor (#6112)

* Player refactor.

Took 1 hour 43 minutes

Took 1 minute


Took 23 seconds

* Tiny lint.

Took 3 minutes

* Hook up tap logic again.

Took 13 minutes

* Fix an include.

Took 3 minutes

* Stuff.

Took 6 minutes

* Fix typo.

Took 7 minutes

* Include.

Took 1 minute

* Reorganize method/variable definitions, remove unused ones.

Took 1 hour 8 minutes


Took 24 seconds

* Clean up some unused imports.

Took 6 minutes

* Player holds the deck, emits deckChanged(), other elements player->getDeck() to respond to changes.

Took 37 minutes

* Connect player->openDeckEditor signal directly in the player constructor

Took 6 minutes

* Emit openDeckEditor signal in player_actions again.

Took 3 minutes

* Do to-do's

Took 3 hours 32 minutes

* Lint.

Took 3 minutes

* Lint again.

Took 2 minutes

* Fix include.

Took 32 minutes

* The stack should ensure card visibility.

Took 21 minutes

* Fine, the game can remember the tab.

Took 10 minutes

Took 21 seconds

Took 9 seconds

* zoneId is a dynamic gameplay property and thus belongs in player.cpp

Took 11 minutes

Took 19 seconds

* Signal view removal, addition.

Took 5 minutes

* Ensure all players are considered local in local game.

Took 10 minutes

* ENSURE they are.

Took 8 minutes

* Bounds check data sent by QAction()

Took 54 minutes

* Move comment.

Took 20 seconds

* Reimplement logging category for game_event_handler.cpp, remove linebreaks.

Took 36 seconds

* PlayerGraphicsItem is responsible for retranslateUi, not Player.


Took 14 seconds

* Set menu for sideboard again, translate some menu titles, reimplement actIncPT action

Took 54 seconds

* Comment spacing.

Took 43 seconds

* Change message_log_widget.cpp slots to take CardZoneLogic parameters as emitted by PlayerEventHandler.

Took 7 minutes

Took 14 seconds

* Remove unused player_logger.cpp

Took 2 minutes

* Query local game state correctly from tab_supervisor again

Took 3 minutes

* Revert Deck legality checker.

Took 3 minutes

* Instantiate menu before graphics item.

Took 1 hour 5 minutes

Took 55 minutes

* Differentiate games and replays.


Took 9 seconds

* Lint.

Took 10 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-09-11 00:49:33 +02:00 committed by GitHub
parent b8e545bfa4
commit 9601a1fa4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
92 changed files with 7104 additions and 5827 deletions

View file

@ -7,6 +7,7 @@
#include "../game_scene.h"
#include "../player/player.h"
#include "../zones/card_zone.h"
#include "../zones/logic/view_zone_logic.h"
#include "../zones/table_zone.h"
#include "../zones/view_zone.h"
#include "arrow_item.h"
@ -18,7 +19,7 @@
#include <QMenu>
#include <QPainter>
CardItem::CardItem(Player *_owner, QGraphicsItem *parent, const CardRef &cardRef, int _cardid, CardZone *_zone)
CardItem::CardItem(Player *_owner, QGraphicsItem *parent, const CardRef &cardRef, int _cardid, CardZoneLogic *_zone)
: AbstractCardItem(parent, cardRef, _owner, _cardid), zone(_zone), attacking(false), destroyOnZoneChange(false),
doesntUntap(false), dragItem(nullptr), attachedTo(nullptr)
{
@ -34,7 +35,7 @@ void CardItem::prepareDelete()
{
if (owner != nullptr) {
if (owner->getGame()->getActiveCard() == this) {
owner->updateCardMenu(nullptr);
owner->getPlayerMenu()->updateCardMenu(nullptr);
owner->getGame()->setActiveCard(nullptr);
}
owner = nullptr;
@ -59,7 +60,7 @@ void CardItem::deleteLater()
AbstractCardItem::deleteLater();
}
void CardItem::setZone(CardZone *_zone)
void CardItem::setZone(CardZoneLogic *_zone)
{
zone = _zone;
}
@ -184,13 +185,13 @@ void CardItem::setAttachedTo(CardItem *_attachedTo)
gridPoint.setX(-1);
attachedTo = _attachedTo;
if (attachedTo != nullptr) {
setParentItem(attachedTo->getZone());
emit attachedTo->zone->cardAdded(this);
attachedTo->addAttachedCard(this);
if (zone != attachedTo->getZone()) {
attachedTo->getZone()->reorganizeCards();
}
} else {
setParentItem(zone);
emit zone->cardAdded(this);
}
if (zone != nullptr) {
@ -259,10 +260,14 @@ void CardItem::deleteDragItem()
void CardItem::drawArrow(const QColor &arrowColor)
{
if (static_cast<TabGame *>(owner->parent())->getGameState()->isSpectator())
if (static_cast<TabGame *>(owner->parent())->getGame()->getPlayerManager()->isSpectator())
return;
Player *arrowOwner = static_cast<TabGame *>(owner->parent())->getGameState()->getActiveLocalPlayer();
Player *arrowOwner = static_cast<TabGame *>(owner->parent())
->getGame()
->getPlayerManager()
->getActiveLocalPlayer(
static_cast<TabGame *>(owner->parent())->getGame()->getGameState()->getActivePlayer());
ArrowDragItem *arrow = new ArrowDragItem(arrowOwner, this, arrowColor);
scene()->addItem(arrow);
arrow->grabMouse();
@ -282,7 +287,7 @@ void CardItem::drawArrow(const QColor &arrowColor)
void CardItem::drawAttachArrow()
{
if (static_cast<TabGame *>(owner->parent())->getGameState()->isSpectator())
if (static_cast<TabGame *>(owner->parent())->getGame()->getPlayerManager()->isSpectator())
return;
auto *arrow = new ArrowAttachItem(this);
@ -322,10 +327,10 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() <
2 * QApplication::startDragDistance())
return;
if (const ZoneViewZone *view = qobject_cast<const ZoneViewZone *>(zone)) {
if (const ZoneViewZoneLogic *view = qobject_cast<const ZoneViewZoneLogic *>(zone)) {
if (view->getRevealZone() && !view->getWriteableRevealZone())
return;
} else if (!owner->getLocalOrJudge())
} else if (!owner->getPlayerInfo()->getLocalOrJudge())
return;
bool forceFaceDown = event->modifiers().testFlag(Qt::ShiftModifier);
@ -358,17 +363,18 @@ void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void CardItem::playCard(bool faceDown)
{
// Do nothing if the card belongs to another player
if (!owner->getLocalOrJudge())
if (!owner->getPlayerInfo()->getLocalOrJudge())
return;
TableZone *tz = qobject_cast<TableZone *>(zone);
TableZoneLogic *tz = qobject_cast<TableZoneLogic *>(zone);
if (tz)
tz->toggleTapped();
emit tz->toggleTapped();
else {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
faceDown ? zone->getPlayer()->actPlayFacedown() : zone->getPlayer()->actPlay();
faceDown ? zone->getPlayer()->getPlayerActions()->actPlayFacedown()
: zone->getPlayer()->getPlayerActions()->actPlay();
} else {
zone->getPlayer()->playCard(this, faceDown);
zone->getPlayer()->getPlayerActions()->playCard(this, faceDown);
}
}
}
@ -377,9 +383,9 @@ void CardItem::playCard(bool faceDown)
* @brief returns true if the zone is a unwritable reveal zone view (eg a card reveal window). Will return false if zone
* is nullptr.
*/
static bool isUnwritableRevealZone(CardZone *zone)
static bool isUnwritableRevealZone(CardZoneLogic *zone)
{
if (auto *view = qobject_cast<ZoneViewZone *>(zone)) {
if (auto *view = qobject_cast<ZoneViewZoneLogic *>(zone)) {
return view->getRevealZone() && !view->getWriteableRevealZone();
}
return false;
@ -395,7 +401,7 @@ void CardItem::handleClickedToPlay(bool shiftHeld)
{
if (isUnwritableRevealZone(zone)) {
if (SettingsCache::instance().getClickPlaysAllSelected()) {
zone->getPlayer()->actHide();
zone->getPlayer()->getPlayerActions()->actHide();
} else {
zone->removeCard(this);
}
@ -410,7 +416,7 @@ void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
if (owner != nullptr) {
owner->getGame()->setActiveCard(this);
if (QMenu *cardMenu = owner->updateCardMenu(this)) {
if (QMenu *cardMenu = owner->getPlayerMenu()->updateCardMenu(this)) {
cardMenu->popup(event->screenPos());
return;
}
@ -467,10 +473,11 @@ QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value)
if ((change == ItemSelectedHasChanged) && owner != nullptr) {
if (value == true) {
owner->getGame()->setActiveCard(this);
owner->updateCardMenu(this);
} else if (owner->scene()->selectedItems().isEmpty()) {
owner->getPlayerMenu()->updateCardMenu(this);
} else if (owner->getGameScene()->selectedItems().isEmpty()) {
owner->getGame()->setActiveCard(nullptr);
owner->updateCardMenu(nullptr);
owner->getPlayerMenu()->updateCardMenu(nullptr);
}
}
return AbstractCardItem::itemChange(change, value);