-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlobby_menu_textures.cpp
101 lines (88 loc) · 2.23 KB
/
lobby_menu_textures.cpp
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
101
#include "lobby_menu_textures.h"
#ifndef LOGIC_ONLY
#include "game_resources.h"
#include <QFile>
#include <functional>
#include <cassert>
#include <sstream>
lobby_menu_textures::lobby_menu_textures()
{
for (const auto r: get_all_races())
{
const std::string filename_str{get_head_filename(r)};
const QString filename{filename_str.c_str()};
QFile f(":/resources/textures/lobby_menu/" + filename);
f.copy(filename);
if (!m_heads[r].loadFromFile(filename.toStdString()))
{
QString msg{"Cannot find image file '" + filename + "'"};
throw std::runtime_error(msg.toStdString());
}
}
for (const auto r: get_all_chess_colors())
{
const std::string filename_str{get_color_filename(r)};
const QString filename{filename_str.c_str()};
QFile f(":/resources/textures/lobby_menu/" + filename);
f.copy(filename);
if (!m_color[r].loadFromFile(filename.toStdString()))
{
QString msg{"Cannot find image file '" + filename + "'"};
throw std::runtime_error(msg.toStdString());
}
}
for (const auto b: {true, false})
{
const std::string filename_str{get_ready_filename(b)};
const QString filename{filename_str.c_str()};
QFile f(":/resources/textures/lobby_menu/" + filename);
f.copy(filename);
if (!m_ready[b].loadFromFile(filename.toStdString()))
{
QString msg{"Cannot find image file '" + filename + "'"};
throw std::runtime_error(msg.toStdString());
}
}
}
sf::Texture& lobby_menu_textures::get_color(
const chess_color c
) noexcept
{
return m_color[c];
}
std::string lobby_menu_textures::get_color_filename(
const chess_color c
) const noexcept
{
std::stringstream s;
s << c << "_chess_color.jpg";
return s.str();
}
std::string lobby_menu_textures::get_head_filename(
const race r
) const noexcept
{
std::stringstream s;
s << r << "_head.jpg";
return s.str();
}
sf::Texture& lobby_menu_textures::get_ready(
const bool b
) noexcept
{
return m_ready[b];
}
std::string lobby_menu_textures::get_ready_filename(
const bool is_ready
) const noexcept
{
if (is_ready) return "ready_yes.jpg";
return "ready_no.jpg";
}
sf::Texture& lobby_menu_textures::get_head(
const race r
) noexcept
{
return m_heads[r];
}
#endif // LOGIC_ONLY