From 6fc8570cf4050e83d5fbd00fa96bcb50ba581cd1 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 17 Oct 2013 23:10:43 +1100 Subject: [PATCH] Added the saving function --- common/map_loader.cpp | 24 +++++++++++++++++++++++- editor/editor_scene.cpp | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/common/map_loader.cpp b/common/map_loader.cpp index 34fae2a..01327fb 100644 --- a/common/map_loader.cpp +++ b/common/map_loader.cpp @@ -75,5 +75,27 @@ void loadGameMap(std::string mapPathName, RegionPager* pager, std::list* 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(); } \ No newline at end of file diff --git a/editor/editor_scene.cpp b/editor/editor_scene.cpp index 1d0fb64..6b8e340 100644 --- a/editor/editor_scene.cpp +++ b/editor/editor_scene.cpp @@ -66,6 +66,7 @@ EditorScene::EditorScene() { // sheetList.front().LoadSurface("rsc\\graphics\\tilesets\\terrain.bmp", 32, 32); loadGameMap("rsc\\maps\\mappy", &pager, &sheetList); + saveGameMap("rsc\\maps\\foo", &pager, &sheetList); cout << "Region Width: " << pager.GetWidth() << endl; cout << "Region Height: " << pager.GetHeight() << endl;