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
|
#include "Icons.h"
#include <string>
#include <unordered_map>
#include <raylib.h>
static const std::unordered_map<long int, std::string> FILENAMES {
{834, "resources/frigate_16.png"},
{324, "resources/frigate_16.png"},
{830, "resources/frigate_16.png"},
{25, "resources/frigate_16.png"},
{27, "resources/battleship_16.png"},
{540, "resources/battleCruiser_16.png"},
{1305, "resources/destroyer_16.png"},
{420, "resources/destroyer_16.png"},
{1534, "resources/destroyer_16.png"},
{541, "resources/destroyer_16.png"},
{29, "resources/capsule_16.png"},
{361, "resources/mobileWarpDisruptor.png"},
{963, "resources/cruiser_16.png"},
{894, "resources/cruiser_16.png"},
{26, "resources/cruiser_16.png"},
{832, "resources/cruiser_16.png"},
{906, "resources/cruiser_16.png"},
{358, "resources/cruiser_16.png"},
{237, "resources/rookie_16.png"},
{1404, "resources/engineeringComplexLarge.png"},
};
Icons::Icons() :
m_cache {}
{
}
Icons::~Icons()
{
reset();
}
void
Icons::reset()
{
for (const auto& [_, texture] : m_cache)
UnloadTexture(texture);
m_cache.clear();
}
Texture2D
Icons::find(const long int group)
{
const auto search = FILENAMES.find(group);
std::string filename = "resources/wreck.png";
if (search != FILENAMES.end())
filename = search->second;
const auto existing = m_cache.find(filename);
if (existing != m_cache.end()) {
return existing->second;
}
else {
auto texture = LoadTexture(filename.data());
m_cache[filename] = texture;
return texture;
}
}
|