Assets.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Triangles
  3. * Copyright (C) 2016 POSITIVE MENTAL ATTITUDE
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3 of the License.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "Assets.hpp"
  18. #include "Utility.hpp"
  19. Assets::~Assets()
  20. {
  21. textures.clear();
  22. sounds.clear();
  23. fonts.clear();
  24. }
  25. sf::Texture& Assets::loadTexture(std::string file)
  26. {
  27. if(!textures.count(file))
  28. {
  29. sf::Texture texture;
  30. if(!texture.loadFromFile(file))
  31. Echo::out(Echo::Error, "Unable to load texture file: ", file, "\nExpect a segfault!");
  32. texture.setSmooth(true);
  33. textures.emplace(file, texture);
  34. }
  35. return textures.at(file);
  36. }
  37. sf::SoundBuffer& Assets::loadSound(std::string file)
  38. {
  39. if(!sounds.count(file))
  40. {
  41. sf::SoundBuffer sound;
  42. if(!sound.loadFromFile(file))
  43. Echo::out(Echo::Error, "Unable to load sound file: ", file, "\nExpect a segfault!");
  44. sound.loadFromFile(file);
  45. sounds.emplace(file, sound);
  46. }
  47. return sounds.at(file);
  48. }
  49. sf::Font& Assets::loadFont(std::string file)
  50. {
  51. if(!fonts.count(file))
  52. {
  53. sf::Font font;
  54. if(!font.loadFromFile(file))
  55. Echo::out(Echo::Error, "Unable to load font file: ", file, "\nExpect a segfault!");
  56. fonts.emplace(file, font);
  57. }
  58. return fonts.at(file);
  59. }