mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 01:23:24 -08:00
[Game] Connect zone dump response before sending the request (#7711)
ZoneViewZone::initializeCards() connected PendingCommand::finished only after ZoneViewZoneLogic::requestZoneDump() had already sent the command. Local games process the dump synchronously, so finished was emitted before the view connected and the library/sideboard view stayed empty. Split requestZoneDump() into prepareZoneDump() and sendZoneDump(), and connect before sending, matching the TabRoom prepare/send convention. Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
00151380e3
commit
ff393b8990
3 changed files with 25 additions and 12 deletions
|
|
@ -99,9 +99,13 @@ void ZoneViewZone::initializeCards(const QList<const ServerInfo_Card *> &cardLis
|
|||
}
|
||||
reorganizeCards();
|
||||
} else if (!qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->contentsKnown()) {
|
||||
PendingCommand *pend = qobject_cast<ZoneViewZoneLogic *>(getLogic())->requestZoneDump();
|
||||
auto *viewLogic = qobject_cast<ZoneViewZoneLogic *>(getLogic());
|
||||
PendingCommand *pend = viewLogic->prepareZoneDump();
|
||||
if (pend != nullptr) {
|
||||
// A local game answers synchronously, so the handler has to be connected before the
|
||||
// command is sent or the response would be delivered to nobody.
|
||||
connect(pend, &PendingCommand::finished, this, &ZoneViewZone::zoneDumpReceived);
|
||||
viewLogic->sendZoneDump(pend);
|
||||
}
|
||||
} else {
|
||||
const CardList &c = qobject_cast<ZoneViewZoneLogic *>(getLogic())->getOriginalZone()->getCards();
|
||||
|
|
|
|||
|
|
@ -192,12 +192,14 @@ void ZoneViewZoneLogic::setWriteableRevealZone(bool _writeableRevealZone)
|
|||
writeableRevealZone = _writeableRevealZone;
|
||||
}
|
||||
|
||||
PendingCommand *ZoneViewZoneLogic::requestZoneDump()
|
||||
PendingCommand *ZoneViewZoneLogic::prepareZoneDump()
|
||||
{
|
||||
PlayerActions *actions = getPlayer()->getPlayerActions();
|
||||
PendingCommand *pend = actions->prepareZoneDump(this, numberCards);
|
||||
if (pend != nullptr) {
|
||||
actions->sendGameCommand(pend);
|
||||
return getPlayer()->getPlayerActions()->prepareZoneDump(this, numberCards);
|
||||
}
|
||||
|
||||
void ZoneViewZoneLogic::sendZoneDump(PendingCommand *pendingCommand)
|
||||
{
|
||||
if (pendingCommand != nullptr) {
|
||||
getPlayer()->getPlayerActions()->sendGameCommand(pendingCommand);
|
||||
}
|
||||
return pend;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,14 +88,21 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares and sends the zone-dump command for this view.
|
||||
* @brief Builds the zone-dump command for this view without sending it.
|
||||
* @return The pending command, or nullptr when there is no zone to dump.
|
||||
*
|
||||
* Keeps command construction in game/ so graphics views don't reach
|
||||
* through the player into PlayerActions to set it up. The command is sent
|
||||
* asynchronously, so callers connect to finished() after calling this.
|
||||
* through the player into PlayerActions to set it up. The response can
|
||||
* arrive synchronously (local games), so callers must connect to
|
||||
* PendingCommand::finished before calling sendZoneDump().
|
||||
*/
|
||||
PendingCommand *requestZoneDump();
|
||||
PendingCommand *prepareZoneDump();
|
||||
|
||||
/**
|
||||
* @brief Sends a command returned by prepareZoneDump().
|
||||
* @param pendingCommand The prepared command; nullptr is ignored.
|
||||
*/
|
||||
void sendZoneDump(PendingCommand *pendingCommand);
|
||||
|
||||
protected:
|
||||
void addCardImpl(CardState *card, int x, int y) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue