From c99784606bc1777bca12c687b54682c605a1fd96 Mon Sep 17 00:00:00 2001 From: amy Date: Sun, 15 Mar 2026 13:00:47 +0000 Subject: [PATCH 1/2] order don't matter --- .../Tests/Savefile/BasicReadAndWrite.dm | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm b/Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm index 476ed78733..18a90b0b1e 100644 --- a/Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm +++ b/Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm @@ -50,11 +50,17 @@ //Test dir S.cd = "/" var/dir = S.dir - ASSERT(dir ~= list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2")) + var/dir_compare = list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2") + ASSERT(length(dir) == length(dir_compare)) + for(var/d in dir) + ASSERT(d in dir_compare) //test add dir += "test/beep" - ASSERT(dir ~= list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2", "test")) + dir_compare = list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2", "test") + ASSERT(length(dir) == length(dir_compare)) + for(var/d in dir) + ASSERT(d in dir_compare) ASSERT(S["test"] == null) S.cd = "test" ASSERT(dir ~= list("beep")) @@ -62,15 +68,24 @@ //test del S.cd = "/" dir -= "test" - ASSERT(dir ~= list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2")) + dir_compare = list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2") + ASSERT(length(dir) == length(dir_compare)) + for(var/d in dir) + ASSERT(d in dir_compare) //test rename and null dir[1] = "CBA" - ASSERT(dir ~= list("CBA", "DEF", "notakey", "pathymcpathface", "pie", "pie2")) - ASSERT(S["CBA"] == null) + dir_compare = list("CBA", "DEF", "notakey", "pathymcpathface", "pie", "pie2") + ASSERT(length(dir) == length(dir_compare)) + for(var/d in dir) + ASSERT(d in dir_compare) + + ASSERT(S["CBA"] == 5) fdel("savefile.sav") +#ifdef OPENDREAM +//we're only testing this in OD for now, BYOND reports an error but not a runtime when reading from a malformed save file("badsavefile.sav") << "hey wait, this isn't json! oh well, better fail miserably and die" var/savefile/fail @@ -80,3 +95,4 @@ ASSERT(isnull(fail)) ASSERT(fail == null) fdel("badsavefile.sav") +#endif \ No newline at end of file From f7467978f0793864623c607e0b4e18730b6cd9cf Mon Sep 17 00:00:00 2001 From: amy Date: Sun, 15 Mar 2026 13:39:33 +0000 Subject: [PATCH 2/2] rename doesn't null values --- OpenDreamRuntime/Objects/Types/DreamList.cs | 2 +- OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/OpenDreamRuntime/Objects/Types/DreamList.cs b/OpenDreamRuntime/Objects/Types/DreamList.cs index db80bf71b5..d400e262f4 100644 --- a/OpenDreamRuntime/Objects/Types/DreamList.cs +++ b/OpenDreamRuntime/Objects/Types/DreamList.cs @@ -1645,7 +1645,7 @@ public override void SetValue(DreamValue key, DreamValue value, bool allowGrowth if (index < 1 || index > backedSaveFile.CurrentDir.Count) throw new Exception($"Out of bounds index on savefile dir list: {index}"); - backedSaveFile.RenameAndNullSavefileValue(backedSaveFile.CurrentDir.Keys.ElementAt(index - 1), valueStr); + backedSaveFile.RenameSavefileValue(backedSaveFile.CurrentDir.Keys.ElementAt(index - 1), valueStr); } public override void AddValue(DreamValue value) { diff --git a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs index a9c18b6f3d..53397ccf0d 100644 --- a/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs +++ b/OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs @@ -311,15 +311,10 @@ public void RemoveSavefileValue(string index) { } } - public void RenameAndNullSavefileValue(string index, string newIndex) { + public void RenameSavefileValue(string index, string newIndex) { if (CurrentDir.TryGetValue(index, out var value)) { CurrentDir.Remove(index); - SfDreamDir newDir = new SfDreamDir(); - foreach (var key in value.Keys) { - newDir[key] = value[key]; - } - - CurrentDir[newIndex] = newDir; + CurrentDir[newIndex] = value; SavefilesToFlush.Add(this); } }