mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Process local player first.
Took 45 minutes
This commit is contained in:
parent
98da0a066f
commit
18fdf94fb2
2 changed files with 47 additions and 34 deletions
|
|
@ -566,7 +566,7 @@ void TabGame::actCompleterChanged()
|
||||||
|
|
||||||
Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info)
|
Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info)
|
||||||
{
|
{
|
||||||
bool local = ((clients.size() > 1) || (playerId == localPlayerId));
|
bool local = clients.size() > 1 || playerId == localPlayerId;
|
||||||
auto *newPlayer = new Player(info, playerId, local, judge, this);
|
auto *newPlayer = new Player(info, playerId, local, judge, this);
|
||||||
connect(newPlayer, SIGNAL(openDeckEditor(const DeckLoader *)), this, SIGNAL(openDeckEditor(const DeckLoader *)));
|
connect(newPlayer, SIGNAL(openDeckEditor(const DeckLoader *)), this, SIGNAL(openDeckEditor(const DeckLoader *)));
|
||||||
QString newPlayerName = "@" + newPlayer->getName();
|
QString newPlayerName = "@" + newPlayer->getName();
|
||||||
|
|
@ -850,6 +850,44 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event,
|
||||||
const GameEventContext & /*context*/)
|
const GameEventContext & /*context*/)
|
||||||
{
|
{
|
||||||
const int playerListSize = event.player_list_size();
|
const int playerListSize = event.player_list_size();
|
||||||
|
|
||||||
|
// Always process the local player first so we have an established deckViewcontainer
|
||||||
|
|
||||||
|
for (int i = 0; i < playerListSize; ++i) {
|
||||||
|
const ServerInfo_Player &playerInfo = event.player_list(i);
|
||||||
|
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||||
|
const int playerId = prop.player_id();
|
||||||
|
QString playerName = "@" + QString::fromStdString(prop.user_info().name());
|
||||||
|
if (sayEdit && !autocompleteUserList.contains(playerName)) {
|
||||||
|
autocompleteUserList << playerName;
|
||||||
|
sayEdit->setCompletionList(autocompleteUserList);
|
||||||
|
}
|
||||||
|
if (!prop.spectator()) {
|
||||||
|
Player *player = players.value(playerId, 0);
|
||||||
|
if (!player) {
|
||||||
|
if (clients.size() > 1 || playerId == localPlayerId) {
|
||||||
|
player = addPlayer(playerId, prop.user_info());
|
||||||
|
playerListWidget->addPlayer(prop);
|
||||||
|
player->processPlayerInfo(playerInfo);
|
||||||
|
if (player->getLocal()) {
|
||||||
|
TabbedDeckViewContainer *deckViewContainer = deckViewContainers.value(playerId);
|
||||||
|
if (playerInfo.has_deck_list()) {
|
||||||
|
DeckLoader newDeck(QString::fromStdString(playerInfo.deck_list()));
|
||||||
|
PictureLoader::cacheCardPixmaps(
|
||||||
|
CardDatabaseManager::getInstance()->getCards(newDeck.getCardRefList()));
|
||||||
|
deckViewContainer->playerDeckView->setDeck(newDeck);
|
||||||
|
player->setDeck(newDeck);
|
||||||
|
}
|
||||||
|
deckViewContainer->playerDeckView->setReadyStart(prop.ready_start());
|
||||||
|
deckViewContainer->playerDeckView->setSideboardLocked(prop.sideboard_locked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// then process every non-local player.
|
||||||
|
|
||||||
for (int i = 0; i < playerListSize; ++i) {
|
for (int i = 0; i < playerListSize; ++i) {
|
||||||
const ServerInfo_Player &playerInfo = event.player_list(i);
|
const ServerInfo_Player &playerInfo = event.player_list(i);
|
||||||
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||||
|
|
@ -872,17 +910,8 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event,
|
||||||
}
|
}
|
||||||
player->processPlayerInfo(playerInfo);
|
player->processPlayerInfo(playerInfo);
|
||||||
if (player->getLocal()) {
|
if (player->getLocal()) {
|
||||||
TabbedDeckViewContainer *deckViewContainer = deckViewContainers.value(playerId);
|
continue;
|
||||||
if (playerInfo.has_deck_list()) {
|
|
||||||
DeckLoader newDeck(QString::fromStdString(playerInfo.deck_list()));
|
|
||||||
PictureLoader::cacheCardPixmaps(
|
|
||||||
CardDatabaseManager::getInstance()->getCards(newDeck.getCardRefList()));
|
|
||||||
deckViewContainer->playerDeckView->setDeck(newDeck);
|
|
||||||
player->setDeck(newDeck);
|
|
||||||
}
|
}
|
||||||
deckViewContainer->playerDeckView->setReadyStart(prop.ready_start());
|
|
||||||
deckViewContainer->playerDeckView->setSideboardLocked(prop.sideboard_locked());
|
|
||||||
} else {
|
|
||||||
DeckList loader;
|
DeckList loader;
|
||||||
loader.loadFromString_Native(QString::fromStdString(playerInfo.deck_list()));
|
loader.loadFromString_Native(QString::fromStdString(playerInfo.deck_list()));
|
||||||
QMapIterator<int, TabbedDeckViewContainer *> i(deckViewContainers);
|
QMapIterator<int, TabbedDeckViewContainer *> i(deckViewContainers);
|
||||||
|
|
@ -892,7 +921,6 @@ void TabGame::eventGameStateChanged(const Event_GameStateChanged &event,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (int i = 0; i < playerListSize; ++i) {
|
for (int i = 0; i < playerListSize; ++i) {
|
||||||
const ServerInfo_Player &playerInfo = event.player_list(i);
|
const ServerInfo_Player &playerInfo = event.player_list(i);
|
||||||
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
const ServerInfo_PlayerProperties &prop = playerInfo.properties();
|
||||||
|
|
|
||||||
|
|
@ -513,21 +513,6 @@ void Server_Game::addPlayer(Server_AbstractUserInterface *userInterface,
|
||||||
userInterface->playerAddedToGame(gameId, room->getId(), newPlayer->getPlayerId());
|
userInterface->playerAddedToGame(gameId, room->getId(), newPlayer->getPlayerId());
|
||||||
|
|
||||||
createGameJoinedEvent(newPlayer, rc, false);
|
createGameJoinedEvent(newPlayer, rc, false);
|
||||||
|
|
||||||
Event_PlayerPropertiesChanged event;
|
|
||||||
GameEventStorage ges;
|
|
||||||
|
|
||||||
if (getShareDecklistsOnLoad()) {
|
|
||||||
for (const auto &player : players) {
|
|
||||||
Context_DeckSelect context;
|
|
||||||
if (player->getDeckList() != nullptr) {
|
|
||||||
context.set_deck_list(player->getDeckList()->writeToString_Native().toStdString());
|
|
||||||
ges.setGameEventContext(context);
|
|
||||||
ges.enqueueGameEvent(event, player->getPlayerId());
|
|
||||||
ges.sendToGame(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Game::removePlayer(Server_Player *player, Event_Leave::LeaveReason reason)
|
void Server_Game::removePlayer(Server_Player *player, Event_Leave::LeaveReason reason)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue