File indexing completed on 2024-04-21 04:04:44

0001 /* This file is part of KsirK.
0002    Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KsirK is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, either version 2
0007    of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    General Public License for more details.
0013 
0014    You should have received a copy of the GNU General Public License
0015    along with this program; if not, write to the Free Software
0016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0017    02110-1301, USA
0018 */
0019 
0020 /* begin                : Mon Feb 07 2005 */
0021 
0022 #ifndef KSIRK_SAVELOAD_KSIRKGAMEXMLHANDLER_H
0023 #define KSIRK_SAVELOAD_KSIRKGAMEXMLHANDLER_H
0024 
0025 #include "KsirkGlobalDefinitions.h"
0026 #include "kgamewin.h"
0027 #include "GameLogic/gameautomaton.h"
0028 #include "GameLogic/player.h"
0029 #include "GameLogic/goal.h"
0030 
0031 #include <QString>
0032 #include <qxml.h>
0033 
0034 namespace Ksirk
0035 {
0036 
0037 namespace SaveLoad
0038 {
0039 
0040 /**
0041   * Sax handler for the KsirK skin XML definition file.
0042   * @author Gael de Chalendar (aka Kleag)
0043   */
0044 class GameXmlHandler : public QXmlDefaultHandler
0045 {
0046 public:
0047   /** 
0048     * Constructor
0049     * @param game The game that the file loaded will set up
0050     * @param waitedPlayers This list will be filled by the description of the 
0051     * network players whose connection will be waited for
0052     */
0053   GameXmlHandler(KGameWindow& game, QList<GameLogic::PlayerMatrix>& waitedPlayers) :
0054     m_game(game),
0055     m_waitedPlayers(waitedPlayers),
0056     m_playersNumber(0),
0057     m_inGoal(false),
0058     m_goal(nullptr)
0059   {
0060     m_waitedPlayers.clear();
0061   }
0062 
0063   /** Default destructor */
0064   ~GameXmlHandler() override {}
0065 
0066   /** Called when initializing reading of a document */
0067   bool startDocument() override;
0068 
0069   /** 
0070     * Called whenever a XML open tag is read
0071     * @param namespaceURI The read element namespace URI
0072     * @param localName The simple name of the tag
0073     * @param qName The qualified name of the tag (see http://www.w3.org/XML/ 
0074     * for details)
0075     * @param atts The attributes of this tag.
0076     */
0077   bool startElement( const QString & namespaceURI, const QString & localName, 
0078                      const QString & qName, const QXmlAttributes & atts ) override;
0079 
0080   /**
0081     * Called whenever a XML close tag is read.
0082     * @param namespaceURI The closing element namespace URI
0083     * @param localName The simple name of the tag
0084     * @param qName The qualified name of the tag (see http://www.w3.org/XML/ 
0085     * for details)
0086     */
0087   bool endElement(const QString& namespaceURI, const QString& localName, 
0088                   const QString& qName ) override;
0089 
0090 private:
0091   KGameWindow& m_game;
0092   GameLogic::GameAutomaton::GameState m_savedState;
0093   QMap<QString,QString> m_ownersMap;
0094   QList<GameLogic::PlayerMatrix>& m_waitedPlayers;
0095   unsigned int m_playersNumber;
0096   bool m_inGoal;
0097   GameLogic::Goal* m_goal;
0098   QString m_goalPlayerName;
0099 };
0100 
0101 
0102 } // closing namespace SaveLoad
0103 } // closing namespace Ksirk
0104 
0105 
0106 #endif // KSIRK_SAVELOAD_KSIRKGAMEXMLHANDLER_H
0107