mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
Savegames: save/load properly the warnings, penalties and solos
This commit is contained in:
parent
7868593cb2
commit
3c29804148
2 changed files with 58 additions and 4 deletions
|
@ -49,6 +49,7 @@
|
|||
#include "player_rack_cmd.h"
|
||||
#include "player_move_cmd.h"
|
||||
#include "player_points_cmd.h"
|
||||
#include "player_event_cmd.h"
|
||||
#include "master_move_cmd.h"
|
||||
#include "navigation.h"
|
||||
#include "header.h"
|
||||
|
@ -165,7 +166,7 @@ void XmlReader::startElement(const string& namespaceURI,
|
|||
{
|
||||
(void) namespaceURI;
|
||||
(void) qName;
|
||||
LOG_DEBUG("Start Element: " << (localName.empty() ? qName : namespaceURI + ":" + localName));
|
||||
LOG_TRACE("Start Element: " << (localName.empty() ? qName : namespaceURI + ":" + localName));
|
||||
|
||||
m_data.clear();
|
||||
const string &tag = localName;
|
||||
|
@ -197,7 +198,8 @@ void XmlReader::startElement(const string& namespaceURI,
|
|||
}
|
||||
}
|
||||
else if (tag == "GameRack" || tag == "PlayerRack" ||
|
||||
tag == "PlayerMove" || tag == "GameMove" || tag == "MasterMove")
|
||||
tag == "PlayerMove" || tag == "GameMove" || tag == "MasterMove" ||
|
||||
tag == "Warning" || tag == "Penalty" || tag == "Solo")
|
||||
{
|
||||
m_attributes.clear();
|
||||
for (int i = 0; i < atts.getLength(); ++i)
|
||||
|
@ -220,7 +222,7 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
const string&)
|
||||
{
|
||||
(void) namespaceURI;
|
||||
LOG_DEBUG("endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")");
|
||||
LOG_TRACE("endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")");
|
||||
|
||||
const string &tag = localName;
|
||||
|
||||
|
@ -388,13 +390,37 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
m_game->accessNavigation().addAndExecute(cmd);
|
||||
}
|
||||
|
||||
else if (tag == "Warning")
|
||||
{
|
||||
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"]);
|
||||
int points = toInt(m_attributes["points"]);
|
||||
LOG_ERROR("points=" << points);
|
||||
PlayerEventCmd *cmd = new PlayerEventCmd(p, PlayerEventCmd::PENALTY, points);
|
||||
m_game->accessNavigation().addAndExecute(cmd);
|
||||
}
|
||||
|
||||
else if (tag == "Solo")
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void XmlReader::characters(const string& ch)
|
||||
{
|
||||
m_data += ch;
|
||||
LOG_DEBUG("Characters: " << ch);
|
||||
LOG_TRACE("Characters: " << ch);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "player_rack_cmd.h"
|
||||
#include "player_move_cmd.h"
|
||||
#include "player_points_cmd.h"
|
||||
#include "player_event_cmd.h"
|
||||
#include "master_move_cmd.h"
|
||||
#include "dic.h"
|
||||
#include "header.h"
|
||||
|
@ -250,6 +251,33 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
|||
out << endl;
|
||||
|
||||
}
|
||||
else if (dynamic_cast<const PlayerEventCmd*>(cmd))
|
||||
{
|
||||
const PlayerEventCmd *eventCmd = static_cast<const PlayerEventCmd*>(cmd);
|
||||
unsigned int id = eventCmd->getPlayer().getId() + 1;
|
||||
int value = eventCmd->getPoints();
|
||||
// Warnings
|
||||
if (eventCmd->getEventType() == PlayerEventCmd::WARNING)
|
||||
{
|
||||
out << indent << "<Warning playerid=\"" << id << "\" />" << endl;
|
||||
}
|
||||
// Penalties
|
||||
else if (eventCmd->getEventType() == PlayerEventCmd::PENALTY)
|
||||
{
|
||||
out << indent << "<Penalty playerid=\"" << id
|
||||
<< "\" points=\"" << value << "\" />" << endl;
|
||||
}
|
||||
// Solos
|
||||
else if (eventCmd->getEventType() == PlayerEventCmd::SOLO)
|
||||
{
|
||||
out << indent << "<Solo playerid=\"" << id
|
||||
<< "\" points=\"" << value << "\" />" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unknown event type: " << eventCmd->getEventType());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR("Unsupported command: " << lfw(cmd->toString()));
|
||||
|
|
Loading…
Reference in a new issue