Start of multiple save support.
This commit is contained in:
parent
c39974e2a7
commit
32949a192c
|
@ -91,6 +91,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#define MAX_SND_CHANNELS 64
|
#define MAX_SND_CHANNELS 64
|
||||||
|
|
||||||
|
#define MAX_SAVE_SLOTS 5
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
ET_NONE,
|
ET_NONE,
|
||||||
|
|
|
@ -270,7 +270,7 @@ void loadGame(void)
|
||||||
Tuple *t;
|
Tuple *t;
|
||||||
Trophy *trophy;
|
Trophy *trophy;
|
||||||
|
|
||||||
sprintf(filename, "%s/game.json", app.saveDir);
|
sprintf(filename, "%s/%d/game.json", app.saveDir, game.saveSlot);
|
||||||
|
|
||||||
if (fileExists(filename))
|
if (fileExists(filename))
|
||||||
{
|
{
|
||||||
|
@ -335,7 +335,7 @@ void saveGame(void)
|
||||||
Trophy *trophy;
|
Trophy *trophy;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sprintf(filename, "%s/game.json", app.saveDir);
|
sprintf(filename, "%s/%d/game.json", app.saveDir, game.saveSlot);
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving game to '%s' ...", filename);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving game to '%s' ...", filename);
|
||||||
|
|
||||||
|
@ -388,6 +388,7 @@ void saveGame(void)
|
||||||
if (!writeFile(filename, out))
|
if (!writeFile(filename, out))
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save game");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save game");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
@ -404,7 +405,7 @@ void restoreGameState(void)
|
||||||
char *text, filename[MAX_FILENAME_LENGTH];
|
char *text, filename[MAX_FILENAME_LENGTH];
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
sprintf(filename, "%s/game.json", app.saveDir);
|
sprintf(filename, "%s/%d/game.json", app.saveDir, game.saveSlot);
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Restoring game from '%s' ...", filename);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Restoring game from '%s' ...", filename);
|
||||||
|
|
||||||
|
|
|
@ -24,25 +24,29 @@ void createSaveFolder(void)
|
||||||
{
|
{
|
||||||
char *userHome;
|
char *userHome;
|
||||||
char dir[MAX_FILENAME_LENGTH];
|
char dir[MAX_FILENAME_LENGTH];
|
||||||
|
int i;
|
||||||
|
|
||||||
userHome = getenv("HOME");
|
userHome = getenv("HOME");
|
||||||
|
|
||||||
if (!userHome)
|
if (!userHome)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Unable to determine user save folder.");
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
|
||||||
|
|
||||||
sprintf(dir, "%s/.local/share/blobwarsAttrition", userHome);
|
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
||||||
|
{
|
||||||
|
sprintf(dir, "%s/.local/share/blobwarsAttrition/%d", userHome, i);
|
||||||
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
|
if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
return;
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
|
sprintf(app.saveDir, "%s/.local/share/blobwarsAttrition", userHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createScreenshotFolder(void)
|
void createScreenshotFolder(void)
|
||||||
|
|
|
@ -24,25 +24,29 @@ void createSaveFolder(void)
|
||||||
{
|
{
|
||||||
char *userHome;
|
char *userHome;
|
||||||
char dir[MAX_FILENAME_LENGTH];
|
char dir[MAX_FILENAME_LENGTH];
|
||||||
|
int i;
|
||||||
|
|
||||||
userHome = getenv("USERPROFILE");
|
userHome = getenv("USERPROFILE");
|
||||||
|
|
||||||
if (!userHome)
|
if (!userHome)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir.");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Unable to determine user save folder.");
|
||||||
return;
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome);
|
||||||
|
|
||||||
sprintf(dir, "%s\\blobwarsAttrition", userHome);
|
for (i = 0 ; i < MAX_SAVE_SLOTS ; i++)
|
||||||
|
{
|
||||||
|
sprintf(dir, "%s\\blobwarsAttrition\\%d", userHome, i);
|
||||||
if (mkdir(dir) != 0 && errno != EEXIST)
|
if (mkdir(dir) != 0 && errno != EEXIST)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to create save dir '%s'.", dir);
|
||||||
return;
|
exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH);
|
sprintf(app.saveDir, "%s\\blobwarsAttrition", userHome);
|
||||||
}
|
}
|
||||||
|
|
||||||
void createScreenshotFolder(void)
|
void createScreenshotFolder(void)
|
||||||
|
|
|
@ -369,6 +369,7 @@ typedef struct {
|
||||||
unsigned int stats[STAT_MAX];
|
unsigned int stats[STAT_MAX];
|
||||||
char worldId[MAX_NAME_LENGTH];
|
char worldId[MAX_NAME_LENGTH];
|
||||||
int isComplete;
|
int isComplete;
|
||||||
|
int saveSlot;
|
||||||
Tuple keys[MAX_KEY_TYPES];
|
Tuple keys[MAX_KEY_TYPES];
|
||||||
Tuple missionStatusHead, *missionStatusTail;
|
Tuple missionStatusHead, *missionStatusTail;
|
||||||
Trophy trophyHead, *trophyTail;
|
Trophy trophyHead, *trophyTail;
|
||||||
|
|
|
@ -266,7 +266,7 @@ void saveScreenshot(char *name)
|
||||||
|
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
{
|
{
|
||||||
sprintf(filename, "%s/%s.png", app.saveDir, name);
|
sprintf(filename, "%s/%d/%s.png", app.saveDir, game.saveSlot, name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,4 +26,5 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
extern Dev dev;
|
extern Dev dev;
|
||||||
|
extern Game game;
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ void init18N(int argc, char *argv[])
|
||||||
|
|
||||||
if (languageId >= argc)
|
if (languageId >= argc)
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "You must specify a language to use with -language. Using default.");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "You must specify a language to use with -language. Using default.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,13 +227,15 @@ static void loadConfig(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
cJSON *root, *controlsJSON, *node;
|
cJSON *root, *controlsJSON, *node;
|
||||||
char *text;
|
char *text, filename[MAX_FILENAME_LENGTH];
|
||||||
|
|
||||||
initDefaultConfig();
|
initDefaultConfig();
|
||||||
|
|
||||||
if (fileExists(getSaveFilePath(CONFIG_FILENAME)))
|
sprintf(filename, "%s/%s", app.saveDir, CONFIG_FILENAME);
|
||||||
|
|
||||||
|
if (fileExists(filename))
|
||||||
{
|
{
|
||||||
text = readFile(getSaveFilePath(CONFIG_FILENAME));
|
text = readFile(filename);
|
||||||
|
|
||||||
root = cJSON_Parse(text);
|
root = cJSON_Parse(text);
|
||||||
|
|
||||||
|
@ -281,10 +283,10 @@ static void loadConfig(void)
|
||||||
void saveConfig(void)
|
void saveConfig(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *out, *configFilename;
|
char *out, filename[MAX_FILENAME_LENGTH];
|
||||||
cJSON *root, *controlsJSON, *keysJSON, *joypadJSON;
|
cJSON *root, *controlsJSON, *keysJSON, *joypadJSON;
|
||||||
|
|
||||||
configFilename = getSaveFilePath(CONFIG_FILENAME);
|
sprintf(filename, "%s/%s", app.saveDir, CONFIG_FILENAME);
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving config ...");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving config ...");
|
||||||
|
|
||||||
|
@ -321,9 +323,10 @@ void saveConfig(void)
|
||||||
|
|
||||||
out = cJSON_Print(root);
|
out = cJSON_Print(root);
|
||||||
|
|
||||||
if (!writeFile(configFilename, out))
|
if (!writeFile(filename, out))
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save config");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save config");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
|
|
@ -35,7 +35,6 @@ extern void destroyTextures(void);
|
||||||
extern void expireTexts(int all);
|
extern void expireTexts(int all);
|
||||||
extern int fileExists(const char *filename);
|
extern int fileExists(const char *filename);
|
||||||
extern char *getLookupName(const char *prefix, long num);
|
extern char *getLookupName(const char *prefix, long num);
|
||||||
extern char *getSaveFilePath(const char *filename);
|
|
||||||
extern void initAtlas(void);
|
extern void initAtlas(void);
|
||||||
extern void initBackground(void);
|
extern void initBackground(void);
|
||||||
extern void initEntityFactory(void);
|
extern void initEntityFactory(void);
|
||||||
|
|
|
@ -131,18 +131,6 @@ int writeFile(const char *filename, const char *data)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *getSaveFilePath(const char *filename)
|
|
||||||
{
|
|
||||||
static char path[MAX_FILENAME_LENGTH];
|
|
||||||
memset(path, '\0', MAX_FILENAME_LENGTH);
|
|
||||||
|
|
||||||
sprintf(path, "%s/%s", app.saveDir, filename);
|
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG, "getSaveFilePath = '%s'", path);
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
char **getFileList(const char *dir, int *count)
|
char **getFileList(const char *dir, int *count)
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
|
|
|
@ -24,5 +24,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#include "dirent.h"
|
#include "dirent.h"
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
extern App app;
|
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ void loadWorld(char *id)
|
||||||
world.objectiveTail = &world.objectiveHead;
|
world.objectiveTail = &world.objectiveHead;
|
||||||
world.particleTail = &world.particleHead;
|
world.particleTail = &world.particleHead;
|
||||||
|
|
||||||
sprintf(filename, "%s/%s.json", app.saveDir, id);
|
sprintf(filename, "%s/%d/%s.json", app.saveDir, game.saveSlot, id);
|
||||||
|
|
||||||
if (!game.isComplete && fileExists(filename))
|
if (!game.isComplete && fileExists(filename))
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,7 @@ void saveWorld(void)
|
||||||
cJSON *root;
|
cJSON *root;
|
||||||
char filename[MAX_FILENAME_LENGTH], *out;
|
char filename[MAX_FILENAME_LENGTH], *out;
|
||||||
|
|
||||||
sprintf(filename, "%s/%s.json", app.saveDir, world.id);
|
sprintf(filename, "%s/%d/%s.json", app.saveDir, game.saveSlot, world.id);
|
||||||
|
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving world to '%s' ...", filename);
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Saving world to '%s' ...", filename);
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ void saveWorld(void)
|
||||||
if (!writeFile(filename, out))
|
if (!writeFile(filename, out))
|
||||||
{
|
{
|
||||||
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save world");
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Failed to save world");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON_Delete(root);
|
cJSON_Delete(root);
|
||||||
|
|
|
@ -25,5 +25,6 @@ extern int writeFile(const char *filename, const char *data);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Entity *self;
|
extern Entity *self;
|
||||||
|
extern Game game;
|
||||||
extern World world;
|
extern World world;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue