Add player name field to save file, save it out as a round-trip test

Adds savefile_t.playerName (SAVE_PLAYER_NAME_MAX) serialized via the
existing saveFileReadString/WriteString helpers, and stamps + saves it in
rpgInit() as a test that the save system now persists actual game data,
not just the header/version. Verified manually: written bytes end in
"Dusk\0" immediately after the version field, and loading it back returns
the same string.
This commit is contained in:
2026-08-04 08:59:29 -05:00
parent 7a03ef8eaf
commit 24badd06a5
3 changed files with 15 additions and 0 deletions
+8
View File
@@ -18,6 +18,8 @@
#include "util/memory.h"
#include "util/string.h"
#include "assert/assert.h"
#include "save/save.h"
#include "error/error.h"
#include "ui/rpg/uiemoji.h"
@@ -51,6 +53,12 @@ errorret_t rpgInit(void) {
backpackAdd(ITEM_ID_POTATO, 3);
backpackAdd(ITEM_ID_APPLE, 8);
// TEST: Verify the save system round-trips real game data, not just the
// header/version. Remove once there's an actual name-entry flow.
savefile_t *saveFile = saveGet(0);
stringCopy(saveFile->playerName, "Dusk", SAVE_PLAYER_NAME_MAX);
errorCatch(errorPrint(saveWrite(0)));
// All Good!
errorOk();
}
+5
View File
@@ -20,6 +20,9 @@
/** Maximum number of independent save slots supported. */
#define SAVE_FILE_COUNT_MAX 3
/** Maximum length of a saved player name, including the null terminator. */
#define SAVE_PLAYER_NAME_MAX 32
typedef struct {
/** Magic header bytes read from the file; must equal SAVE_FILE_HEADER. */
char_t header[SAVE_FILE_HEADER_SIZE];
@@ -27,4 +30,6 @@ typedef struct {
uint32_t version;
/** Runtime flag - true if this slot was successfully loaded or written. */
bool_t exists;
/** The player's saved name. */
char_t playerName[SAVE_PLAYER_NAME_MAX];
} savefile_t;
+2
View File
@@ -330,11 +330,13 @@ errorret_t saveStreamWriteDateImpl(
errorret_t saveFileLoad(savestream_t *stream, savefile_t *file) {
saveFileReadHeader(stream, file->header);
saveFileReadVersion(stream, &file->version);
saveFileReadString(stream, file->playerName, SAVE_PLAYER_NAME_MAX);
errorOk();
}
errorret_t saveFileWrite(savestream_t *stream, savefile_t *file) {
saveFileWriteHeader(stream, file->header);
saveFileWriteVersion(stream, &file->version);
saveFileWriteString(stream, file->playerName, SAVE_PLAYER_NAME_MAX);
errorOk();
}