mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-08 19:13: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)
|
||||
{
|
||||
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 "../board/card_list.h"
|
||||
#include "card_menu_action_type.h"
|
||||
#include "card_move_request.h"
|
||||
#include "libcockatrice/card/card_info.h"
|
||||
#include "move_top_cards_until_options.h"
|
||||
#include "token_info.h"
|
||||
|
|
@ -36,6 +37,7 @@ class Message;
|
|||
}
|
||||
} // namespace google
|
||||
|
||||
class CardZoneLogic;
|
||||
class Command_MoveCard;
|
||||
class PendingCommand;
|
||||
class PlayerLogic;
|
||||
|
|
@ -58,6 +60,17 @@ public:
|
|||
PendingCommand *prepareGameCommand(const ::google::protobuf::Message &cmd);
|
||||
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 stopMoveTopCardsUntil();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue