-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.cpp
79 lines (70 loc) · 1.69 KB
/
helper.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
#include "helper.h"
#include <cassert>
#include <cmath>
#include <iostream>
#include <QFile>
#include <vector>
#include "amino_acid.h"
void create_fonts()
{
const std::vector<std::string> v = { "arial.ttf" };
for (const std::string s: v)
{
QFile f( (":/fonts/" + s).c_str());
f.copy(s.c_str());
assert(QFile::exists(s.c_str()));
}
}
void create_resources()
{
create_fonts();
create_sounds();
create_sprites();
}
void create_sounds()
{
const std::vector<std::string> v = { "amino_acid_fighter_tune.wav" };
for (const std::string s: v)
{
QFile f( (":/sounds/" + s).c_str());
f.copy(s.c_str());
assert(QFile::exists(s.c_str()));
}
}
void create_sprites()
{
std::vector<amino_acid> amino_acids = get_all_amino_acids();
std::vector<std::string> file_names;
std::transform(
std::begin(amino_acids),
std::end(amino_acids),
std::back_inserter(file_names),
[](const amino_acid a)
{
return "Pictures/AminoAcids/" + to_str(a) + ".png";
}
);
file_names.push_back("Pictures/Bullet.png");
file_names.push_back("Pictures/BackgroundAminoAcidFighter2.png");
for (const std::string s: file_names)
{
QFile f((std::string(":/sprites/") + s).c_str());
const std::string filename{extract_base(s)};
f.copy(filename.c_str());
if (!QFile::exists(filename.c_str()))
{
std::cerr << "file " << s << " not created\n";
}
assert(QFile::exists(filename.c_str()));
}
}
std::string extract_base(const std::string& s)
{
const auto from = s.find_last_of('/');
if (from == std::string::npos) return s;
return s.substr(from + 1, s.size() - 1);
}
double deg_to_rad(const double deg) noexcept
{
return deg * M_PI / 180.0;
}