levelz-cpp 0.2.0
Loading...
Searching...
No Matches
level.hpp
1#pragma once
2
3#include <vector>
4#include <unordered_map>
5
6#include "block.hpp"
7#include "coordinate.hpp"
8
9namespace LevelZ {
10
14 struct Level {
15 protected:
16 std::unordered_map<std::string, std::string> _headers = {};
17 std::vector<LevelZ::LevelObject> _blocks = {};
18
19 Level() {}
20
21 public:
26 inline std::unordered_map<std::string, std::string> headers() const {
27 return _headers;
28 }
29
34 inline std::vector<LevelObject> blocks() const {
35 return _blocks;
36 }
37
43 bool operator==(const Level& other) const {
44 return _headers == other._headers && _blocks == other._blocks;
45 }
46
52 bool operator!=(const Level& other) const {
53 return _headers != other._headers || _blocks != other._blocks;
54 }
55 };
56
60 enum Scroll {
64 NONE,
65
69 HORIZONTAL_LEFT,
70
74 HORIZONTAL_RIGHT,
75
79 VERTICAL_UP,
80
84 VERTICAL_DOWN
85 };
86
90 struct Level2D : Level {
91 public:
96
101
106 explicit Level2D(const std::unordered_map<std::string, std::string>& headers) : Level2D(headers, {}) {}
107
113 Level2D(const std::unordered_map<std::string, std::string>& headers, const std::vector<LevelObject>& blocks) {
114 _headers = headers;
115 _blocks = blocks;
116
117 if (headers.find("type") == headers.end())
118 _headers["type"] = "2";
119
120 spawn = Coordinate2D(0, 0);
121 if (headers.find("spawn") != headers.end()) {
123 }
124 }
125
130 explicit Level2D(const Level& level) : Level2D(level.headers(), level.blocks()) {};
131
136 inline Scroll scroll() {
137 if (_headers.find("scroll") == _headers.end())
138 return Scroll::NONE;
139
140 std::string scroll = _headers.at("scroll");
141
142 if (scroll == "none") return Scroll::NONE;
143 if (scroll == "horizontal-left") return Scroll::HORIZONTAL_LEFT;
144 if (scroll == "horizontal-right") return Scroll::HORIZONTAL_RIGHT;
145 if (scroll == "vertical-up") return Scroll::VERTICAL_UP;
146 if (scroll == "vertical-down") return Scroll::VERTICAL_DOWN;
147
148 return Scroll::NONE;
149 }
150 };
151
155 struct Level3D : Level {
156 public:
161
166
171 explicit Level3D(const std::unordered_map<std::string, std::string>& headers) : Level3D(headers, {}) {}
172
178 Level3D(const std::unordered_map<std::string, std::string>& headers, const std::vector<LevelObject>& blocks) {
179 _headers = headers;
180 _blocks = blocks;
181
182 if (headers.find("type") == headers.end())
183 _headers["type"] = "3";
184
185 spawn = Coordinate3D(0, 0, 0);
186 if (headers.find("spawn") != headers.end()) {
188 }
189 }
190
195 explicit Level3D(const Level& level) : Level3D(level.headers(), level.blocks()) {};
196 };
197
198}
Definition coordinate.hpp:28
static Coordinate2D from_string(const std::string &str)
Definition coordinate.hpp:167
Definition coordinate.hpp:177
static Coordinate3D from_string(const std::string &str)
Definition coordinate.hpp:323
Definition level.hpp:90
Level2D(const std::unordered_map< std::string, std::string > &headers)
Definition level.hpp:106
Level2D()
Definition level.hpp:100
Coordinate2D spawn
Definition level.hpp:95
Level2D(const std::unordered_map< std::string, std::string > &headers, const std::vector< LevelObject > &blocks)
Definition level.hpp:113
Level2D(const Level &level)
Definition level.hpp:130
Scroll scroll()
Definition level.hpp:136
Definition level.hpp:155
Level3D(const std::unordered_map< std::string, std::string > &headers, const std::vector< LevelObject > &blocks)
Definition level.hpp:178
Level3D(const std::unordered_map< std::string, std::string > &headers)
Definition level.hpp:171
Coordinate3D spawn
Definition level.hpp:160
Level3D(const Level &level)
Definition level.hpp:195
Level3D()
Definition level.hpp:165
Definition level.hpp:14
bool operator!=(const Level &other) const
Definition level.hpp:52
std::unordered_map< std::string, std::string > headers() const
Definition level.hpp:26
std::vector< LevelObject > blocks() const
Definition level.hpp:34
bool operator==(const Level &other) const
Definition level.hpp:43