Saved games: write the dictionary letters as display strings

This commit is contained in:
Olivier Teulière 2012-03-28 23:21:24 +02:00
parent 53adb5d91b
commit a5f13e3ba7
2 changed files with 16 additions and 2 deletions

View file

@ -19,6 +19,7 @@
*****************************************************************************/
#include <fstream>
#include <algorithm>
#include <SAX/XMLReader.hpp>
#include <SAX/InputSource.hpp>
@ -202,7 +203,13 @@ void XmlReader::endElement(const string& namespaceURI,
{
if (tag == "Letters")
{
if (m_dic.getHeader().getLetters() != fromUtf8(m_data))
const wdstring & displayLetters = m_dic.convertToDisplay(m_dic.getHeader().getLetters());
// Remove spaces
string::iterator it;
it = remove(m_data.begin(), m_data.end(), L' ');
m_data.erase(it, m_data.end());
// Compare
if (displayLetters != fromUtf8(m_data))
throw LoadGameException("The current dictionary is different from the one used in the saved game");
}
else if (tag == "WordNb")

View file

@ -116,7 +116,14 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
else
throw SaveGameException("Invalid dictionary type");
out << "</Type>" << endl;
out << indent << "<Letters>" << toUtf8(header.getLetters()) << "</Letters>" << endl;
// Retrieve the dictionary letters, ans separate them with spaces
wstring lettersWithSpaces = header.getLetters();
for (size_t i = lettersWithSpaces.size() - 1; i > 0; --i)
lettersWithSpaces.insert(i, 1, L' ');
// Convert to a display string
const wstring &displayLetters =
iGame.getDic().convertToDisplay(lettersWithSpaces);
out << indent << "<Letters>" << toUtf8(displayLetters) << "</Letters>" << endl;
out << indent << "<WordNb>" << header.getNbWords() << "</WordNb>" << endl;
removeIndent(indent);
out << indent << "</Dictionary>" << endl;