Added the saving function

This commit is contained in:
Kayne Ruse
2013-10-17 23:10:43 +11:00
parent 0bfd916df4
commit 6fc8570cf4
2 changed files with 24 additions and 1 deletions
+23 -1
View File
@@ -75,5 +75,27 @@ void loadGameMap(std::string mapPathName, RegionPager* pager, std::list<TileShee
} }
void saveGameMap(std::string mapPathName, RegionPager* pager, std::list<TileSheet>* sheetList) { void saveGameMap(std::string mapPathName, RegionPager* pager, std::list<TileSheet>* sheetList) {
//TODO //open the index file
std::ofstream indexFile(mapPathName + "\\index");
if (!indexFile.is_open()) {
throw(std::runtime_error(std::string("Failed to open game map: ") + mapPathName));
}
//write each part of the metadata header
indexFile << truncatePath(mapPathName) << std::endl;
indexFile << sheetList->size() << ", ";
indexFile << TileSheet::GetRangeEnd() << ", ";
indexFile << pager->GetWidth() << ", ";
indexFile << pager->GetHeight() << std::endl;
//write each tile sheet's data
for (auto& it : *sheetList) {
indexFile << it.GetName() << ", ";
indexFile << it.GetImage()->GetClipW() << ", ";
indexFile << it.GetImage()->GetClipH() << ", ";
indexFile << it.GetBegin() << ", ";
indexFile << it.GetEnd() << std::endl;
}
indexFile.close();
} }
+1
View File
@@ -66,6 +66,7 @@ EditorScene::EditorScene() {
// sheetList.front().LoadSurface("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32); // sheetList.front().LoadSurface("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32);
loadGameMap("rsc\\maps\\mappy", &pager, &sheetList); loadGameMap("rsc\\maps\\mappy", &pager, &sheetList);
saveGameMap("rsc\\maps\\foo", &pager, &sheetList);
cout << "Region Width: " << pager.GetWidth() << endl; cout << "Region Width: " << pager.GetWidth() << endl;
cout << "Region Height: " << pager.GetHeight() << endl; cout << "Region Height: " << pager.GetHeight() << endl;