mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 02:53:25 -08:00
[Refactor] Build Command_MoveCard in game/ instead of the zone views
This commit is contained in:
parent
bb9f38a375
commit
271d40302c
8 changed files with 98 additions and 78 deletions
22
cockatrice/src/game/player/card_move_request.h
Normal file
22
cockatrice/src/game/player/card_move_request.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
* @file card_move_request.h
|
||||||
|
* @ingroup GameLogicActions
|
||||||
|
*/
|
||||||
|
//! \todo Document this file.
|
||||||
|
|
||||||
|
#ifndef COCKATRICE_CARD_MOVE_REQUEST_H
|
||||||
|
#define COCKATRICE_CARD_MOVE_REQUEST_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Describes one card a view wants moved, in logic terms rather than wire terms.
|
||||||
|
*/
|
||||||
|
struct CardMoveRequest
|
||||||
|
{
|
||||||
|
int cardId = -1;
|
||||||
|
bool faceDown = false;
|
||||||
|
QString pt = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // COCKATRICE_CARD_MOVE_REQUEST_H
|
||||||
|
|
@ -1999,6 +1999,42 @@ PendingCommand *PlayerActions::prepareGameCommand(const QList<const ::google::pr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerActions::moveCards(CardZoneLogic *startZone,
|
||||||
|
CardZoneLogic *targetZone,
|
||||||
|
int x,
|
||||||
|
int y,
|
||||||
|
const QList<CardMoveRequest> &cards)
|
||||||
|
{
|
||||||
|
if (!startZone || !targetZone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Command_MoveCard cmd;
|
||||||
|
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
||||||
|
cmd.set_start_zone(startZone->getName().toStdString());
|
||||||
|
cmd.set_target_player_id(targetZone->getPlayer()->getPlayerInfo()->getId());
|
||||||
|
cmd.set_target_zone(targetZone->getName().toStdString());
|
||||||
|
cmd.set_x(x);
|
||||||
|
cmd.set_y(y);
|
||||||
|
|
||||||
|
if (auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(targetZone)) {
|
||||||
|
cmd.set_is_reversed(viewLogic->getIsReversed());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const CardMoveRequest &card : cards) {
|
||||||
|
auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
|
||||||
|
cardToMove->set_card_id(card.cardId);
|
||||||
|
if (card.faceDown) {
|
||||||
|
cardToMove->set_face_down(true);
|
||||||
|
}
|
||||||
|
if (!card.pt.isEmpty()) {
|
||||||
|
cardToMove->set_pt(card.pt.toStdString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerActions::sendGameCommand(const google::protobuf::Message &command)
|
void PlayerActions::sendGameCommand(const google::protobuf::Message &command)
|
||||||
{
|
{
|
||||||
if (player->getPlayerInfo()->getJudge() && !player->getPlayerInfo()->getLocal()) {
|
if (player->getPlayerInfo()->getJudge() && !player->getPlayerInfo()->getLocal()) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "../../game_graphics/board/card_item.h" // IWYU pragma: keep - moc instantiates the metatype for QList<CardItem *>, which Qt 6.4 needs complete
|
#include "../../game_graphics/board/card_item.h" // IWYU pragma: keep - moc instantiates the metatype for QList<CardItem *>, which Qt 6.4 needs complete
|
||||||
#include "../board/card_list.h"
|
#include "../board/card_list.h"
|
||||||
#include "card_menu_action_type.h"
|
#include "card_menu_action_type.h"
|
||||||
|
#include "card_move_request.h"
|
||||||
#include "libcockatrice/card/card_info.h"
|
#include "libcockatrice/card/card_info.h"
|
||||||
#include "move_top_cards_until_options.h"
|
#include "move_top_cards_until_options.h"
|
||||||
#include "token_info.h"
|
#include "token_info.h"
|
||||||
|
|
@ -36,6 +37,7 @@ class Message;
|
||||||
}
|
}
|
||||||
} // namespace google
|
} // namespace google
|
||||||
|
|
||||||
|
class CardZoneLogic;
|
||||||
class Command_MoveCard;
|
class Command_MoveCard;
|
||||||
class PendingCommand;
|
class PendingCommand;
|
||||||
class PlayerLogic;
|
class PlayerLogic;
|
||||||
|
|
@ -58,6 +60,17 @@ public:
|
||||||
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
||||||
PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
|
PendingCommand *prepareGameCommand(const QList<const ::google::protobuf::Message *> &cmdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Moves the requested cards between zones on behalf of a view.
|
||||||
|
* @param startZone Zone the cards are dragged out of.
|
||||||
|
* @param targetZone Zone the cards are dropped onto.
|
||||||
|
* @param x Horizontal target index within the zone.
|
||||||
|
* @param y Vertical target index within the zone.
|
||||||
|
* @param cards The cards to move, as chosen by the view.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
moveCards(CardZoneLogic *startZone, CardZoneLogic *targetZone, int x, int y, const QList<CardMoveRequest> &cards);
|
||||||
|
|
||||||
void moveOneCardUntil(CardItem *card);
|
void moveOneCardUntil(CardItem *card);
|
||||||
void stopMoveTopCardsUntil();
|
void stopMoveTopCardsUntil();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
#include <QPointF>
|
#include <QPointF>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
|
||||||
#include <libcockatrice/settings/interface_settings.h>
|
#include <libcockatrice/settings/interface_settings.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -58,19 +57,13 @@ void HandZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||||
x = calcDropIndexFromY(dropPoint.y(), !sameZone);
|
x = calcDropIndexFromY(dropPoint.y(), !sameZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_MoveCard cmd;
|
QList<CardMoveRequest> cards;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
cards.reserve(dragItems.size());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
for (const CardDragItem *item : dragItems) {
|
||||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
cards.append(CardMoveRequest{item->getId()});
|
||||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
|
||||||
cmd.set_x(x);
|
|
||||||
cmd.set_y(-1);
|
|
||||||
|
|
||||||
for (int i = 0; i < dragItems.size(); ++i) {
|
|
||||||
cmd.mutable_cards_to_move()->add_card()->set_card_id(dragItems[i]->getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
getLogic()->getPlayer()->getPlayerActions()->moveCards(startZone, getLogic(), x, -1, cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF HandZone::boundingRect() const
|
QRectF HandZone::boundingRect() const
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QTransform>
|
#include <QTransform>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
|
||||||
#include <libcockatrice/settings/cards_display_settings.h>
|
#include <libcockatrice/settings/cards_display_settings.h>
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
@ -80,23 +79,13 @@ void PileZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*optio
|
||||||
|
|
||||||
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &)
|
void PileZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZoneLogic *startZone, const QPoint &)
|
||||||
{
|
{
|
||||||
Command_MoveCard cmd;
|
QList<CardMoveRequest> cards;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
cards.reserve(dragItems.size());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
for (const CardDragItem *item : dragItems) {
|
||||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
cards.append(CardMoveRequest{item->getId(), item->isForceFaceDown()});
|
||||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
|
||||||
cmd.set_x(0);
|
|
||||||
cmd.set_y(0);
|
|
||||||
|
|
||||||
for (int i = 0; i < dragItems.size(); ++i) {
|
|
||||||
auto cardToMove = cmd.mutable_cards_to_move()->add_card();
|
|
||||||
cardToMove->set_card_id(dragItems[i]->getId());
|
|
||||||
if (dragItems[i]->isForceFaceDown()) {
|
|
||||||
cardToMove->set_face_down(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
getLogic()->getPlayer()->getPlayerActions()->moveCards(startZone, getLogic(), 0, 0, cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PileZone::reorganizeCards()
|
void PileZone::reorganizeCards()
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QRectF>
|
#include <QRectF>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
|
||||||
#include <qnumeric.h>
|
#include <qnumeric.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|
@ -79,25 +78,15 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_MoveCard cmd;
|
QList<CardMoveRequest> cards;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
cards.reserve(dragItems.size());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
|
||||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
|
||||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
|
||||||
cmd.set_x(index);
|
|
||||||
cmd.set_y(0);
|
|
||||||
|
|
||||||
for (const CardDragItem *item : dragItems) {
|
for (const CardDragItem *item : dragItems) {
|
||||||
if (item) {
|
if (item) {
|
||||||
auto *cardToMove = cmd.mutable_cards_to_move()->add_card();
|
cards.append(CardMoveRequest{item->getId(), item->isForceFaceDown()});
|
||||||
cardToMove->set_card_id(item->getId());
|
|
||||||
if (item->isForceFaceDown()) {
|
|
||||||
cardToMove->set_face_down(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
getLogic()->getPlayer()->getPlayerActions()->moveCards(startZone, getLogic(), index, 0, cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackZone::setHeight(qreal newHeight)
|
void StackZone::setHeight(qreal newHeight)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#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_set_card_attr.pb.h>
|
#include <libcockatrice/protocol/pb/command_set_card_attr.pb.h>
|
||||||
#include <libcockatrice/settings/interface_settings.h>
|
#include <libcockatrice/settings/interface_settings.h>
|
||||||
#include <libcockatrice/utility/zone_names.h>
|
#include <libcockatrice/utility/zone_names.h>
|
||||||
|
|
@ -209,29 +208,20 @@ void TableZone::handleDropEventByGrid(const QList<CardDragItem *> &dragItems,
|
||||||
CardZoneLogic *startZone,
|
CardZoneLogic *startZone,
|
||||||
const QPoint &gridPoint)
|
const QPoint &gridPoint)
|
||||||
{
|
{
|
||||||
Command_MoveCard cmd;
|
QList<CardMoveRequest> cards;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
cards.reserve(dragItems.size());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
for (const CardDragItem *item : dragItems) {
|
||||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
CardMoveRequest card{item->getId(), item->isForceFaceDown()};
|
||||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
|
||||||
cmd.set_x(gridPoint.x());
|
|
||||||
cmd.set_y(gridPoint.y());
|
|
||||||
|
|
||||||
for (const auto &item : dragItems) {
|
|
||||||
CardToMove *ctm = cmd.mutable_cards_to_move()->add_card();
|
|
||||||
ctm->set_card_id(item->getId());
|
|
||||||
if (item->isForceFaceDown()) {
|
|
||||||
ctm->set_face_down(true);
|
|
||||||
}
|
|
||||||
if (startZone->getName() != getLogic()->getName() && !item->isForceFaceDown()) {
|
if (startZone->getName() != getLogic()->getName() && !item->isForceFaceDown()) {
|
||||||
const auto &card = item->getItem()->getCard();
|
const auto &cardInfo = item->getItem()->getCard();
|
||||||
if (card) {
|
if (cardInfo) {
|
||||||
ctm->set_pt(card.getInfo().getPowTough().toStdString());
|
card.pt = cardInfo.getInfo().getPowTough();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cards.append(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
startZone->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
startZone->getPlayer()->getPlayerActions()->moveCards(startZone, getLogic(), gridPoint.x(), gridPoint.y(), cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableZone::reorganizeCards()
|
void TableZone::reorganizeCards()
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <libcockatrice/card/card_localization.h>
|
#include <libcockatrice/card/card_localization.h>
|
||||||
#include <libcockatrice/protocol/pb/command_dump_zone.pb.h>
|
#include <libcockatrice/protocol/pb/command_dump_zone.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
|
|
||||||
#include <libcockatrice/protocol/pb/response_dump_zone.pb.h>
|
#include <libcockatrice/protocol/pb/response_dump_zone.pb.h>
|
||||||
#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
|
#include <libcockatrice/protocol/pb/serverinfo_card.pb.h>
|
||||||
#include <libcockatrice/protocol/pending_command.h>
|
#include <libcockatrice/protocol/pending_command.h>
|
||||||
|
|
@ -301,24 +300,13 @@ void ZoneViewZone::handleDropEvent(const QList<CardDragItem *> &dragItems,
|
||||||
CardZoneLogic *startZone,
|
CardZoneLogic *startZone,
|
||||||
const QPoint & /*dropPoint*/)
|
const QPoint & /*dropPoint*/)
|
||||||
{
|
{
|
||||||
Command_MoveCard cmd;
|
QList<CardMoveRequest> cards;
|
||||||
cmd.set_start_player_id(startZone->getPlayer()->getPlayerInfo()->getId());
|
cards.reserve(dragItems.size());
|
||||||
cmd.set_start_zone(startZone->getName().toStdString());
|
|
||||||
cmd.set_target_player_id(getLogic()->getPlayer()->getPlayerInfo()->getId());
|
|
||||||
cmd.set_target_zone(getLogic()->getName().toStdString());
|
|
||||||
cmd.set_x(0);
|
|
||||||
cmd.set_y(0);
|
|
||||||
cmd.set_is_reversed(qobject_cast<ZoneViewZoneLogic *>(getLogic())->getIsReversed());
|
|
||||||
|
|
||||||
for (int i = 0; i < dragItems.size(); ++i) {
|
for (int i = 0; i < dragItems.size(); ++i) {
|
||||||
auto cardToMove = cmd.mutable_cards_to_move()->add_card();
|
cards.append(CardMoveRequest{dragItems[i]->getId(), dragItems[i]->isForceFaceDown()});
|
||||||
cardToMove->set_card_id(dragItems[i]->getId());
|
|
||||||
if (dragItems[i]->isForceFaceDown()) {
|
|
||||||
cardToMove->set_face_down(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogic()->getPlayer()->getPlayerActions()->sendGameCommand(cmd);
|
getLogic()->getPlayer()->getPlayerActions()->moveCards(startZone, getLogic(), 0, 0, cards);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewZone::setGeometry(const QRectF &rect)
|
void ZoneViewZone::setGeometry(const QRectF &rect)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue