-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimages.cpp
More file actions
40 lines (31 loc) · 855 Bytes
/
images.cpp
File metadata and controls
40 lines (31 loc) · 855 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
#include <filesystem>
#include "raylib.h"
#include "images.h"
ImageLoader::ImageLoader(std::string_view dir)
: images_{}
{
for (auto const &dir_entry : std::filesystem::directory_iterator(dir))
{
const std::string ext{dir_entry.path().extension()};
if (ext != ".png" && ext != ".jpg")
continue;
const std::string imagename{dir_entry.path().stem()};
const char *filename = dir_entry.path().c_str();
images_.emplace(imagename, LoadTexture(filename));
}
}
ImageLoader::~ImageLoader()
{
for (auto [key, tex] : images_)
{
::UnloadTexture(tex);
}
}
const Texture2D &ImageLoader::at(std::string_view name) const
{
return images_.at(std::string(name));
}
const Texture2D &ImageLoader::operator[](std::string_view name)
{
return images_[std::string(name)];
}