From 560c51cf27717c726407cae8db300e14c219cf07 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Sun, 16 Aug 2026 20:20:34 -0500 Subject: [PATCH] Drop default-skip behavior from savejson write macros Only reads should fall back to a default when a key is missing; writes should always emit the field so the saved JSON is a complete record. --- src/dusk/save/savejson.h | 58 ++++++++++++++---------------------- src/dusk/save/savesettings.c | 2 +- src/dusk/save/saveslot.c | 2 +- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/src/dusk/save/savejson.h b/src/dusk/save/savejson.h index 2cb558fc..49e23c91 100644 --- a/src/dusk/save/savejson.h +++ b/src/dusk/save/savejson.h @@ -56,15 +56,13 @@ if(!hasInt32(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes an int32_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes an int32_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeInt32(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_int(doc, object, key, (int64_t)(value)) +#define writeInt32(key, value) \ + yyjson_mut_obj_add_int(doc, object, key, (int64_t)(value)) /** * Reads an int32_t from the current JSON object, falling back to the given @@ -94,15 +92,13 @@ if(!hasUInt32(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes a uint32_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes a uint32_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeUInt32(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) +#define writeUInt32(key, value) \ + yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) /** * Reads a uint32_t from the current JSON object, falling back to the given @@ -132,15 +128,13 @@ if(!hasUInt8(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes a uint8_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes a uint8_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeUInt8(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) +#define writeUInt8(key, value) \ + yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) /** * Reads a uint8_t from the current JSON object, falling back to the given @@ -170,15 +164,13 @@ if(!hasInt64(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes an int64_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes an int64_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeInt64(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_sint(doc, object, key, (int64_t)(value)) +#define writeInt64(key, value) \ + yyjson_mut_obj_add_sint(doc, object, key, (int64_t)(value)) /** * Reads an int64_t from the current JSON object, falling back to the given @@ -208,15 +200,13 @@ if(!hasUInt64(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes a uint64_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes a uint64_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeUInt64(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) +#define writeUInt64(key, value) \ + yyjson_mut_obj_add_uint(doc, object, key, (uint64_t)(value)) /** * Reads a uint64_t from the current JSON object, falling back to the given @@ -246,15 +236,13 @@ if(!hasFloat(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes a float_t to the current JSON object, omitting the key entirely - * if it matches the given default. + * Writes a float_t to the current JSON object. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeFloat(key, value, def) \ - if((value) != (def)) yyjson_mut_obj_add_real(doc, object, key, (double)(value)) +#define writeFloat(key, value) \ + yyjson_mut_obj_add_real(doc, object, key, (double)(value)) /** * Reads a float_t from the current JSON object, falling back to the given @@ -284,16 +272,14 @@ if(!hasString(key)) errorThrow("Save JSON missing '%s' key", key) /** - * Writes a string to the current JSON object, omitting the key entirely if - * it matches the given default. The string is copied, so it does not need - * to outlive the JSON document. + * Writes a string to the current JSON object. The string is copied, so it + * does not need to outlive the JSON document. * * @param key The key to write to. * @param value The value to write. - * @param def The default value; if value equals this, the key is omitted. */ -#define writeString(key, value, def) \ - if(!stringEquals((value), (def))) yyjson_mut_obj_add_strcpy(doc, object, key, value) +#define writeString(key, value) \ + yyjson_mut_obj_add_strcpy(doc, object, key, value) /** * Reads a string from the current JSON object into dest, falling back to diff --git a/src/dusk/save/savesettings.c b/src/dusk/save/savesettings.c index 90f805e9..b2488760 100644 --- a/src/dusk/save/savesettings.c +++ b/src/dusk/save/savesettings.c @@ -25,7 +25,7 @@ errorret_t saveSettingsWriteJSON( assertNotNull(doc, "Doc cannot be null"); assertNotNull(object, "Object cannot be null"); - writeInt32("someSetting", settings->someSetting, 0); + writeInt32("someSetting", settings->someSetting); errorOk(); } diff --git a/src/dusk/save/saveslot.c b/src/dusk/save/saveslot.c index cd6b6a69..dc51b6a2 100644 --- a/src/dusk/save/saveslot.c +++ b/src/dusk/save/saveslot.c @@ -31,7 +31,7 @@ errorret_t saveSlotWriteJSON( assertNotNull(doc, "Doc cannot be null"); assertNotNull(object, "Object cannot be null"); - writeString("name", slot->name, ""); + writeString("name", slot->name); writeTime("time", slot->time); errorOk();