1 /* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_SAVEDGAME
19 #define INCLUDED_SAVEDGAME
22 #include "scriptinterface/StructuredClone.h"
28 * Contains functions for managing saved game archives.
30 * A saved game is simply a zip archive with the extension '0adsave'
31 * and containing two files:
33 * <li>metadata.json - JSON data file containing the game metadata</li>
34 * <li>simulation.dat - the serialized simulation state data</li>
41 * Create new saved game archive with given name and simulation data
43 * @param name Name to save the game with
44 * @param description A user-given description of the save
46 * @param guiMetadataClone if not NULL, store some UI-related data with the saved game
47 * @return INFO::OK if successfully saved, else an error Status
49 Status
Save(const CStrW
& name
, const CStrW
& description
, CSimulation2
& simulation
, const Script::StructuredClone
& guiMetadataClone
);
52 * Create new saved game archive with given prefix and simulation data
54 * @param prefix Create new numbered file starting with this prefix
55 * @param description A user-given description of the save
57 * @param guiMetadataClone if not NULL, store some UI-related data with the saved game
58 * @return INFO::OK if successfully saved, else an error Status
60 Status
SavePrefix(const CStrW
& prefix
, const CStrW
& description
, CSimulation2
& simulation
, const Script::StructuredClone
& guiMetadataClone
);
63 * Load saved game archive with the given name
65 * @param name filename of saved game (without path or extension)
66 * @param scriptInterface
67 * @param[out] metadata object containing metadata associated with saved game,
68 * parsed from metadata.json inside the archive.
69 * @param[out] savedState serialized simulation state stored as string of bytes,
70 * loaded from simulation.dat inside the archive.
71 * @return INFO::OK if successfully loaded, else an error Status
73 Status
Load(const std::wstring
& name
, const ScriptInterface
& scriptInterface
, JS::MutableHandleValue metadata
, std::string
& savedState
);
76 * Get list of saved games for GUI script usage
78 * @param scriptInterface the ScriptInterface in which to create the return data.
79 * @return array of objects containing saved game data
81 JS::Value
GetSavedGames(const ScriptInterface
& scriptInterface
);
84 * Permanently deletes the saved game archive with the given name
86 * @param name filename of saved game (without path or extension)
87 * @return true if deletion was successful, or false on error
89 bool DeleteSavedGame(const std::wstring
& name
);
92 #endif // INCLUDED_SAVEDGAME