-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoadMap.cpp
83 lines (61 loc) · 1.69 KB
/
LoadMap.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
#include "LoadMap.h"
void LoadMap::split_insert(const std::string& s, char delim, std::vector<int>& v)
{
std::stringstream ss(s);
std::string number;
while (std::getline(ss, number, delim)) {
v.push_back(std::stoi(number));
}
}
void LoadMap::createMap(std::string mapName)
{
is = new std::ifstream(mapName);
auto extract_number = [](std::string l)
{
int c = l.find(' ');
return l.substr((int)c + 1);
};
if (is->is_open())
{
for (int i = 0; getline(*is, line); i++)
{
//cas 1
switch (i)
{
case 0:
tileswide = std::stoi(extract_number(line));
break;
case 1:
tileshigh = std::stoi(extract_number(line));
break;
case 2:
tilewidth = std::stoi(extract_number(line));
break;
case 3:
tileheight = std::stoi(extract_number(line));
break;
default:
if (line != "") {
if (!isInLayer)
{
layer = std::stoi(extract_number(line));
map.push_back(std::vector<int>());
isInLayer = true;
}
else {
std::cout << line << '\n';
split_insert(line, ',', map[layer]);
}
}
if (line == "" && isInLayer) {
isInLayer = false;
}
break;
}
}
is->close();
}
}
LoadMap::LoadMap()
{
}