-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetManager.cpp
More file actions
36 lines (34 loc) · 1.18 KB
/
AssetManager.cpp
File metadata and controls
36 lines (34 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <SFML/Graphics.hpp>
#include <map>
#include <string>
#include <iostream>
class AssetManager {
inline static std::map<std::string, sf::Texture> textures = std::map<std::string, sf::Texture>();
inline static std::map<std::string, sf::Font> fonts = std::map<std::string, sf::Font>();
public:
static auto getTexture(const std::string fileName) -> sf::Texture&{
{
auto pairExists = textures.find(fileName);
if (pairExists != textures.end()) {
return pairExists->second;
} else {
auto &texture = textures[fileName];
if (!texture.loadFromFile(fileName)){std::cerr << "Wrong texture name";}
return texture;
}
}
}
static auto getFont(const std::string fileName) -> sf::Font& {
{
auto pairExists = fonts.find(fileName);
if (pairExists != fonts.end()) {
return pairExists->second;
} else {
auto &font = fonts[fileName];
if (!font.loadFromFile(fileName)){std::cerr << "Wrong font name";}
return font;
}
}
}
};