Skip to content

Commit

Permalink
libcommon|GameSessionWriter: Add brief header and generally prettify …
Browse files Browse the repository at this point in the history
….save package Info files

As of this commit, saving the game is once again possible (in Doom
at least) and a new .save package is written to the repository.

Todo: Verify all state file output matches expected input.
Todo: Check the other games.
  • Loading branch information
danij-deng committed Mar 21, 2014
1 parent e2c8a6f commit 68a7408
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/mapstatewriter.h
Expand Up @@ -36,7 +36,7 @@ class MapStateWriter
MapStateWriter();

/**
* Serialize the map state using the specified @a reader.
* Serialize the @em current map state using the specified @a writer.
*
* @param excludePlayers @c true= Do not include players in the ThingArchive.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/g_game.cpp
Expand Up @@ -3002,10 +3002,10 @@ void G_DoLeaveMap()
// SaveSlot &sslot = G_SaveSlots()["base"];
de::Path const mapStateFilePath(Str_Text(Uri_Compose(gameMapUri)));

if(!SV_OpenFileForWrite(mapStateFilePath))
/*if(!SV_OpenFileForWrite(mapStateFilePath))
{
throw de::Error("G_DoLeaveMap", "Failed opening \"" + de::NativePath(mapStateFilePath).pretty() + "\" for write");
}
}*/

Writer *writer = SV_NewWriter();
MapStateWriter().write(writer, true/*exclude players*/);
Expand Down
22 changes: 21 additions & 1 deletion doomsday/plugins/common/src/gamesessionwriter.cpp
Expand Up @@ -28,6 +28,7 @@
#include <de/App>
#include <de/NativeFile>
#include <de/PackageFolder>
#include <de/Time>
#include <de/Writer>
#include <de/ZipArchive>

Expand All @@ -39,6 +40,24 @@ DENG2_PIMPL_NOREF(GameSessionWriter)
{
SavedSession &session; // Saved session to be updated. Not owned.
Instance(SavedSession &session) : session(session) {}

String composeInfo(SessionMetadata const &metadata) const
{
String info;
QTextStream os(&info);
os.setCodec("UTF-8");

// Write header and misc info.
Time now;
os << "# Doomsday Engine saved game session package.\n#"
<< "\n# Generator: GameSessionWriter (libcommon)"
<< "\n# Generation Date: " + now.asDateTime().toString(Qt::SystemLocaleShortDate);

// Write metadata.
os << "\n\n" + metadata.asTextWithInfoSyntax() + "\n";

return info;
}
};

GameSessionWriter::GameSessionWriter(SavedSession &session)
Expand All @@ -59,7 +78,7 @@ void GameSessionWriter::write(String const &userDescription)

// Write the Info file for this .save package.
ZipArchive arch;
arch.add("Info", metadata->asTextWithInfoSyntax().toUtf8());
arch.add("Info", d->composeInfo(*metadata).toUtf8());

#if __JHEXEN__
// Serialize the world ACScript state.
Expand All @@ -84,6 +103,7 @@ void GameSessionWriter::write(String const &userDescription)

File &outFile = App::rootFolder().locate<Folder>("/savegame").replaceFile(d->session.path() + ".save");
de::Writer(outFile) << arch;
outFile.flush();
LOG_MSG("Wrote ") << outFile.as<NativeFile>().nativePath().pretty();

delete metadata;
Expand Down

0 comments on commit 68a7408

Please sign in to comment.