mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-30 20:34:27 +01:00
Saved games: use camelCase for attribute names
This commit is contained in:
parent
b76f48f545
commit
ef14d5e9d6
2 changed files with 18 additions and 14 deletions
|
@ -120,7 +120,7 @@ static int toInt(const string &str)
|
||||||
static Player & getPlayer(map<string, Player*> &players, const string &id)
|
static Player & getPlayer(map<string, Player*> &players, const string &id)
|
||||||
{
|
{
|
||||||
if (players.find(id) == players.end())
|
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];
|
return *players[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +226,10 @@ void XmlReader::startElement(const string& namespaceURI,
|
||||||
else
|
else
|
||||||
m_game->accessNavigation().newTurn();
|
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);
|
pldrack.setManual(rackStr);
|
||||||
LOG_DEBUG("loaded rack: " << lfw(pldrack.toString()));
|
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);
|
PlayerRackCmd *cmd = new PlayerRackCmd(p, pldrack);
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
LOG_DEBUG("rack: " << lfw(pldrack.toString()));
|
LOG_DEBUG("rack: " << lfw(pldrack.toString()));
|
||||||
|
@ -394,7 +398,7 @@ void XmlReader::endElement(const string& namespaceURI,
|
||||||
else if (tag == "PlayerMove")
|
else if (tag == "PlayerMove")
|
||||||
{
|
{
|
||||||
const Move &move = buildMove(*m_game, m_attributes, /*XXX:true*/false);
|
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);
|
PlayerMoveCmd *cmd = new PlayerMoveCmd(p, move);
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
}
|
}
|
||||||
|
@ -402,21 +406,21 @@ void XmlReader::endElement(const string& namespaceURI,
|
||||||
else if (tag == "GameMove")
|
else if (tag == "GameMove")
|
||||||
{
|
{
|
||||||
const Move &move = buildMove(*m_game, m_attributes, false);
|
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());
|
GameMoveCmd *cmd = new GameMoveCmd(*m_game, move, p.getId());
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tag == "Warning")
|
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);
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::WARNING);
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tag == "Penalty")
|
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"]);
|
int points = toInt(m_attributes["points"]);
|
||||||
LOG_ERROR("points=" << points);
|
LOG_ERROR("points=" << points);
|
||||||
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::PENALTY, points);
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::PENALTY, points);
|
||||||
|
@ -425,7 +429,7 @@ void XmlReader::endElement(const string& namespaceURI,
|
||||||
|
|
||||||
else if (tag == "Solo")
|
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"]);
|
int points = toInt(m_attributes["points"]);
|
||||||
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::SOLO, points);
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::SOLO, points);
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
|
@ -433,7 +437,7 @@ void XmlReader::endElement(const string& namespaceURI,
|
||||||
|
|
||||||
else if (tag == "EndGame")
|
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"]);
|
int points = toInt(m_attributes["points"]);
|
||||||
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::END_GAME, points);
|
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::END_GAME, points);
|
||||||
m_game->accessNavigation().addAndExecute(cmd);
|
m_game->accessNavigation().addAndExecute(cmd);
|
||||||
|
|
|
@ -84,7 +84,7 @@ static void writeMove(ostream &out, const Move &iMove,
|
||||||
{
|
{
|
||||||
out << "<" << iTag;
|
out << "<" << iTag;
|
||||||
if (iPlayerId != -1)
|
if (iPlayerId != -1)
|
||||||
out << " playerid=\"" << iPlayerId << "\"";
|
out << " playerId=\"" << iPlayerId << "\"";
|
||||||
out << " points=\"" << iMove.getScore() << "\" type=\"";
|
out << " points=\"" << iMove.getScore() << "\" type=\"";
|
||||||
if (iMove.isValid())
|
if (iMove.isValid())
|
||||||
{
|
{
|
||||||
|
@ -231,7 +231,7 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
||||||
{
|
{
|
||||||
const PlayerRackCmd *rackCmd = static_cast<const PlayerRackCmd*>(cmd);
|
const PlayerRackCmd *rackCmd = static_cast<const PlayerRackCmd*>(cmd);
|
||||||
unsigned int id = rackCmd->getPlayer().getId() + 1;
|
unsigned int id = rackCmd->getPlayer().getId() + 1;
|
||||||
out << indent << "<PlayerRack playerid=\"" << id << "\">"
|
out << indent << "<PlayerRack playerId=\"" << id << "\">"
|
||||||
<< toUtf8(rackCmd->getRack().toString())
|
<< toUtf8(rackCmd->getRack().toString())
|
||||||
<< "</PlayerRack>" << endl;
|
<< "</PlayerRack>" << endl;
|
||||||
}
|
}
|
||||||
|
@ -267,24 +267,24 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
||||||
// Warnings
|
// Warnings
|
||||||
if (eventCmd->getEventType() == PlayerEventCmd::WARNING)
|
if (eventCmd->getEventType() == PlayerEventCmd::WARNING)
|
||||||
{
|
{
|
||||||
out << indent << "<Warning playerid=\"" << id << "\" />" << endl;
|
out << indent << "<Warning playerId=\"" << id << "\" />" << endl;
|
||||||
}
|
}
|
||||||
// Penalties
|
// Penalties
|
||||||
else if (eventCmd->getEventType() == PlayerEventCmd::PENALTY)
|
else if (eventCmd->getEventType() == PlayerEventCmd::PENALTY)
|
||||||
{
|
{
|
||||||
out << indent << "<Penalty playerid=\"" << id
|
out << indent << "<Penalty playerId=\"" << id
|
||||||
<< "\" points=\"" << value << "\" />" << endl;
|
<< "\" points=\"" << value << "\" />" << endl;
|
||||||
}
|
}
|
||||||
// Solos
|
// Solos
|
||||||
else if (eventCmd->getEventType() == PlayerEventCmd::SOLO)
|
else if (eventCmd->getEventType() == PlayerEventCmd::SOLO)
|
||||||
{
|
{
|
||||||
out << indent << "<Solo playerid=\"" << id
|
out << indent << "<Solo playerId=\"" << id
|
||||||
<< "\" points=\"" << value << "\" />" << endl;
|
<< "\" points=\"" << value << "\" />" << endl;
|
||||||
}
|
}
|
||||||
// End game bonuses (freegame mode)
|
// End game bonuses (freegame mode)
|
||||||
else if (eventCmd->getEventType() == PlayerEventCmd::END_GAME)
|
else if (eventCmd->getEventType() == PlayerEventCmd::END_GAME)
|
||||||
{
|
{
|
||||||
out << indent << "<EndGame playerid=\"" << id
|
out << indent << "<EndGame playerId=\"" << id
|
||||||
<< "\" points=\"" << value << "\" />" << endl;
|
<< "\" points=\"" << value << "\" />" << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Reference in a new issue