Preserve the editable face-up token preview when creating face down

Consolidate #7737 on current master and address maintainer review 4439182056. Keep the visible token draft independent of outgoing face-down color and P/T normalization; remove unused control object names requested in 4438752178. Retain the original submission as a parent.

Native Cockatrice/game target build and three focused token command tests pass. Actual offscreen dialog receiving verifies draft toggles, selected token, filtering and typed alias/default P/T.
This commit is contained in:
Bryce! 2026-11-03 20:09:57 -05:00
commit 866743d4e1
7 changed files with 234 additions and 29 deletions

View file

@ -4,6 +4,7 @@
#include <QString>
#include <libcockatrice/game/player/player_actions.h>
#include <libcockatrice/game/zones/table_zone_logic.h>
#include <libcockatrice/protocol/pb/command_create_token.pb.h>
#include <libcockatrice/protocol/pb/command_move_card.pb.h>
#include <libcockatrice/utility/zone_names.h>
#include <string>
@ -117,3 +118,64 @@ TEST(PlayerActionsTest, PlayCiptCreatureSendsTapped)
EXPECT_TRUE(card.has_tapped());
EXPECT_TRUE(card.tapped());
}
// These three #7737 command cases use the current shared game harness.
TEST(TokenCommandTest, FaceDownKnownTokenDoesNotRestoreDatabasePowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("Kitten");
token.color = QString(QChar());
token.faceDown = true;
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_EQ(command.card_name(), "Kitten");
EXPECT_TRUE(command.face_down());
EXPECT_TRUE(command.pt().empty());
harness.player()->getPlayerActions()->actCreateAnotherToken();
ASSERT_EQ(harness.client()->sent.size(), 2);
const auto &repeat = harness.lastCommand().game_command(0).GetExtension(Command_CreateToken::ext);
EXPECT_TRUE(repeat.face_down());
EXPECT_TRUE(repeat.pt().empty());
}
TEST(TokenCommandTest, FaceUpKnownAliasKeepsCanonicalNameAndDefaultPowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("kitten");
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_EQ(command.card_name(), "Kitten");
EXPECT_FALSE(command.face_down());
EXPECT_EQ(command.pt(), "1/1");
}
TEST(TokenCommandTest, FaceUpKnownTokenPreservesExplicitPowerToughness)
{
GameHarness harness;
harness.client()->sent.clear();
TokenInfo token;
token.name = QStringLiteral("Kitten");
token.pt = QStringLiteral("7/9");
token.annotation = QStringLiteral("Flying");
harness.player()->getPlayerActions()->actCreateToken(token);
ASSERT_EQ(harness.client()->sent.size(), 1);
ASSERT_EQ(harness.lastCommand().game_command_size(), 1);
const auto &gameCommand = harness.lastCommand().game_command(0);
ASSERT_TRUE(gameCommand.HasExtension(Command_CreateToken::ext));
const auto &command = gameCommand.GetExtension(Command_CreateToken::ext);
EXPECT_FALSE(command.face_down());
EXPECT_EQ(command.pt(), "7/9");
EXPECT_EQ(command.annotation(), "Flying");
}