-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresourse_manager.cpp
More file actions
100 lines (67 loc) · 2.3 KB
/
resourse_manager.cpp
File metadata and controls
100 lines (67 loc) · 2.3 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "resourse_manager.h"
namespace ResourceLocations {
std::string MenuFont = "Media/fonts/menu_font.otf";
std::string MenuTexture = "Media/images/main_background.jpg";
std::string ScoresFont = "Media/fonts/menu_font.otf";
std::string ScoresTexture = "Media/images/main_background.jpg";
std::string HighscoresData = "Media/highscores.dat";
std::string GameTexture = "Media/images/game_background.jpg";
}
/** Primary manager implementation **/
sf::Texture* ResourseManager::getTexture(Textures::Code code) {
return texture_manager.getTexture(code);
}
sf::Font * ResourseManager::getFont(Fonts::Code code) {
return font_manager.getFont(code);
}
/** Texture manager implementation **/
TextureManager::~TextureManager() {
std::map<Textures::Code, sf::Texture*>::iterator it;
for (it = textures.begin(); it != textures.end(); ++it)
delete it->second;
}
sf::Texture *TextureManager::getTexture(Textures::Code code) {
sf::Texture *texture = nullptr;
if(textures.find(code) != textures.end())
return textures[code];
texture = new sf::Texture();
switch (code) {
case Textures::Code::MenuBackground:
texture->loadFromFile(ResourceLocations::MenuTexture);
break;
case Textures::Code::ScoreBackground:
texture->loadFromFile(ResourceLocations::ScoresTexture);
break;
case Textures::Code::GameBackground:
texture->loadFromFile(ResourceLocations::GameTexture);
break;
default:
break;
}
textures[code] = texture;
return texture;
}
/** Font manager implementation **/
FontManager::~FontManager() {
std::map<Fonts::Code, sf::Font*>::iterator it;
for (it = fonts.begin(); it != fonts.end(); ++it)
delete it->second;
}
sf::Font *FontManager::getFont(Fonts::Code code) {
sf::Font *font = nullptr;
if(fonts.find(code) != fonts.end())
return fonts[code];
font = new sf::Font();
switch (code) {
case Fonts::Code::Menu:
font->loadFromFile(ResourceLocations::MenuFont);
break;
case Fonts::Code::Score:
font->loadFromFile(ResourceLocations::ScoresFont);
break;
default:
break;
}
fonts[code] = font;
return font;
}