XmlMapsFile.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "common/Logger.h"
  16. #include "engine/xml/XmlMapsFile.h"
  17. XmlMapsFile::XmlMapsFile(const Ogre::String& file): XmlFile(file){}
  18. XmlMapsFile::~XmlMapsFile(){}
  19. const Ogre::String XmlMapsFile::GetMapFileNameByName(const Ogre::String& name){
  20. TiXmlNode* node = file_.RootElement();
  21. if (node == nullptr || node->ValueStr() != "maps"){
  22. LOG_ERROR(
  23. "Field XML Manager: " + file_.ValueStr() + " is not a valid maps file! No <maps> in root."
  24. );
  25. return "";
  26. }
  27. node = node->FirstChild();
  28. while (node != nullptr){
  29. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "map")
  30. if (GetString(node, "name") == name) return GetString(node, "file_name");
  31. node = node->NextSibling();
  32. }
  33. LOG_WARNING("Can't find map \"" + name + "\" in " + file_.ValueStr() + ".");
  34. return "";
  35. }
  36. void XmlMapsFile::GetMapNames(Ogre::StringVector& complete_params){
  37. TiXmlNode* node = file_.RootElement();
  38. if (node == nullptr || node->ValueStr() != "maps"){
  39. LOG_ERROR(
  40. "Field XML Manager: " + file_.ValueStr() + " is not a valid maps file! No <maps> in root."
  41. );
  42. return;
  43. }
  44. node = node->FirstChild();
  45. while (node != nullptr){
  46. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "map")
  47. complete_params.push_back(GetString(node, "name"));
  48. node = node->NextSibling();
  49. }
  50. }