Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,42 @@
//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"))

//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
Expand All @@ -80,3 +95,4 @@
ASSERT(isnull(fail))
ASSERT(fail == null)
fdel("badsavefile.sav")
#endif
2 changes: 1 addition & 1 deletion OpenDreamRuntime/Objects/Types/DreamList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 2 additions & 7 deletions OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Loading