This repository has been archived on 2026-04-30. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Tortuga/common/map_loader.cpp
T
Kayne Ruse 88aee0f4f5 Created the loadGameMap() function, still incomplete
Although the overall logic of this function is finished, I still need to
write the callbacks for RegionPager's onNew and onDelete.

I've also tested this using a hand written save/index file. I've written
up a map file format by hand, and I'll be implementing it over the next
few commits.
2013-10-14 21:12:09 +11:00

79 lines
2.1 KiB
C++

#include "map_loader.hpp"
#include "utility.hpp"
#include <fstream>
#include <stdexcept>
void loadGameMap(std::string mapPathName, RegionPager* pager, std::list<TileSheet>* sheetList) {
//open the index file
std::ifstream indexFile(mapPathName + "\\index");
if (!indexFile.is_open()) {
throw(std::runtime_error(std::string("Failed to open game map: ") + mapPathName));
}
//read each part of the metadata header
std::string buffer, knownName;
int sheetCount = -1, rangeEnd = -1, regionWidth = -1, regionHeight = -1;
getline(indexFile, knownName);
if (knownName != truncatePath(mapPathName)) {
//probably not needed, I'll losen this down the road
throw(std::runtime_error("Internal and external map names do not match"));
}
getline(indexFile, buffer, ',');
sheetCount = to_integer_custom(buffer);
getline(indexFile, buffer, ',');
rangeEnd = to_integer_custom(buffer);
getline(indexFile, buffer, ',');
regionWidth = to_integer_custom(buffer);
getline(indexFile, buffer);
regionHeight = to_integer_custom(buffer);
//setup the pager
pager->GetRegions()->clear();
pager->SetWidth(regionWidth);
pager->SetHeight(regionHeight);
pager->SetOnNew([](Region* const ptr) {
//TODO
});
pager->SetOnDelete([](Region* const ptr) {
//TODO
});
//load all of the tile sheets
sheetList->clear();
for (int i = 0; i < sheetCount; i++) {
sheetList->push_back(TileSheet());
//get the name, width & height
std::string sheetName;
getline(indexFile, sheetName, ',');
getline(indexFile, buffer, ',');
int w = to_integer_custom(buffer);
getline(indexFile, buffer, ',');
int h = to_integer_custom(buffer);
//load
sheetList->back().LoadSurface(std::string("rsc\\graphics\\tilesets\\") + sheetName, w, h);
//set the range
getline(indexFile, buffer, ',');
sheetList->back().SetBegin(to_integer_custom(buffer));
getline(indexFile, buffer);
sheetList->back().SetEnd(to_integer_custom(buffer));
}
TileSheet::SetRangeEnd(rangeEnd);
//clean up
indexFile.close();
}
void saveGameMap(std::string mapPathName, RegionPager* pager, std::list<TileSheet>* sheetList) {
//TODO
}