-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
71 lines (59 loc) · 1.88 KB
/
utils.cpp
File metadata and controls
71 lines (59 loc) · 1.88 KB
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
#include "Game/Game.hpp"
extern Game game;
namespace fs = std::filesystem;
std::vector<std::string> GetFileNamesInFolder(const std::string& folderPath) {
std::vector<std::string> fileNames;
if (fs::exists(folderPath) && fs::is_directory(folderPath)) {
for (const auto& entry : fs::directory_iterator(folderPath)) {
if (entry.is_regular_file()) {
fileNames.push_back(entry.path().filename().string());
}
}
}
return fileNames;
}
std::vector<std::string> SplitString(std::string s, std::string delimiter) {
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
std::string token;
std::vector<std::string> res;
while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
token = s.substr (pos_start, pos_end - pos_start);
pos_start = pos_end + delim_len;
res.push_back (token);
}
res.push_back(s.substr(pos_start));
return res;
}
Entity& GetEntityByName(const std::string& name)
{
for (Entity& entity : game.entities) {
if (entity.name == name) {
return entity;
}
}
auto it = std::find_if(game.killed_entities.begin(), game.killed_entities.end(), [&name](const Entity& item) {
return item.name == name;
});
if (it == game.killed_entities.end()) {
std::string err = "! ENTITY " + name + " NOT FOUND !";
auto er_it = std::find_if(game.Errors.begin(), game.Errors.end(), [&err](std::string& item) {
return err == item;
});
if (it != game.killed_entities.end())
{
Error(err);
}
}
static Entity default_entity;
default_entity.name = name;
return default_entity;
}
int CountStringsInVector(std::vector<std::string>& v, std::string& s)
{
int i = 0;
for (std::string& fs : v)
{
if (fs == s) i++;
}
return 0;
}