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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef _LOAD_SAVE_HANDLER_H
#define _LOAD_SAVE_HANDLER_H
#include <string>
struct SaveFileData {
std::string name; // "saves/quicksave.ssf"
std::string args; // "-y"
};
class ILoadSaveHandler
{
public:
static ILoadSaveHandler* CreateHandler(const std::string& saveFile);
static bool CreateSave(const std::string& saveFile, const std::string& saveArgs);
static bool CreateSave(SaveFileData fileData) {
if (fileData.name.empty())
return false;
return (CreateSave(fileData.name, fileData.args));
}
protected:
static std::string FindSaveFile(const std::string& file);
public:
virtual ~ILoadSaveHandler() = default;
virtual void SaveGame(const std::string& file) = 0;
/// load scriptText and (for creg saves) {map,mod}Name needed to fire up the engine
virtual bool LoadGameStartInfo(const std::string& file) = 0;
virtual void LoadGame() = 0;
void SaveInfo(const std::string& _mapName, const std::string& _modName) {
mapName = _mapName;
modName = _modName;
}
const std::string& GetScriptText() const { return scriptText; }
protected:
std::string scriptText;
std::string mapName;
std::string modName;
};
class DummyLoadSaveHandler: public ILoadSaveHandler {
public:
void SaveGame(const std::string& file) override {}
bool LoadGameStartInfo(const std::string& file) override { return false; }
void LoadGame() override {}
};
extern SaveFileData globalSaveFileData;
#endif // _LOAD_SAVE_HANDLER_H
|