-
Notifications
You must be signed in to change notification settings - Fork 0
/
Savegame.h
83 lines (67 loc) · 1.97 KB
/
Savegame.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
/** @file Savegame.h */
#ifndef KQ_SAVE_GAME_H
#define KQ_SAVE_GAME_H
#include "Common.h"
#include "ExportableToLua.h"
#include <map>
struct lua_State;
/**
* \brief Manages the game data saved.
*
* This class provides read and write access to the saved data.
*/
class Savegame: public ExportableToLua
{
public:
Savegame(MainLoop& main_loop, const std::string& file_name);
~Savegame();
//file state
bool is_empty();
void save();
const std::string& get_file_name();
//data
bool is_string(const std::string& key);
const std::string& get_string(const std::string& key);
void set_string(const std::string& key, const std::string& value);
bool is_integer(const std::string& key);
int get_integer(const std::string& key);
void set_integer(const std::string& key, int value);
bool is_boolean(const std::string& key);
bool get_boolean(const std::string& key);
void set_boolean(const std::string& key, bool value);
void unset(const std::string& key);
// unsaved data
MainLoop& get_main_loop();
LuaContext& get_lua_context();
//Equipment& get_equipment();
Game* get_game();
void set_game(Game* game);
void notify_game_started();
void notify_game_finished();
virtual const std::string& get_lua_type_name() const;
private:
struct SavedValue
{
enum
{
VALUE_STRING,
VALUE_INTEGER,
VALUE_BOOLEAN
} type;
std::string string_data;
int int_data; //Also used for boolean
};
std::map<std::string, SavedValue> saved_values;
bool empty;
std::string file_name; /**< Savegame file name relative to the quest write directory. */
std::string prefixed_file_name; /**< Savegame file name relative to the engine write directory. */
MainLoop& main_loop;
//Equipment equipment;
Game* game; /**< NULL if this savegame is not currently running */
void load();
static int l_newindex(lua_State* l);
void set_initial_values();
void set_default_keyboard_controls();
void set_default_joypad_controls();
};
#endif