aboutsummaryrefslogtreecommitdiff
path: root/engines/savestate.h
blob: e91cc9c78d4fd2eae6ef9cf7ea051c8f1a35a927 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#ifndef ENGINES_SAVESTATE_H
#define ENGINES_SAVESTATE_H

#include "common/array.h"
#include "common/str.h"
#include "common/ptr.h"

namespace Graphics {
struct Surface;
}

/**
 * Object describing a save state.
 *
 * This at least includes the save slot number and a human readable
 * description of the save state.
 *
 * Further possibilites are a thumbnail, play time, creation date,
 * creation time, delete protected, write protection.
 *
 * Saves are writable and deletable by default.
 */
class SaveStateDescriptor {
public:
	SaveStateDescriptor();
	SaveStateDescriptor(int s, const Common::String &d);

	/**
	 * @param slot The saveslot id, as it would be passed to the "-x" command line switch.
	 */
	void setSaveSlot(int slot) { _slot = slot; }

	/**
	 * @return The saveslot id, as it would be passed to the "-x" command line switch.
	 */
	int getSaveSlot() const { return _slot; }

	/**
	 * @param desc A human readable description of the save state.
	 */
	void setDescription(const Common::String &desc) { _description = desc; }

	/**
	 * @return A human readable description of the save state.
	 */
	const Common::String &getDescription() const { return _description; }

	/** Optional entries only included when querying via MetaEngine::querySaveMetaInfo */

	/**
	 * Defines whether the save state is allowed to be deleted.
	 */
	void setDeletableFlag(bool state) { _isDeletable = state; }

	/**
	 * Queries whether the save state is allowed to be deleted.
	 */
	bool getDeletableFlag() const { return _isDeletable; }

	/**
	 * Defines whether the save state is write protected.
	 */
	void setWriteProtectedFlag(bool state) { _isWriteProtected = state; }

	/**
	 * Queries whether the save state is write protected.
	 */
	bool getWriteProtectedFlag() const { return _isWriteProtected; }

	/**
	 * Defines whether the save state is "locked" because is being synced.
	 */
	void setLocked(bool state) {
		_isLocked = state;

		//just in case:
		if (state) {
			setDeletableFlag(false);
			setWriteProtectedFlag(true);
		}
	}

	/**
	* Queries whether the save state is "locked" because is being synced.
	*/
	bool getLocked() const { return _isLocked; }

	/**
	 * Return a thumbnail graphics surface representing the savestate visually.
	 * This is usually a scaled down version of the game graphics. The size
	 * should be either 160x100 or 160x120 pixels, depending on the aspect
	 * ratio of the game. If another ratio is required, contact the core team.
	 */
	const Graphics::Surface *getThumbnail() const { return _thumbnail.get(); }

	/**
	 * Set a thumbnail graphics surface representing the savestate visually.
	 * Ownership of the surface is transferred to the SaveStateDescriptor.
	 * Hence the caller must not delete the surface.
	 */
	void setThumbnail(Graphics::Surface *t);
	void setThumbnail(Common::SharedPtr<Graphics::Surface> t) { _thumbnail = t; }

	/**
	 * Sets the date the save state was created.
	 *
	 * @param year  Year of creation.
	 * @param month Month of creation.
	 * @param day   Day of creation.
	 */
	void setSaveDate(int year, int month, int day);

	/**
	 * Queries a human readable description of the date the save state was created.
	 *
	 * This will return an empty string in case the value is not set.
	 */
	const Common::String &getSaveDate() const { return _saveDate; }

	/**
	 * Sets the time the save state was created.
	 *
	 * @param hour  Hour of creation.
	 * @param min   Minute of creation.
	 */
	void setSaveTime(int hour, int min);

	/**
	 * Queries a human readable description of the time the save state was created.
	 *
	 * This will return an empty string in case the value is not set.
	 */
	const Common::String &getSaveTime() const { return _saveTime; }

	/**
	 * Sets the time the game was played before the save state was created.
	 *
	 * @param hours How many hours the user played the game so far.
	 * @param minutes   How many minutes the user played the game so far.
	 */
	void setPlayTime(int hours, int minutes);

	/**
	 * Sets the time the game was played before the save state was created.
	 *
	 * @param msecs How many milliseconds the user played the game so far.
	 */
	void setPlayTime(uint32 msecs);

	/**
	 * Queries a human readable description of the time the game was played
	 * before the save state was created.
	 *
	 * This will return an empty string in case the value is not set.
	 */
	const Common::String &getPlayTime() const { return _playTime; }

	/**
	 * Returns the time the game was played before the save state was created
	 * in milliseconds.
	 *
	 * It defaults to 0.
	 */
	uint32 getPlayTimeMSecs() const { return _playTimeMSecs; }

private:
	/**
	 * The saveslot id, as it would be passed to the "-x" command line switch.
	 */
	int _slot;

	/**
	 * A human readable description of the save state.
	 */
	Common::String _description;

	/**
	 * Whether the save state can be deleted.
	 */
	bool _isDeletable;

	/**
	 * Whether the save state is write protected.
	 */
	bool _isWriteProtected;

	/**
	 * Whether the save state is "locked" because is being synced.
	 */
	bool _isLocked;

	/**
	 * Human readable description of the date the save state was created.
	 */
	Common::String _saveDate;

	/**
	 * Human readable description of the time the save state was created.
	 */
	Common::String _saveTime;

	/**
	 * Human readable description of the time the game was played till the
	 * save state was created.
	 */
	Common::String _playTime;

	/**
	 * The time the game was played before the save state was created
	 * in milliseconds.
	 */
	uint32 _playTimeMSecs;

	/**
	 * The thumbnail of the save state.
	 */
	Common::SharedPtr<Graphics::Surface> _thumbnail;
};

/** List of savestates. */
typedef Common::Array<SaveStateDescriptor> SaveStateList;

/**
 * Comparator object to compare SaveStateDescriptor's based on slot.
 */
struct SaveStateDescriptorSlotComparator {
	bool operator()(const SaveStateDescriptor &x, const SaveStateDescriptor &y) const {
		return x.getSaveSlot() < y.getSaveSlot();
	}
};

#endif