123456789101112131415161718192021222324252627282930313233343536373839404142 |
- #pragma once
-
- #include <unordered_map>
- #include <SFML/Graphics.hpp>
- #include "Log.hpp"
- class Asset {
- public:
- static const sf::Texture& texture(std::string str) {
- if(s_tex.find(str) == s_tex.end()) {
- if(!s_tex[str].loadFromFile(str)) {
- Log(ERROR, "Unable to load ", str);
- exit(-1);
- }
- }
- return s_tex[str];
- }
-
- static const sf::SoundBuffer& sound(std::string str) {
- if(s_snd.find(str) == s_snd.end()) {
- if(!s_snd[str].loadFromFile(str)) {
- Log(ERROR, "Unable to load ", str);
- exit(-1);
- }
- }
- return s_snd[str];
- }
-
- static const sf::Font& font(std::string str) {
- if(s_fnt.find(str) == s_fnt.end()) {
- if(!s_fnt[str].loadFromFile(str)) {
- Log(ERROR, "Unable to load ", str);
- exit(-1);
- }
- }
- return s_fnt[str];
- }
- private:
- static std::unordered_map<std::string, sf::Texture> s_tex;
- static std::unordered_map<std::string, sf::SoundBuffer> s_snd;
- static std::unordered_map<std::string, sf::Font> s_fnt;
- };
|