From ef14d5e9d6a5526691b300170eee5e8ae76a96f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Tue, 23 Oct 2012 23:58:31 +0200 Subject: [PATCH] Saved games: use camelCase for attribute names --- game/xml_reader.cpp | 20 ++++++++++++-------- game/xml_writer.cpp | 12 ++++++------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/game/xml_reader.cpp b/game/xml_reader.cpp index c6310f4..0ea0012 100644 --- a/game/xml_reader.cpp +++ b/game/xml_reader.cpp @@ -120,7 +120,7 @@ static int toInt(const string &str) static Player & getPlayer(map &players, const string &id) { if (players.find(id) == players.end()) - throw LoadGameException(FMT1(_("Invalid player ID: %1%"), id)); + throw LoadGameException(FMT1(_("Invalid player ID: %1%"), "-" + id + "-")); return *players[id]; } @@ -226,6 +226,10 @@ void XmlReader::startElement(const string& namespaceURI, else m_game->accessNavigation().newTurn(); } + // For backwards compatibility ("playerid" was used in saved games + // before release 2.1, with XML version 2) + if (m_attributes["playerid"] != "") + m_attributes["playerId"] = m_attributes["playerid"]; } @@ -373,7 +377,7 @@ void XmlReader::endElement(const string& namespaceURI, pldrack.setManual(rackStr); LOG_DEBUG("loaded rack: " << lfw(pldrack.toString())); - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); PlayerRackCmd *cmd = new PlayerRackCmd(p, pldrack); m_game->accessNavigation().addAndExecute(cmd); LOG_DEBUG("rack: " << lfw(pldrack.toString())); @@ -394,7 +398,7 @@ void XmlReader::endElement(const string& namespaceURI, else if (tag == "PlayerMove") { const Move &move = buildMove(*m_game, m_attributes, /*XXX:true*/false); - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); PlayerMoveCmd *cmd = new PlayerMoveCmd(p, move); m_game->accessNavigation().addAndExecute(cmd); } @@ -402,21 +406,21 @@ void XmlReader::endElement(const string& namespaceURI, else if (tag == "GameMove") { const Move &move = buildMove(*m_game, m_attributes, false); - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); GameMoveCmd *cmd = new GameMoveCmd(*m_game, move, p.getId()); m_game->accessNavigation().addAndExecute(cmd); } else if (tag == "Warning") { - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::WARNING); m_game->accessNavigation().addAndExecute(cmd); } else if (tag == "Penalty") { - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); int points = toInt(m_attributes["points"]); LOG_ERROR("points=" << points); PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::PENALTY, points); @@ -425,7 +429,7 @@ void XmlReader::endElement(const string& namespaceURI, else if (tag == "Solo") { - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); int points = toInt(m_attributes["points"]); PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::SOLO, points); m_game->accessNavigation().addAndExecute(cmd); @@ -433,7 +437,7 @@ void XmlReader::endElement(const string& namespaceURI, else if (tag == "EndGame") { - Player &p = getPlayer(m_players, m_attributes["playerid"]); + Player &p = getPlayer(m_players, m_attributes["playerId"]); int points = toInt(m_attributes["points"]); PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::END_GAME, points); m_game->accessNavigation().addAndExecute(cmd); diff --git a/game/xml_writer.cpp b/game/xml_writer.cpp index 31bc1d5..ead1bf3 100644 --- a/game/xml_writer.cpp +++ b/game/xml_writer.cpp @@ -84,7 +84,7 @@ static void writeMove(ostream &out, const Move &iMove, { out << "<" << iTag; if (iPlayerId != -1) - out << " playerid=\"" << iPlayerId << "\""; + out << " playerId=\"" << iPlayerId << "\""; out << " points=\"" << iMove.getScore() << "\" type=\""; if (iMove.isValid()) { @@ -231,7 +231,7 @@ void XmlWriter::write(const Game &iGame, const string &iFileName) { const PlayerRackCmd *rackCmd = static_cast(cmd); unsigned int id = rackCmd->getPlayer().getId() + 1; - out << indent << "" + out << indent << "" << toUtf8(rackCmd->getRack().toString()) << "" << endl; } @@ -267,24 +267,24 @@ void XmlWriter::write(const Game &iGame, const string &iFileName) // Warnings if (eventCmd->getEventType() == PlayerEventCmd::WARNING) { - out << indent << "" << endl; + out << indent << "" << endl; } // Penalties else if (eventCmd->getEventType() == PlayerEventCmd::PENALTY) { - out << indent << "" << endl; } // Solos else if (eventCmd->getEventType() == PlayerEventCmd::SOLO) { - out << indent << "" << endl; } // End game bonuses (freegame mode) else if (eventCmd->getEventType() == PlayerEventCmd::END_GAME) { - out << indent << "" << endl; } else