VGearsMapFileXMLSerializer.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/VGearsXMLSerializer.h"
  18. #include "VGearsMapFile.h"
  19. namespace VGears{
  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[in] stream The contents of the map file.
  37. * @param[out] dest 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[in] node The XML node to read.
  49. */
  50. virtual void ReadHeader(TiXmlNode *node);
  51. /**
  52. * Reads the script file location from the field XML file.
  53. *
  54. * @param[in] node The XML node to read.
  55. * @param[out] dest The script data will be loaded here.
  56. */
  57. virtual void ReadScript(TiXmlNode &node, MapFile *dest);
  58. /**
  59. * Reads the backgrouns file location from the field XML file.
  60. *
  61. * @param[in] node The XML node to read.
  62. * @param[out] dest The background data will be loaded here.
  63. */
  64. virtual void ReadBackground2D(TiXmlNode &node, MapFile *dest);
  65. /**
  66. * Reads the text file location from the field XML file.
  67. *
  68. * @param[in] node The XML node to read.
  69. * @param[out] dest The background data will be loaded here.
  70. */
  71. virtual void ReadTexts(TiXmlNode &node, MapFile *dest);
  72. /**
  73. * Reads the walkmesh file location from the field XML file.
  74. *
  75. * @param[in] node The XML node to read.
  76. * @param[out] dest The walkmesh data will be loaded here.
  77. */
  78. virtual void ReadWalkmesh(TiXmlNode &node, MapFile *dest);
  79. /**
  80. * Reads the field forward direction location from the field XML file.
  81. *
  82. * @param[in] node The XML node to read.
  83. * @param[out] dest The direction data will be loaded here.
  84. */
  85. virtual void ReadForwardDirection(TiXmlNode &node, MapFile *dest);
  86. /**
  87. * Reads the entities location from the field XML file.
  88. *
  89. * @param[in] node The XML node to read.
  90. * @param[out] dest The entity data will be loaded here.
  91. */
  92. virtual void ReadEntities(TiXmlNode &node, MapFile *dest);
  93. /**
  94. * Reads an object from the field XML file.
  95. *
  96. * @param[in] node The XML node to read.
  97. * @param[out] dest The formed point data.
  98. */
  99. virtual void readObject(TiXmlNode &node, Point &dest);
  100. /**
  101. * Reads a trigger from the field XML file.
  102. *
  103. * @param[in] node The XML node to read.
  104. * @param[out] dest The formed trigger data.
  105. */
  106. virtual void readObject(TiXmlNode &node, Trigger &dest);
  107. /**
  108. * Reads entities from a map.
  109. *
  110. * @param[in] node Input data.
  111. * @param[in] tag Entity section tag.
  112. * @param[out] dest The formed vector data.
  113. */
  114. template<typename ValueType> void ReadEntities(
  115. TiXmlNode &node, const String &tag, std::vector<ValueType> &dest
  116. );
  117. };
  118. }