Mario: formatting

This commit is contained in:
2022-07-21 20:17:24 +02:00
parent 6558329547
commit 58fd1a37a8
9 changed files with 373 additions and 302 deletions
+18 -18
View File
@@ -14,10 +14,10 @@
#define FILE_VERSION 0x01
void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer);
std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer);
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> mario,
@@ -96,7 +96,7 @@ MapObject parseBlock(std::ifstream &map_file) {
modifier_id, modifier_data);
}
void loadEmptyMap( std::vector<mapColumnType> &objects, size_t editor_width) {
void loadEmptyMap(std::vector<mapColumnType> &objects, size_t editor_width) {
objects.resize(editor_width);
}
@@ -106,7 +106,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario,
const std::string &file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width) {
if(!FSLib::exists(file)) {
if (!FSLib::exists(file)) {
// create empty array large enough for initial editor window
loadEmptyMap(objects, editor_width);
return;
@@ -116,20 +116,21 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
map_file.open(file, std::ios::in | std::ios::binary);
uint16_t version;
map_file.read((char *)&version, sizeof(uint16_t) / sizeof(char));
switch(version) {
case 0x01:
loadMapV01(scene, mario, map_file, objects, editor, editor_width, renderer);
break;
default:
throw "Invalid file version";
switch (version) {
case 0x01:
loadMapV01(scene, mario, map_file, objects, editor, editor_width,
renderer);
break;
default:
throw "Invalid file version";
}
}
void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer) {
std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer) {
uint16_t cols;
map_file.read((char *)&cols, sizeof(uint16_t) / sizeof(char));
if (editor) {
@@ -222,14 +223,13 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
if (editor && objects.size() < editor_width) {
objects.resize(editor_width);
}
}
// TODO catch exception in calling func
void saveMap(const std::string &file, std::vector<mapColumnType> &objects) {
std::ofstream output_file;
output_file.open(file, std::ios::out | std::ios::binary);
if(!output_file.is_open()) {
if (!output_file.is_open()) {
throw "Could not open file '" + file + "'";
}
const uint16_t version = FILE_VERSION;