Pyrogenesis  trunk
VisualReplay.h
Go to the documentation of this file.
1 /* Copyright (C) 2021 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_VISUAL_REPLAY
19 #define INCLUDED_VISUAL_REPLAY
20 
21 #include "lib/os_path.h"
22 #include "ps/CStrForward.h"
24 
25 class ScriptInterface;
26 
27 /**
28  * Contains functions for visually replaying past games.
29  */
30 namespace VisualReplay
31 {
32 
33 /**
34  * Returns the absolute path to the sim-log directory (that contains the directories with the replay files.
35  */
37 
38 /**
39  * Returns the absolute path to the replay cache file.
40  */
42 
43 /**
44  * Returns the absolute path to the temporary replay cache file used to
45  * always have a valid cache file in place even if bad things happen.
46  */
48 
49 /**
50  * Replays the commands.txt file in the given subdirectory visually.
51  */
52 bool StartVisualReplay(const OsPath& directory);
53 
54 /**
55  * Reads the replay Cache file and parses it into a jsObject
56  *
57  * @param scriptInterface - the ScriptInterface in which to create the return data.
58  * @param cachedReplaysObject - the cached replays.
59  * @return true on succes
60  */
61 bool ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject);
62 
63 /**
64  * Stores the replay list in the replay cache file
65  *
66  * @param scriptInterface - the ScriptInterface in which to create the return data.
67  * @param replays - the replay list to store.
68  */
69 void StoreCacheFile(const ScriptInterface& scriptInterface, JS::HandleObject replays);
70 
71 /**
72  * Load the replay cache and check if there are new/deleted replays. If so, update the cache.
73  *
74  * @param scriptInterface - the ScriptInterface in which to create the return data.
75  * @param compareFiles - compare the directory name and the FileSize of the replays and the cache.
76  * @return cache entries
77  */
78 JS::HandleObject ReloadReplayCache(const ScriptInterface& scriptInterface, bool compareFiles);
79 
80 /**
81  * Get a list of replays to display in the GUI.
82  *
83  * @param scriptInterface - the ScriptInterface in which to create the return data.
84  * @param compareFiles - reload the cache, which takes more time,
85  * but nearly ensures, that no changed replay is missed.
86  * @return array of objects containing replay data
87  */
88 JS::Value GetReplays(const ScriptInterface& scriptInterface, bool compareFiles);
89 
90 /**
91  * Parses a commands.txt file and extracts metadata.
92  * Works similarly to CGame::LoadReplayData().
93  */
94 JS::Value LoadReplayData(const ScriptInterface& scriptInterface, const OsPath& directory);
95 
96 /**
97  * Permanently deletes the visual replay (including the parent directory)
98  *
99  * @param replayFile - path to commands.txt, whose parent directory will be deleted.
100  * @return true if deletion was successful, false on error
101  */
102 bool DeleteReplay(const OsPath& replayFile);
103 
104 /**
105  * Returns the parsed header of the replay file (commands.txt).
106  */
107 JS::Value GetReplayAttributes(const ScriptInterface& scriptInterface, const OsPath& directoryName);
108 
109 /**
110  * Returns whether or not the metadata / summary screen data has been saved properly when the game ended.
111  */
112 bool HasReplayMetadata(const OsPath& directoryName);
113 
114 /**
115  * Returns the metadata of a replay.
116  */
117 JS::Value GetReplayMetadata(const ScriptInterface& scriptInterface, const OsPath& directoryName);
118 
119 /**
120 * Adds a replay to the replayCache.
121 */
122 void AddReplayToCache(const ScriptInterface& scriptInterface, const CStrW& directoryName);
123 }
124 
125 #endif
void AddReplayToCache(const ScriptInterface &scriptInterface, const CStrW &directoryName)
Adds a replay to the replayCache.
Definition: VisualReplay.cpp:459
Contains functions for visually replaying past games.
Definition: VisualReplay.h:30
JS::Value LoadReplayData(const ScriptInterface &scriptInterface, const OsPath &directory)
Parses a commands.txt file and extracts metadata.
Definition: VisualReplay.cpp:341
void StoreCacheFile(const ScriptInterface &scriptInterface, JS::HandleObject replays)
Stores the replay list in the replay cache file.
Definition: VisualReplay.cpp:102
OsPath GetCacheFilePath()
Returns the absolute path to the replay cache file.
Definition: VisualReplay.cpp:52
JS::HandleObject ReloadReplayCache(const ScriptInterface &scriptInterface, bool compareFiles)
Load the replay cache and check if there are new/deleted replays.
Definition: VisualReplay.cpp:116
bool HasReplayMetadata(const OsPath &directoryName)
Returns whether or not the metadata / summary screen data has been saved properly when the game ended...
Definition: VisualReplay.cpp:479
OsPath GetTempCacheFilePath()
Returns the absolute path to the temporary replay cache file used to always have a valid cache file i...
Definition: VisualReplay.cpp:57
bool ReadCacheFile(const ScriptInterface &scriptInterface, JS::MutableHandleObject cachedReplaysObject)
Reads the replay Cache file and parses it into a jsObject.
Definition: VisualReplay.cpp:77
Config::Value_type Value
Definition: json_spirit_value.h:182
Definition: path.h:79
JS::Value GetReplays(const ScriptInterface &scriptInterface, bool compareFiles)
Get a list of replays to display in the GUI.
Definition: VisualReplay.cpp:236
OsPath GetDirectoryPath()
Returns the absolute path to the sim-log directory (that contains the directories with the replay fil...
Definition: VisualReplay.cpp:47
bool StartVisualReplay(const OsPath &directory)
Replays the commands.txt file in the given subdirectory visually.
Definition: VisualReplay.cpp:62
JS::Value GetReplayAttributes(const ScriptInterface &scriptInterface, const OsPath &directoryName)
Returns the parsed header of the replay file (commands.txt).
Definition: VisualReplay.cpp:435
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
bool DeleteReplay(const OsPath &replayFile)
Permanently deletes the visual replay (including the parent directory)
Definition: VisualReplay.cpp:426
JS::Value GetReplayMetadata(const ScriptInterface &scriptInterface, const OsPath &directoryName)
Returns the metadata of a replay.
Definition: VisualReplay.cpp:492