Added the saving function
This commit is contained in:
+23
-1
@@ -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();
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user