/
saveslots.h
190 lines (159 loc) · 5.67 KB
/
saveslots.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/** @file saveslots.h Map of logical game save slots.
*
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2005-2013 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#ifndef LIBCOMMON_SAVESLOTS_H
#define LIBCOMMON_SAVESLOTS_H
#include <de/Error>
#include <de/game/SavedSession>
#include <de/Path>
#include <de/String>
/**
* Maps save-game session file names into a finite set of "save slots".
*
* @ingroup libcommon
*/
class SaveSlots
{
public:
/// A missing/unknown slot was referenced. @ingroup errors
DENG2_ERROR(MissingSlotError);
/**
* Logical save slot.
*/
class Slot
{
public:
/// No SavedSession exists for the logical save slot. @ingroup errors
DENG2_ERROR(MissingSessionError);
/// Logical saved session status:
enum SessionStatus {
Loadable,
Incompatible,
Unused
};
public:
Slot(de::String id, bool userWritable, de::String savePath, int menuWidgetId = 0);
/**
* Returns the logical status of the saved session associated with the logical save slot.
*/
SessionStatus sessionStatus() const;
inline bool isLoadable() const { return sessionStatus() == Loadable; }
inline bool isIncompatible() const { return sessionStatus() == Incompatible; }
inline bool isUnused() const { return sessionStatus() == Unused; }
/**
* Returns @c true iff the logical save slot is user-writable.
*/
bool isUserWritable() const;
/**
* Returns @c true iff a saved game session exists for the logical save slot.
*/
bool hasSavedSession() const;
/**
* Convenient method for determining whether a loadable saved session exists for the
* logical save slot.
*
* @see hasSavedSession(), isLoadable()
*/
inline bool hasLoadableSavedSession() const {
return hasSavedSession() && isLoadable();
}
/**
* Returns the saved session for the logical save slot.
*/
de::game::SavedSession &savedSession() const;
/**
* Change the saved session linked with the logical save slot. It is not usually
* necessary to call this.
*
* @param newSession New SavedSession to apply. Use @c 0 to clear.
*/
void setSavedSession(de::game::SavedSession *newSession);
/**
* Copies the saved session from the @a source slot.
*/
void copySavedSession(Slot const &source);
/**
* Returns the unique identifier/name for the logical save slot.
*/
de::String const &id() const;
/**
* Returns the absolute path of the saved session, bound to the logical save slot.
*/
de::String const &savePath() const;
/**
* Change the absolute path of the saved session, bound to the logical save slot.
*
* @param newPath New absolute path of the saved session to bind to.
*/
void bindSavePath(de::String newPath);
/**
* Deletes the saved session linked to the logical save slot (if any).
*/
void clear();
private:
DENG2_PRIVATE(d)
};
public:
SaveSlots();
/**
* Add a new logical save slot.
*
* @param id Unique identifier for this slot.
* @param userWritable @c true= allow the user to write to this slot.
* @param repositoryPath Relative path in the repository to bind to this slot.
* @param menuWidgetId Unique identifier of the game menu widget to associate this slot with.
* Use @c 0 for none.
*/
void add(de::String id, bool userWritable, de::String savePath, int menuWidgetId = 0);
/**
* Returns the total number of logical save slots.
*/
int count() const;
/// @copydoc count()
inline int size() const { return count(); }
/**
* Returns @c true iff @a value is interpretable as a logical slot identifier.
*/
bool has(de::String value) const;
/// @see slot()
inline Slot &operator [] (de::String slotId) {
return slot(slotId);
}
/**
* Returns the logical save slot associated with @a slotId.
*
* @see has()
*/
Slot &slot(de::String slotId) const;
/**
* Returns the logical save slot associated with the given saved @a session.
*/
Slot *slot(de::game::SavedSession const *session) const;
/**
* Register the console commands and variables of this module.
*
* - game-save-last-slot Last-used slot. Can be @c -1 (not set).
* - game-save-quick-slot Nominated quick-save slot. Can be @c -1 (not set).
*/
static void consoleRegister();
private:
DENG2_PRIVATE(d)
};
typedef SaveSlots::Slot SaveSlot;
#endif // LIBCOMMON_SAVESLOTS_H