/
saveslots.h
164 lines (137 loc) · 4.96 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
/** @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/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:
/// 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 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;
/**
* Returns the name of the saved session, bound to the logical save slot.
* @see savePath()
*/
inline de::String const saveName() const { return savePath().fileNameWithoutExtension(); }
/**
* 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);
private:
friend class SaveSlots;
void setSavedSession(de::game::SavedSession *newSession);
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 const &id, bool userWritable, de::String const &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 slotId is interpretable as a logical slot identifier.
*/
bool has(de::String const &slotId) const;
/// @see slot()
inline Slot &operator [] (de::String const &slotId) {
return slot(slotId);
}
/**
* Returns the logical save slot associated with @a slotId.
*
* @see has()
*/
Slot &slot(de::String const &slotId) const;
/**
* Returns the logical save slot associated with the saved session @a name specified.
*/
Slot *slotBySaveName(de::String const &name) const;
/**
* Returns the logical save slot associated with the @em first saved session with the
* user @a description specified.
*/
Slot *slotBySavedUserDescription(de::String const &description) 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