// --- QGAMES::Board* QGAMES::BasicBoardAddsOn::createBoard (const QGAMES::BoardBuilder::BoardDefinition& def, const std::string& bP) { TiXmlDocument doc (def._fileDefinition.c_str ()); int e = doc.LoadFile (); assert (e); // Is it a valid doc? TiXmlElement* rootElement = doc.RootElement (); assert (rootElement); // One element minimum... // Read all parts of the file defining the QGAMES::BoardResources resources; QGAMES::BoardSquares squares; std::list <QGAMES::BasicBoardAddsOn::SquareConnectionDefinition> connections; for (TiXmlElement* groupElement = rootElement -> FirstChildElement (); groupElement != NULL; groupElement = groupElement -> NextSiblingElement ()) { if (strcmp (groupElement -> Value (), __QGAMES_BOARDRESOURCESTAG__) == 0) resources = createBoardResources (readResources (groupElement)); if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARESTAG__) == 0) squares = createBoardSquares (readSquares (groupElement)); if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARECONNECTIONSTAG__) == 0) connections = readConnections (groupElement); } // Once everything has been read, the instance is created... // and then the squares connected. QGAMES::Board* result = createBoardInstance (def._id, squares, resources); setConnections (squares, connections); return (result); // The result is returned! }
json::Array ConnectionHistory::connectionsAsJson() { json::Array connectionsJson; Error error = readConnections(&connectionsJson); if (error) LOG_ERROR(error); return connectionsJson; }
void ConnectionHistory::remove(const ConnectionId &id) { // read existing connections json::Array connectionsJson; Error error = readConnections(&connectionsJson); if (error) { LOG_ERROR(error); return; } // remove matching connection connectionsJson.erase(std::remove_if(connectionsJson.begin(), connectionsJson.end(), boost::bind(isConnection, id, _1)), connectionsJson.end()); // write out the connections error = writeConnections(connectionsJson); if (error) LOG_ERROR(error); }
void ConnectionHistory::update(const Connection& connection) { // read existing connections json::Array connectionsJson; Error error = readConnections(&connectionsJson); if (error) { LOG_ERROR(error); return; } // look for a matching connection and update it bool foundConnection = false; for (size_t i = 0; i<connectionsJson.size(); i++) { json::Value valueJson = connectionsJson[i]; if (isConnection(connection.id, valueJson)) { connectionsJson[i] = connectionJson(connection); foundConnection = true; break; } } // if we didn't find a connection then append if (!foundConnection) connectionsJson.push_back(connectionJson(connection)); // write out the connections error = writeConnections(connectionsJson); if (error) LOG_ERROR(error); // fire event onConnectionsChanged(); }