mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-30 20:34:27 +01:00
Write more information in a saved game: dictionary info and move points
This commit is contained in:
parent
f9ca096dda
commit
c37107ed87
2 changed files with 51 additions and 3 deletions
|
@ -40,6 +40,7 @@
|
|||
#include "player_points_cmd.h"
|
||||
#include "master_move_cmd.h"
|
||||
#include "navigation.h"
|
||||
#include "header.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -178,7 +179,11 @@ void XmlReader::startElement(const string& namespaceURI,
|
|||
|
||||
m_data.clear();
|
||||
const string &tag = localName;
|
||||
if (tag == "Player")
|
||||
if (tag == "Dictionary")
|
||||
{
|
||||
m_context = "Dictionary";
|
||||
}
|
||||
else if (tag == "Player")
|
||||
{
|
||||
m_context = "Player";
|
||||
for (int i = 0; i < atts.getLength(); ++i)
|
||||
|
@ -206,6 +211,25 @@ void XmlReader::endElement(const string& namespaceURI,
|
|||
LOG_DEBUG("endElement: " << namespaceURI << ":" << localName << "(" << m_data << ")");
|
||||
|
||||
const string &tag = localName;
|
||||
|
||||
// Dictionary section
|
||||
if (m_context == "Dictionary")
|
||||
{
|
||||
if (tag == "Letters")
|
||||
{
|
||||
if (m_dic.getHeader().getLetters() != fromUtf8(m_data))
|
||||
throw LoadGameException("The current dictionary is different from the one used in the saved game");
|
||||
}
|
||||
else if (tag == "WordNb")
|
||||
{
|
||||
if (m_dic.getHeader().getNbWords() != atoi(m_data.c_str()))
|
||||
throw LoadGameException("The current dictionary is different from the one used in the saved game");
|
||||
}
|
||||
else if (tag == "Dictionary")
|
||||
m_context = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (tag == "Mode")
|
||||
{
|
||||
// The game should not be created yet
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "player_points_cmd.h"
|
||||
#include "master_move_cmd.h"
|
||||
#include "mark_played_cmd.h"
|
||||
#include "dic.h"
|
||||
#include "header.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -63,7 +65,8 @@ static string toUtf8(const wstring &s)
|
|||
static void writeMove(ostream &out, const Move &iMove,
|
||||
const string &iTag, int iPlayerId)
|
||||
{
|
||||
out << "<" << iTag << " playerid=\"" << iPlayerId << "\" type=\"";
|
||||
out << "<" << iTag << " playerid=\"" << iPlayerId
|
||||
<< "\" points=\"" << iMove.getScore() << "\" type=\"";
|
||||
if (iMove.getType() == Move::VALID_ROUND)
|
||||
{
|
||||
const Round &round = iMove.getRound();
|
||||
|
@ -100,7 +103,28 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
|
|||
addIndent(indent);
|
||||
|
||||
// ------------------------
|
||||
// Write the header
|
||||
// Write the dictionary information
|
||||
out << indent << "<Dictionary>" << endl;
|
||||
addIndent(indent);
|
||||
const Header &header = iGame.getDic().getHeader();
|
||||
out << indent << "<Name>" << toUtf8(header.getName()) << "</Name>" << endl;
|
||||
out << indent << "<Type>";
|
||||
if (header.getType() == Header::kDAWG)
|
||||
out << "dawg";
|
||||
else if (header.getType() == Header::kGADDAG)
|
||||
out << "gaddag";
|
||||
else
|
||||
throw SaveGameException("Invalid dictionary type");
|
||||
out << "</Type>" << endl;
|
||||
out << indent << "<Letters>" << toUtf8(header.getLetters()) << "</Letters>" << endl;
|
||||
out << indent << "<WordNb>" << header.getNbWords() << "</WordNb>" << endl;
|
||||
removeIndent(indent);
|
||||
out << indent << "</Dictionary>" << endl;
|
||||
// End of dictionary information
|
||||
// ------------------------
|
||||
|
||||
// ------------------------
|
||||
// Write the game header
|
||||
out << indent << "<Game>" << endl;
|
||||
addIndent(indent);
|
||||
// Game type
|
||||
|
|
Loading…
Add table
Reference in a new issue