QGearsMapFileXMLSerializer.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "common/TypeDefine.h"
  17. #include "data/QGearsXMLSerializer.h"
  18. #include "QGearsMapFile.h"
  19. namespace QGears{
  20. /**
  21. * Handles the serialization of map XML files.
  22. */
  23. class MapFileXMLSerializer : public XMLSerializer{
  24. public:
  25. /**
  26. * Constructor.
  27. */
  28. MapFileXMLSerializer();
  29. /**
  30. * Destructor.
  31. */
  32. virtual ~MapFileXMLSerializer();
  33. /**
  34. * Imports a map file.
  35. *
  36. * @param stream[in] The contents of the map file.
  37. * @param dest[out] The formed map file.
  38. */
  39. virtual void ImportMapFile(Ogre::DataStreamPtr &stream, MapFile *dest);
  40. typedef MapFile::Point Point;
  41. typedef MapFile::PointList PointList;
  42. typedef MapFile::Trigger Trigger;
  43. typedef MapFile::TriggerList TriggerList;
  44. protected:
  45. /**
  46. * Reads a file header from an XML node and sets the instance data.
  47. *
  48. * @param node[in] The XML node to read.
  49. */
  50. virtual void ReadHeader(TiXmlNode *node);
  51. /**
  52. * Reads a XML node as a script.
  53. *
  54. * @param node[in] The XML node to read.
  55. * @param dest[out] The script data will be loaded here.
  56. */
  57. virtual void ReadScript(TiXmlNode &node, MapFile *dest);
  58. /**
  59. * Reads a XML node as a 2D background.
  60. *
  61. * @param node[in] The XML node to read.
  62. * @param dest[out] The background data will be loaded here.
  63. */
  64. virtual void ReadBackground2D(TiXmlNode &node, MapFile *dest);
  65. /**
  66. * Reads a XML node as a walkmesh.
  67. *
  68. * @param node[in] The XML node to read.
  69. * @param dest[out] The walkmesh data will be loaded here.
  70. */
  71. virtual void ReadWalkmesh(TiXmlNode &node, MapFile *dest);
  72. /**
  73. * Reads a XML node as a forward direction.
  74. *
  75. * @param node[in] The XML node to read.
  76. * @param dest[out] The direction data will be loaded here.
  77. */
  78. virtual void ReadForwardDirection(TiXmlNode &node, MapFile *dest);
  79. /**
  80. * Reads a XML node as a list of entities.
  81. *
  82. * @param node[in] The XML node to read.
  83. * @param dest[out] The entity data will be loaded here.
  84. */
  85. virtual void ReadEntities(TiXmlNode &node, MapFile *dest);
  86. /**
  87. * Reads an XML node as an entity point.
  88. *
  89. * @param node[in] The XML node to read.
  90. * @param dest[out] The formed point data.
  91. */
  92. virtual void readObject(TiXmlNode &node, Point &dest);
  93. /**
  94. * Reads an XML node as a trigger.
  95. *
  96. * @param node[in] The XML node to read.
  97. * @param dest[out] The formed trigger data.
  98. */
  99. virtual void readObject(TiXmlNode &node, Trigger &dest);
  100. /**
  101. * Reads an object as a vector.
  102. *
  103. * @param stream[in] Input data.
  104. * @param dest[out] The formed vector data.
  105. * @param count[in] The size of the data to read.
  106. */
  107. template<typename ValueType> void ReadEntities(
  108. TiXmlNode &node, const String &tag, std::vector<ValueType> &dest
  109. );
  110. };
  111. }