Make party and save-slot init/new-game operate on SAVE.slot directly
party.c's functions no longer take a party_t* - they always operate on SAVE.slot.party, since gameplay only ever has one active party. That forced the same change on saveSlotInit/saveSlotNewGame (they called partyInit/partyAddMember internally), so those are now parameterless too, always resetting/seeding SAVE.slot. Callers building a save at a specific index (new-game creation, slot deletion) now set SAVE.slotCurrent first instead of building an independent local struct - safe since the select-save screen is only ever reached before any gameplay starts. saveSlotWriteJSON/saveSlotReadJSON deliberately keep their explicit saveslot_t* parameter - they're genuine serialization primitives used by the save-device layer and tests against arbitrary structs, unrelated to the single-current-party assumption. saveSlotReadJSON's internal reset is now a plain memset instead of delegating to the now-global-only saveSlotInit(). Updates test_save/test_savedevice/test_savedevicelinux/test_saveslot for the new signatures. Note: test_savedevice/test_savedevicelinux/test_save have pre-existing failures in this sandbox unrelated to this change - savetestfixture.c swaps $HOME, but saveDeviceLinuxGetDirectory actually derives the save path from ASSET.baseDirectory (the executable's own location), so the fixture's sandboxing never actually applies. test_ saveslot.c (which doesn't depend on that fixture) passes 15/15. Co-Authored-By: Claude Sonnet 5 <[email protected]>
This commit is contained in:
+18
-12
@@ -298,7 +298,7 @@ static void test_saveSaveSlot_invalidSlotIndexAsserts(void **state) {
|
||||
static void test_saveSaveSlot_success(void **state) {
|
||||
makeDeviceAvailable();
|
||||
SAVE.slotCurrent = 1;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
stringCopy(
|
||||
SAVE.slot.cachedData.name, "Hero", sizeof(SAVE.slot.cachedData.name)
|
||||
);
|
||||
@@ -311,8 +311,9 @@ static void test_saveSaveSlot_success(void **state) {
|
||||
assert_true(stringEquals(SAVE.caches[1].name, "Hero"));
|
||||
assert_int_equal(SAVE.caches[1].playerLevel, 12);
|
||||
|
||||
// No pre-init needed - saveSlotReadJSON() (via saveDeviceSlotRead) fully
|
||||
// resets/overwrites its destination struct regardless of prior content.
|
||||
saveslot_t onDisk;
|
||||
saveSlotInit(&onDisk);
|
||||
errorret_t readRet = saveDeviceSlotRead(&SAVE.devices[0], &onDisk, 1);
|
||||
assert_true(errorIsOk(readRet));
|
||||
assert_true(stringEquals(onDisk.cachedData.name, "Hero"));
|
||||
@@ -331,15 +332,20 @@ static void test_saveLoadSlot_invalidSlotIndexAsserts(void **state) {
|
||||
static void test_saveLoadSlot_success(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
saveslot_t onDisk;
|
||||
saveSlotInit(&onDisk);
|
||||
stringCopy(onDisk.cachedData.name, "Zelda", sizeof(onDisk.cachedData.name));
|
||||
onDisk.cachedData.playerLevel = 30;
|
||||
errorret_t writeRet = saveDeviceSlotWrite(&SAVE.devices[0], &onDisk, 2);
|
||||
// Write slot 2's on-disk file via SAVE.slot itself (saveSlotInit() only
|
||||
// ever operates on SAVE.slot now), then reset it again below - the
|
||||
// write and the load-under-test don't overlap in time.
|
||||
SAVE.slotCurrent = 2;
|
||||
saveSlotInit();
|
||||
stringCopy(
|
||||
SAVE.slot.cachedData.name, "Zelda", sizeof(SAVE.slot.cachedData.name)
|
||||
);
|
||||
SAVE.slot.cachedData.playerLevel = 30;
|
||||
errorret_t writeRet = saveDeviceSlotWrite(&SAVE.devices[0], &SAVE.slot, 2);
|
||||
assert_true(errorIsOk(writeRet));
|
||||
|
||||
SAVE.slotCurrent = 2;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
SAVE.slotDirty = true;
|
||||
|
||||
errorret_t ret = saveLoadSlot();
|
||||
@@ -365,7 +371,7 @@ static void test_saveLoadSlot_deviceReadFails_cacheStaysStale(void **state) {
|
||||
fclose(file);
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
SAVE.caches[0].playerLevel = 77;// sentinel
|
||||
|
||||
errorret_t ret = saveLoadSlot();
|
||||
@@ -385,7 +391,7 @@ static void test_saveLoadAllSlots_loadsAllAndEndsAtLastIndex(void **state) {
|
||||
|
||||
for(uint8_t i = 0; i < SAVE_SLOT_COUNT; i++) {
|
||||
SAVE.slotCurrent = i;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
SAVE.slot.cachedData.playerLevel = (int32_t)(i + 1);
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
@@ -404,7 +410,7 @@ static void test_saveLoadAllSlots_missingFileLeavesInitDefaults(void **state) {
|
||||
makeDeviceAvailable();
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
SAVE.slot.cachedData.playerLevel = 5;
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
@@ -427,7 +433,7 @@ static void test_saveLoadAllSlots_middleSlotCorrupt_stopsAtFailingIndex(
|
||||
makeDeviceAvailable();
|
||||
|
||||
SAVE.slotCurrent = 0;
|
||||
saveSlotInit(&SAVE.slot);
|
||||
saveSlotInit();
|
||||
errorret_t saveRet = saveSaveSlot();
|
||||
assert_true(errorIsOk(saveRet));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user