1
+ #pragma once
2
+ #include < string>
3
+ #include < vector>
4
+ #include < iostream>
5
+ #include < fstream>
6
+ #include < sstream>
7
+ #include < glm\glm.hpp>
8
+ #include " Structs.h"
9
+ #include " Singleton.h"
10
+
11
+ // Data layout: Position.x, Position.y, Type, Order, Time (int sec
12
+ // Data format: .csv
13
+
14
+ class Parser : public Fluffy ::Singleton<Parser>
15
+ {
16
+ public:
17
+ static void ParseEnemyLayoutData (const std::string& inputFile, std::vector<EnemyEnteringData>& data)
18
+ {
19
+ std::ifstream file{ inputFile };
20
+ if (!file)
21
+ std::cout << " Cannot open " << inputFile << " !\n " ;
22
+
23
+ while (!file.eof ())
24
+ {
25
+ EnemyEnteringData enemy{};
26
+
27
+ std::string line;
28
+ std::getline (file, line);
29
+
30
+ std::istringstream iLine{ line };
31
+ std::string posX;
32
+ std::getline (iLine, posX, ' ,' );
33
+ std::string posY;
34
+ std::getline (iLine, posY, ' ,' );
35
+ std::string type;
36
+ std::getline (iLine, type, ' ,' );
37
+ std::string order;
38
+ std::getline (iLine, order, ' ,' );
39
+ std::string time ;
40
+ std::getline (iLine, time );
41
+
42
+ if (!posX.empty ())
43
+ {
44
+ bool isInt{ true };
45
+
46
+ std::string::const_iterator it = posX.begin ();
47
+
48
+ while (it != posX.end ())
49
+ {
50
+ if (!std::isdigit (*it))
51
+ {
52
+ isInt = false ;
53
+ break ;
54
+ }
55
+
56
+ ++it;
57
+ }
58
+
59
+ if (isInt)
60
+ {
61
+ enemy.position .x = float (std::stoi (posX));
62
+ }
63
+ }
64
+
65
+ if (!posY.empty ())
66
+ {
67
+ bool isInt{ true };
68
+
69
+ std::string::const_iterator it = posY.begin ();
70
+
71
+ while (it != posY.end ())
72
+ {
73
+ if (!std::isdigit (*it))
74
+ {
75
+ isInt = false ;
76
+ break ;
77
+ }
78
+
79
+ ++it;
80
+ }
81
+
82
+ if (isInt)
83
+ {
84
+ enemy.position .y = float (std::stoi (posY));
85
+ }
86
+ }
87
+
88
+ if (type == " bee" )
89
+ enemy.type = EnemyType::Bee;
90
+ else if (type == " butterfly" )
91
+ enemy.type = EnemyType::Butterfly;
92
+ else if (type == " boss" )
93
+ enemy.type = EnemyType::Boss;
94
+
95
+ enemy.order = std::stoi (order);
96
+ enemy.time = float (std::stoi (time ));
97
+
98
+ data.push_back (enemy);
99
+ }
100
+ }
101
+
102
+ };
0 commit comments