Saved games: use camelCase for attribute names

This commit is contained in:
Olivier Teulière 2012-10-23 23:58:31 +02:00
parent b76f48f545
commit ef14d5e9d6
2 changed files with 18 additions and 14 deletions

View file

@ -120,7 +120,7 @@ static int toInt(const string &str)
static Player & getPlayer(map<string, Player*> &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);

View file

@ -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<const PlayerRackCmd*>(cmd);
unsigned int id = rackCmd->getPlayer().getId() + 1;
out << indent << "<PlayerRack playerid=\"" << id << "\">"
out << indent << "<PlayerRack playerId=\"" << id << "\">"
<< toUtf8(rackCmd->getRack().toString())
<< "</PlayerRack>" << endl;
}
@ -267,24 +267,24 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
// Warnings
if (eventCmd->getEventType() == PlayerEventCmd::WARNING)
{
out << indent << "<Warning playerid=\"" << id << "\" />" << endl;
out << indent << "<Warning playerId=\"" << id << "\" />" << endl;
}
// Penalties
else if (eventCmd->getEventType() == PlayerEventCmd::PENALTY)
{
out << indent << "<Penalty playerid=\"" << id
out << indent << "<Penalty playerId=\"" << id
<< "\" points=\"" << value << "\" />" << endl;
}
// Solos
else if (eventCmd->getEventType() == PlayerEventCmd::SOLO)
{
out << indent << "<Solo playerid=\"" << id
out << indent << "<Solo playerId=\"" << id
<< "\" points=\"" << value << "\" />" << endl;
}
// End game bonuses (freegame mode)
else if (eventCmd->getEventType() == PlayerEventCmd::END_GAME)
{
out << indent << "<EndGame playerid=\"" << id
out << indent << "<EndGame playerId=\"" << id
<< "\" points=\"" << value << "\" />" << endl;
}
else