XmlSoundsFile.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 "engine/audio/AudioManager.h"
  16. #include "common/Logger.h"
  17. #include "core/XmlSoundsFile.h"
  18. XmlSoundsFile::XmlSoundsFile(const Ogre::String& file): XmlFile(file){}
  19. XmlSoundsFile::~XmlSoundsFile(){}
  20. void XmlSoundsFile::LoadSounds(){
  21. TiXmlNode* node = file_.RootElement();
  22. if (node == nullptr || node->ValueStr() != "sounds"){
  23. LOG_ERROR(file_.ValueStr() + " is not a valid sounds file! No <sounds> in root.");
  24. return;
  25. }
  26. node = node->FirstChild();
  27. while (node != nullptr){
  28. if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "sound"){
  29. AudioManager::Sound sound;
  30. sound.name = GetString(node, "name");
  31. sound.file = "./data/" + GetString(node, "file_name");
  32. AudioManager::getSingleton().AddSound(sound);
  33. }
  34. node = node->NextSibling();
  35. }
  36. }