File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)
2
2
3
3
project (levelz-cpp
4
4
LANGUAGES C CXX
5
- VERSION 0.1.0
5
+ VERSION 0.1.1
6
6
DESCRIPTION "C/C++ implementation of the LevelZ File Format"
7
7
HOMEPAGE_URL "https://github.com/LevelZ-File/cpp-bindings"
8
8
)
Original file line number Diff line number Diff line change 1
1
#include < string>
2
2
#include < vector>
3
3
#include < fstream>
4
+ #include < sstream>
4
5
#include < cstdio>
5
6
#include < unordered_map>
6
7
#include < algorithm>
@@ -249,14 +250,19 @@ namespace LevelZ {
249
250
250
251
std::vector<LevelObject> blocks;
251
252
for (std::string& line : parts[1 ]) {
253
+ if (line[0 ] == ' #' ) continue ;
252
254
if (line == END) break ;
253
255
256
+ int ci = line.find (' #' );
257
+ std::string line0 = ci == std::string::npos ? line : line.substr (0 , ci);
258
+ line0.erase (line0.find_last_not_of (" \n\r\t " ) + 1 );
259
+
254
260
if (is2D) {
255
- std::pair<Block, std::vector<Coordinate2D>> pair = read2DLine (line );
261
+ std::pair<Block, std::vector<Coordinate2D>> pair = read2DLine (line0 );
256
262
for (Coordinate2D& point : pair.second )
257
263
blocks.push_back (LevelObject (pair.first , point));
258
264
} else {
259
- std::pair<Block, std::vector<Coordinate3D>> pair = read3DLine (line );
265
+ std::pair<Block, std::vector<Coordinate3D>> pair = read3DLine (line0 );
260
266
for (Coordinate3D& point : pair.second )
261
267
blocks.push_back (LevelObject (pair.first , point));
262
268
}
Original file line number Diff line number Diff line change @@ -19,17 +19,32 @@ int main() {
19
19
20
20
// File Parsing
21
21
std::vector<std::string> l4v = {
22
- " @type 2" ,
23
- " @scroll horizontal-right" ,
24
- " @spawn [-2, 4]" ,
25
- " ---" ,
26
- " grass: [0, 0]" ,
27
- " stone: [0, 1]*[0, 2]"
22
+ " @type 2" ,
23
+ " @scroll horizontal-right" ,
24
+ " @spawn [-2, 4]" ,
25
+ " ---" ,
26
+ " grass: [0, 0]" ,
27
+ " stone: [0, 1]*[0, 2]"
28
28
};
29
29
Level2D l4 = static_cast <Level2D>(LevelZ::parseLines (l4v));
30
30
r |= assert (l4.scroll () == Scroll::HORIZONTAL_RIGHT);
31
31
r |= assert (l4.spawn == Coordinate2D (-2 , 4 ));
32
32
r |= assert (l4.blocks ().size () == 3 );
33
33
34
+ std::vector<std::string> l5v = {
35
+ " @type 2" ,
36
+ " @spawn [-10, 4]" ,
37
+ " @scroll none" ,
38
+ " ---" ,
39
+ " grass<type=1>: [0, 0]*[0, 1] # Comment 1" ,
40
+ " stone<cracked=false>: [-1, 1]*[0, 2] # Comment 2" ,
41
+ " end" ,
42
+ " Some Comment Here"
43
+ };
44
+ Level2D l5 = static_cast <Level2D>(LevelZ::parseLines (l5v));
45
+ r |= assert (l5.scroll () == Scroll::NONE);
46
+ r |= assert (l5.spawn == Coordinate2D (-10 , 4 ));
47
+ r |= assert (l5.blocks ().size () == 4 );
48
+
34
49
return r;
35
50
}
You can’t perform that action at this time.
0 commit comments