summaryrefslogtreecommitdiff
path: root/src/level.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2022-03-24 12:01:09 -0600
committercflip <cflip@cflip.net>2022-03-24 12:01:09 -0600
commit42397536e79fdf68fb194de86bbeb3f1ed098eed (patch)
tree9756ff2870dab58f577b2e1a18325ee0337114d4 /src/level.cpp
parent6ce8e26ecba668578b307ca7039a9af9e86310a7 (diff)
Add a header to the level file format
Diffstat (limited to 'src/level.cpp')
-rw-r--r--src/level.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/level.cpp b/src/level.cpp
index f3235a8..d5893e6 100644
--- a/src/level.cpp
+++ b/src/level.cpp
@@ -103,6 +103,8 @@ void Level::toggleTile(int x, int y)
}
static const char* DEFAULT_FILENAME = "level.non";
+static const char* LEVEL_HEADER = "NON";
+static const int LEVEL_HEADER_SIZE = 3;
void Level::save() const
{
@@ -118,6 +120,8 @@ void Level::save() const
return;
}
+ outputStream.write(LEVEL_HEADER, LEVEL_HEADER_SIZE);
+
outputStream.write((char*)&m_width, 1);
outputStream.write((char*)&m_height, 1);
outputStream.write((char*)m_tiles, m_width * m_height);
@@ -134,6 +138,14 @@ void Level::load()
return;
}
+ char header[LEVEL_HEADER_SIZE];
+ inputStream.read(header, LEVEL_HEADER_SIZE);
+
+ if (strncmp(header, LEVEL_HEADER, LEVEL_HEADER_SIZE) != 0) {
+ std::cerr << "Level loaded from " << DEFAULT_FILENAME << " does not match expected header!\n";
+ return;
+ }
+
uint8_t width, height;
inputStream.read((char*)&width, 1);
inputStream.read((char*)&height, 1);