-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureManager.cpp
More file actions
48 lines (38 loc) · 901 Bytes
/
TextureManager.cpp
File metadata and controls
48 lines (38 loc) · 901 Bytes
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
#include <fstream>
#include <nlohmann/json.hpp>
#include <qimage.h>
#include "TextureManager.h"
#include <string>
#include <LogUtil.h>
using json = nlohmann::json;
void initTextures()
{
std::ifstream file;
file.open("textures/textures.json");
if (!file.is_open())
{
logE("Could not initialize textures. Make sure the textures.json file exists.");
return;
}
json j = json::parse(file);
for (const json& texture : j["textures"])
{
std::string imagePath = std::format("textures/{}", static_cast<std::string>(texture["file"]));
QImage* image = new QImage(imagePath.c_str());
std::string id = texture["id"];
textures[id] = image;
}
logI("Successfully initialized textures");
}
QImage* getTexture(std::string id)
{
return textures[id];
}
void cleanUpTextures()
{
for (const std::pair<std::string, QImage*> entry : textures)
{
delete entry.second;
}
textures.clear();
}