tr2/game_flow: specify savegame format in game flow

This allows defining the savegame format string in the game flow.
This commit is contained in:
lahm86 2025-03-15 22:25:13 +00:00
parent 0b231c2afa
commit 64fb3d2955
7 changed files with 24 additions and 5 deletions

View file

@ -3,6 +3,7 @@
// Lines starting with double slashes are comments and are ignored.
"main_menu_picture": "data/title.pcx",
"savegame_fmt_legacy": "savegame.%d",
"cmd_init": {"action": "exit_to_title"},
"cmd_title": {"action": "noop"},

View file

@ -2,6 +2,7 @@
// This file is used to enable the -l argument support.
"main_menu_picture": "data/title.pcx",
"savegame_fmt_legacy": "savegame.%d",
"cmd_init": {"action": "exit_to_title"},
"cmd_title": {"action": "noop"},

View file

@ -296,6 +296,11 @@ remains distinct for each game.
<td>String<strong>*</strong></td>
<td>Path to the main menu background image.</td>
</tr>
<tr valign="top">
<td><code>savegame_fmt_legacy</code></td>
<td>String<strong>*</strong></td>
<td>Path pattern to look for the original savegame files.</td>
</tr>
<tr valign="top">
<td><code>secret_track</code></td>
<td>Integer</td>

View file

@ -90,8 +90,8 @@ void GF_Shutdown(void)
}
Memory_FreePointer(&gf->main_menu_background_path);
#if TR_VERSION == 1
Memory_FreePointer(&gf->savegame_fmt_legacy);
#if TR_VERSION == 1
Memory_FreePointer(&gf->savegame_fmt_bson);
#else
Memory_FreePointer(&gf->settings.sfx_path);

View file

@ -124,13 +124,20 @@ static void M_LoadRoot(JSON_OBJECT *const obj, GAME_FLOW *const gf)
gf->settings = m_DefaultSettings;
M_LoadSettings(obj, &gf->settings);
const char *const tmp_s =
const char *tmp_s =
JSON_ObjectGetString(obj, "main_menu_picture", JSON_INVALID_STRING);
if (tmp_s == JSON_INVALID_STRING) {
Shell_ExitSystem("'main_menu_picture' must be a string");
}
gf->main_menu_background_path = Memory_DupStr(tmp_s);
tmp_s =
JSON_ObjectGetString(obj, "savegame_fmt_legacy", JSON_INVALID_STRING);
if (tmp_s == JSON_INVALID_STRING) {
Shell_ExitSystem("'savegame_fmt_legacy' must be a string");
}
gf->savegame_fmt_legacy = Memory_DupStr(tmp_s);
// clang-format off
gf->demo_delay = JSON_ObjectGetInt(obj, "demo_delay", 30);
gf->load_save_disabled = JSON_ObjectGetBool(obj, "load_save_disabled", false);

View file

@ -168,6 +168,11 @@ typedef struct {
GF_COMMAND cmd_demo_end;
};
// savegame settings
struct {
char *savegame_fmt_legacy;
};
// global settings
struct {
float demo_delay;

View file

@ -1007,7 +1007,7 @@ bool S_FrontEndCheck(void)
g_SavedGames = 0;
for (int32_t i = 0; i < MAX_REQUESTER_ITEMS; i++) {
char file_name[80];
sprintf(file_name, "savegame.%d", i);
sprintf(file_name, g_GameFlow.savegame_fmt_legacy, i);
if (!File_Exists(file_name)) {
Requester_AddItem(
@ -1045,7 +1045,7 @@ bool S_FrontEndCheck(void)
bool S_SaveGame(const int32_t slot_num)
{
char file_name[80];
sprintf(file_name, "savegame.%d", slot_num);
sprintf(file_name, g_GameFlow.savegame_fmt_legacy, slot_num);
MYFILE *const fp = File_Open(file_name, FILE_OPEN_WRITE);
if (fp == nullptr) {
@ -1094,7 +1094,7 @@ bool S_SaveGame(const int32_t slot_num)
bool S_LoadGame(const int32_t slot_num)
{
char file_name[80];
sprintf(file_name, "savegame.%d", slot_num);
sprintf(file_name, g_GameFlow.savegame_fmt_legacy, slot_num);
MYFILE *const fp = File_Open(file_name, FILE_OPEN_READ);
if (fp == nullptr) {