| 551 | } |
| 552 | |
| 553 | bool writeGameMapToFile(const std::string& fileName, GameMap& gameMap) |
| 554 | { |
| 555 | std::ofstream levelFile(fileName.c_str(), std::ifstream::out); |
| 556 | |
| 557 | // This is better than checking for .bad(), as it checks every error flags. |
| 558 | if (!levelFile.good()) { |
| 559 | OD_LOG_WRN("Couldn't open file for writing: " + fileName); |
| 560 | return false; |
| 561 | } |
| 562 | |
| 563 | // Write the identifier string and the version number |
| 564 | levelFile << ODApplication::VERSIONSTRING |
| 565 | << " # The version of OpenDungeons which created this file (for compatibility reasons).\n"; |
| 566 | |
| 567 | // Write map info |
| 568 | levelFile << "\n[Info]\n"; |
| 569 | levelFile << "Name\t" << (gameMap.getLevelName().empty() ? "No name" : gameMap.getLevelName()) << std::endl; |
| 570 | if (!gameMap.getLevelDescription().empty()) |
| 571 | levelFile << "Description\t" << gameMap.getLevelDescription() << std::endl; |
| 572 | if (!gameMap.getLevelMusicFile().empty()) |
| 573 | levelFile << "Music\t" << gameMap.getLevelMusicFile() << std::endl; |
| 574 | if (!gameMap.getLevelFightMusicFile().empty()) |
| 575 | levelFile << "FightMusic\t" << gameMap.getLevelFightMusicFile() << std::endl; |
| 576 | if(!gameMap.getTileSetName().empty()) |
| 577 | levelFile << "TileSet\t" << gameMap.getTileSetName() << std::endl; |
| 578 | |
| 579 | levelFile << "[/Info]" << std::endl; |
| 580 | |
| 581 | // Write out the seats to the file |
| 582 | levelFile << "\n[Seats]\n"; |
| 583 | const std::vector<Seat*> seats = gameMap.getSeats(); |
| 584 | for (Seat* seat : seats) |
| 585 | { |
| 586 | // We don't save rogue seat |
| 587 | if(seat->isRogueSeat()) |
| 588 | continue; |
| 589 | |
| 590 | levelFile << "[Seat]" << std::endl; |
| 591 | seat->exportSeatToStream(levelFile); |
| 592 | levelFile << "[/Seat]" << std::endl; |
| 593 | } |
| 594 | levelFile << "[/Seats]" << std::endl; |
| 595 | |
| 596 | // Write out the goals shared by all players to the file. |
| 597 | levelFile << "\n[Goals]\n"; |
| 598 | levelFile << "# " << Goal::getFormat() << "\n"; |
| 599 | for (auto& goal : gameMap.getGoalsForAllSeats()) |
| 600 | { |
| 601 | levelFile << *goal.get(); |
| 602 | } |
| 603 | levelFile << "[/Goals]" << std::endl; |
| 604 | |
| 605 | levelFile << "\n[Tiles]\n"; |
| 606 | int mapSizeX = gameMap.getMapSizeX(); |
| 607 | int mapSizeY = gameMap.getMapSizeY(); |
| 608 | levelFile << "# Map Size" << std::endl; |
| 609 | levelFile << mapSizeX << " # MapSizeX" << std::endl; |
| 610 | levelFile << mapSizeY << " # MapSizeY" << std::endl; |
no test coverage detected