Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SavedGame.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 
18 #ifndef INCLUDED_SAVEDGAME
19 #define INCLUDED_SAVEDGAME
20 
21 class CSimulation2;
22 class ScriptInterface;
23 class CScriptValRooted;
24 class CGUIManager;
25 
26 /**
27  * @file
28  * Contains functions for managing saved game archives.
29  *
30  * A saved game is simply a zip archive with the extension '0adsave'
31  * and containing two files:
32  * <ul>
33  * <li>metadata.json - JSON data file containing the game metadata</li>
34  * <li>simulation.dat - the serialized simulation state data</li>
35  * </ul>
36  */
37 
38 namespace SavedGames
39 {
40 
41 /**
42  * Create new saved game archive with given name and simulation data
43  *
44  * @param name Name to save the game with
45  * @param description A user-given description of the save
46  * @param simulation
47  * @param gui if not NULL, store some UI-related data with the saved game
48  * @param playerID ID of the player who saved this file
49  * @return INFO::OK if successfully saved, else an error Status
50  */
51 Status Save(const std::wstring& name, const std::wstring& description, CSimulation2& simulation, CGUIManager* gui, int playerID);
52 
53 /**
54  * Create new saved game archive with given prefix and simulation data
55  *
56  * @param prefix Create new numbered file starting with this prefix
57  * @param description A user-given description of the save
58  * @param simulation
59  * @param gui if not NULL, store some UI-related data with the saved game
60  * @param playerID ID of the player who saved this file
61  * @return INFO::OK if successfully saved, else an error Status
62  */
63 Status SavePrefix(const std::wstring& prefix, const std::wstring& description, CSimulation2& simulation, CGUIManager* gui, int playerID);
64 
65 /**
66  * Load saved game archive with the given name
67  *
68  * @param name filename of saved game (without path or extension)
69  * @param scriptInterface
70  * @param[out] metadata object containing metadata associated with saved game,
71  * parsed from metadata.json inside the archive.
72  * @param[out] savedState serialized simulation state stored as string of bytes,
73  * loaded from simulation.dat inside the archive.
74  * @return INFO::OK if successfully loaded, else an error Status
75  */
76 Status Load(const std::wstring& name, ScriptInterface& scriptInterface, CScriptValRooted& metadata, std::string& savedState);
77 
78 /**
79  * Get list of saved games for GUI script usage
80  *
81  * @param scriptInterface the ScriptInterface in which to create the return data.
82  * @return list of objects containing saved game data
83  */
84 std::vector<CScriptValRooted> GetSavedGames(ScriptInterface& scriptInterface);
85 
86 /**
87  * Permanently deletes the saved game archive with the given name
88  *
89  * @param name filename of saved game (without path or extension)
90  * @return true if deletion was successful, or false on error
91  */
92 bool DeleteSavedGame(const std::wstring& name);
93 
94 }
95 
96 #endif // INCLUDED_SAVEDGAME
std::vector< CScriptValRooted > GetSavedGames(ScriptInterface &scriptInterface)
Get list of saved games for GUI script usage.
Definition: SavedGame.cpp:175
bool DeleteSavedGame(const std::wstring &name)
Permanently deletes the saved game archive with the given name.
Definition: SavedGame.cpp:224
Status Save(const std::wstring &name, const std::wstring &description, CSimulation2 &simulation, CGUIManager *gui, int playerID)
Create new saved game archive with given name and simulation data.
Definition: SavedGame.cpp:50
static CStr prefix
Definition: DllLoader.cpp:47
Public API for simulation system.
Definition: Simulation2.h:46
Status SavePrefix(const std::wstring &prefix, const std::wstring &description, CSimulation2 &simulation, CGUIManager *gui, int playerID)
Create new saved game archive with given prefix and simulation data.
Definition: SavedGame.cpp:35
i64 Status
Error handling system.
Definition: status.h:171
Status Load(const std::wstring &name, ScriptInterface &scriptInterface, CScriptValRooted &metadata, std::string &savedState)
Load saved game archive with the given name.
Definition: SavedGame.cpp:152
Abstraction around a SpiderMonkey JSContext.
External interface to the GUI system.
Definition: GUIManager.h:45