bool EditorApplication::loadProject(const QString& projectFilePath) { DataProxy projectConfig; if(!mProjectManager->loadProject(projectFilePath, projectConfig)) { return false; } QFileInfo projectFileInfo(projectFilePath); QString gameConfig(projectConfig.get("configPath", "gameConfig.json").c_str()); QString resourcePath(projectFileInfo.absolutePath().append(QDir::separator()).append("resources")); mConfigOverride.put("render", mConfig.get<DataProxy>("render", DataProxy())); initEngine("renderWindow", gameConfig, resourcePath); return true; }
void AtlantikNetwork::processNode(QDomNode n) { QDomAttr a; for ( ; !n.isNull() ; n = n.nextSibling() ) { QDomElement e = n.toElement(); if(!e.isNull()) { if (e.tagName() == "server") { a = e.attributeNode( QString("version") ); if ( !a.isNull() ) m_serverVersion = a.value(); emit receivedHandshake(); } else if (e.tagName() == "msg") { a = e.attributeNode(QString("type")); if (!a.isNull()) { if (a.value() == "error") emit msgError(e.attributeNode(QString("value")).value()); else if (a.value() == "info") emit msgInfo(e.attributeNode(QString("value")).value()); else if (a.value() == "chat") emit msgChat(e.attributeNode(QString("author")).value(), e.attributeNode(QString("value")).value()); } } else if (e.tagName() == "display") { int estateId = -1; a = e.attributeNode(QString("estateid")); if (!a.isNull()) { estateId = a.value().toInt(); Estate *estate; estate = m_atlanticCore->findEstate(a.value().toInt()); emit displayDetails(e.attributeNode(QString("text")).value(), e.attributeNode(QString("cleartext")).value().toInt(), e.attributeNode(QString("clearbuttons")).value().toInt(), estate); bool hasButtons = false; for( QDomNode nButtons = n.firstChild() ; !nButtons.isNull() ; nButtons = nButtons.nextSibling() ) { QDomElement eButton = nButtons.toElement(); if (!eButton.isNull() && eButton.tagName() == "button") { emit addCommandButton(eButton.attributeNode(QString("command")).value(), eButton.attributeNode(QString("caption")).value(), eButton.attributeNode(QString("enabled")).value().toInt()); hasButtons = true; } } if (!hasButtons) emit addCloseButton(); } } else if (e.tagName() == "client") { a = e.attributeNode(QString("playerid")); if (!a.isNull()) m_playerId = a.value().toInt(); a = e.attributeNode(QString("cookie")); if (!a.isNull()) emit clientCookie(a.value()); } else if (e.tagName() == "configupdate") { int configId = -1; a = e.attributeNode(QString("configid")); if (!a.isNull()) { configId = a.value().toInt(); ConfigOption *configOption; if (!(configOption = m_atlanticCore->findConfigOption(configId))) configOption = m_atlanticCore->newConfigOption( configId ); a = e.attributeNode(QString("name")); if (configOption && !a.isNull()) configOption->setName(a.value()); a = e.attributeNode(QString("description")); if (configOption && !a.isNull()) configOption->setDescription(a.value()); a = e.attributeNode(QString("edit")); if (configOption && !a.isNull()) configOption->setEdit(a.value().toInt()); a = e.attributeNode(QString("value")); if (configOption && !a.isNull()) configOption->setValue(a.value()); if (configOption) configOption->update(); } int gameId = -1; a = e.attributeNode(QString("gameid")); if (!a.isNull()) { gameId = a.value().toInt(); for( QDomNode nOptions = n.firstChild() ; !nOptions.isNull() ; nOptions = nOptions.nextSibling() ) { QDomElement eOption = nOptions.toElement(); if (!eOption.isNull() && eOption.tagName() == "option") emit gameOption(eOption.attributeNode(QString("title")).value(), eOption.attributeNode(QString("type")).value(), eOption.attributeNode(QString("value")).value(), eOption.attributeNode(QString("edit")).value(), eOption.attributeNode(QString("command")).value()); } emit endConfigUpdate(); } } else if (e.tagName() == "deletegame") { a = e.attributeNode(QString("gameid")); if (!a.isNull()) { int gameId = a.value().toInt(); Game *game = m_atlanticCore->findGame(gameId); if (game) m_atlanticCore->removeGame(game); } } else if (e.tagName() == "gameupdate") { int gameId = -1; a = e.attributeNode(QString("gameid")); if (!a.isNull()) { gameId = a.value().toInt(); Player *playerSelf = m_atlanticCore->playerSelf(); if ( playerSelf && playerSelf->game() ) kdDebug() << "gameupdate for " << QString::number(gameId) << " with playerSelf in game " << QString::number(playerSelf->game()->id()) << endl; else kdDebug() << "gameupdate for " << QString::number(gameId) << endl; Game *game = 0; if (gameId == -1) { a = e.attributeNode(QString("gametype")); if ( !a.isNull() && !(game = m_atlanticCore->findGame(a.value())) ) game = m_atlanticCore->newGame(gameId, a.value()); } else if (!(game = m_atlanticCore->findGame(gameId))) game = m_atlanticCore->newGame(gameId); a = e.attributeNode(QString("canbejoined")); if (game && !a.isNull()) game->setCanBeJoined(a.value().toInt()); a = e.attributeNode(QString("description")); if (game && !a.isNull()) game->setDescription(a.value()); a = e.attributeNode(QString("name")); if (game && !a.isNull()) game->setName(a.value()); a = e.attributeNode(QString("players")); if (game && !a.isNull()) game->setPlayers(a.value().toInt()); a = e.attributeNode(QString("master")); if (game && !a.isNull()) { // Ensure setMaster succeeds by creating player if necessary Player *player = m_atlanticCore->findPlayer( a.value().toInt() ); if ( !player ) player = m_atlanticCore->newPlayer( a.value().toInt() ); game->setMaster( player ); } QString status = e.attributeNode(QString("status")).value(); if ( m_serverVersion.left(4) == "0.9." || (playerSelf && playerSelf->game() == game) ) { if (status == "config") emit gameConfig(); else if (status == "init") emit gameInit(); else if (status == "run") emit gameRun(); else if (status == "end") emit gameEnd(); } if (game) game->update(); } } else if (e.tagName() == "deleteplayer") { a = e.attributeNode(QString("playerid")); if (!a.isNull()) { int playerId = a.value().toInt(); Player *player = m_atlanticCore->findPlayer(playerId); if (player) m_atlanticCore->removePlayer(player); } } else if (e.tagName() == "playerupdate") { int playerId = -1; a = e.attributeNode(QString("playerid")); if (!a.isNull()) { playerId = a.value().toInt(); Player *player; if (!(player = m_atlanticCore->findPlayer(playerId))) player = m_atlanticCore->newPlayer( playerId, (m_playerId == playerId) ); // Update player name a = e.attributeNode(QString("name")); if (player && !a.isNull()) player->setName(a.value()); // Update player game a = e.attributeNode(QString("game")); if (player && !a.isNull()) { int gameId = a.value().toInt(); if (gameId == -1) player->setGame( 0 ); else { // Ensure setGame succeeds by creating game if necessary Game *game = m_atlanticCore->findGame(a.value().toInt()); if (!game) game = m_atlanticCore->newGame(a.value().toInt()); // player->setGame( game ); } } // Update player host a = e.attributeNode(QString("host")); if (player && !a.isNull()) player->setHost(a.value()); // Update player image/token a = e.attributeNode(QString("image")); if (player && !a.isNull()) player->setImage(a.value()); // Update player money a = e.attributeNode(QString("money")); if (player && !a.isNull()) player->setMoney(a.value().toInt()); a = e.attributeNode(QString("bankrupt")); if (player && !a.isNull()) player->setBankrupt(a.value().toInt()); a = e.attributeNode(QString("hasdebt")); if (player && !a.isNull()) player->setHasDebt(a.value().toInt()); a = e.attributeNode(QString("hasturn")); if (player && !a.isNull()) player->setHasTurn(a.value().toInt()); // Update whether player can roll a = e.attributeNode(QString("can_roll")); if (player && !a.isNull()) player->setCanRoll(a.value().toInt()); // Update whether player can buy a = e.attributeNode(QString("can_buyestate")); if (player && !a.isNull()) player->setCanBuy(a.value().toInt()); // Update whether player can auction a = e.attributeNode(QString("canauction")); if (player && !a.isNull()) player->setCanAuction(a.value().toInt()); // Update whether player can use a card a = e.attributeNode(QString("canusecard")); if (player && !a.isNull()) player->setCanUseCard(a.value().toInt()); // Update whether player is jailed a = e.attributeNode(QString("jailed")); if (player && !a.isNull()) { player->setInJail(a.value().toInt()); // TODO: emit signal with player ptr so board can setText and display something } // Update player location a = e.attributeNode(QString("location")); if (!a.isNull()) { m_playerLocationMap[player] = a.value().toInt(); bool directMove = false; Estate *estate = m_atlanticCore->findEstate(a.value().toInt()); a = e.attributeNode(QString("directmove")); if (!a.isNull()) directMove = a.value().toInt(); if (player && estate) { if (directMove) player->setLocation(estate); else player->setDestination(estate); } } if (player) player->update(); } } else if (e.tagName() == "estategroupupdate") { a = e.attributeNode(QString("groupid")); if (!a.isNull()) { int groupId = a.value().toInt(); EstateGroup *estateGroup = 0; bool b_newEstateGroup = false; if (!(estateGroup = m_atlanticCore->findEstateGroup(groupId))) { // Create EstateGroup object estateGroup = m_atlanticCore->newEstateGroup(a.value().toInt()); b_newEstateGroup = true; } a = e.attributeNode(QString("name")); if (estateGroup && !a.isNull()) estateGroup->setName(a.value()); // Emit signal so GUI implementations can create view(s) // TODO: port to atlanticcore and create view there if (estateGroup) { if (b_newEstateGroup) emit newEstateGroup(estateGroup); estateGroup->update(); } } } else if (e.tagName() == "estateupdate") { int estateId = -1; a = e.attributeNode(QString("estateid")); if (!a.isNull()) { estateId = a.value().toInt(); Estate *estate = 0; bool b_newEstate = false; // FIXME: allow any estateId, GUI should not use it to determin its geometry if (estateId >= 0 && estateId < 100 && !(estate = m_atlanticCore->findEstate(a.value().toInt()))) { // Create estate object estate = m_atlanticCore->newEstate(estateId); b_newEstate = true; QObject::connect(estate, SIGNAL(estateToggleMortgage(Estate *)), this, SLOT(estateToggleMortgage(Estate *))); QObject::connect(estate, SIGNAL(estateHouseBuy(Estate *)), this, SLOT(estateHouseBuy(Estate *))); QObject::connect(estate, SIGNAL(estateHouseSell(Estate *)), this, SLOT(estateHouseSell(Estate *))); QObject::connect(estate, SIGNAL(newTrade(Player *)), this, SLOT(newTrade(Player *))); // Players without estate should get one Player *player = 0; QPtrList<Player> playerList = m_atlanticCore->players(); for (QPtrListIterator<Player> it(playerList); (player = *it) ; ++it) if (m_playerLocationMap[player] == estate->id()) player->setLocation(estate); } a = e.attributeNode(QString("name")); if (estate && !a.isNull()) estate->setName(a.value()); a = e.attributeNode(QString("color")); if (estate && !a.isNull() && !a.value().isEmpty()) estate->setColor(a.value()); a = e.attributeNode(QString("bgcolor")); if (estate && !a.isNull()) estate->setBgColor(a.value()); a = e.attributeNode(QString("owner")); Player *player = m_atlanticCore->findPlayer(a.value().toInt()); if (estate && !a.isNull()) estate->setOwner(player); a = e.attributeNode(QString("houses")); if (estate && !a.isNull()) estate->setHouses(a.value().toInt()); a = e.attributeNode(QString("mortgaged")); if (estate && !a.isNull()) estate->setIsMortgaged(a.value().toInt()); a = e.attributeNode(QString("group")); if (!a.isNull()) { EstateGroup *estateGroup = m_atlanticCore->findEstateGroup(a.value().toInt()); if (estate) estate->setEstateGroup(estateGroup); } a = e.attributeNode(QString("can_toggle_mortgage")); if (estate && !a.isNull()) estate->setCanToggleMortgage(a.value().toInt()); a = e.attributeNode(QString("can_be_owned")); if (estate && !a.isNull()) estate->setCanBeOwned(a.value().toInt()); a = e.attributeNode(QString("can_buy_houses")); if (estate && !a.isNull()) estate->setCanBuyHouses(a.value().toInt()); a = e.attributeNode(QString("can_sell_houses")); if (estate && !a.isNull()) estate->setCanSellHouses(a.value().toInt()); a = e.attributeNode(QString("price")); if (estate && !a.isNull()) estate->setPrice(a.value().toInt()); a = e.attributeNode(QString("houseprice")); if (estate && !a.isNull()) estate->setHousePrice(a.value().toInt()); a = e.attributeNode(QString("sellhouseprice")); if (estate && !a.isNull()) estate->setHouseSellPrice(a.value().toInt()); a = e.attributeNode(QString("mortgageprice")); if (estate && !a.isNull()) estate->setMortgagePrice(a.value().toInt()); a = e.attributeNode(QString("unmortgageprice")); if (estate && !a.isNull()) estate->setUnmortgagePrice(a.value().toInt()); a = e.attributeNode(QString("money")); if (estate && !a.isNull()) estate->setMoney(a.value().toInt()); // Emit signal so GUI implementations can create view(s) // TODO: port to atlanticcore and create view there if (estate) { if (b_newEstate) emit newEstate(estate); estate->update(); } } }