Skip to content

Commit

Permalink
handle null index writes
Browse files Browse the repository at this point in the history
  • Loading branch information
amylizzle committed Jan 28, 2024
1 parent f3efcb7 commit baecb4b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/ExportText.dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,10 @@
.2
type = /datum
"}
ASSERT(F.ExportText("list") ~= list_match)

F.cd = "dir6"
F << "test"
F.cd = "/"
ASSERT(F.ExportText("dir6") == ". = \"test\"\nsubdir6 = 321\n")
ASSERT(F.ExportText("dir6/subdir6/") == ". = 321\n")
13 changes: 11 additions & 2 deletions OpenDreamRuntime/Objects/Types/DreamObjectSavefile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,18 @@ public DreamValue GetSavefileValue(string? index) {
}

public void SetSavefileValue(string? index, DreamValue value) {
// TODO reimplement nulling values when cd
if (index == null) {
CurrentDir[$".{CurrentDir.Count}"] = SerializeDreamValue(value);
SFDreamJsonValue newCurrentDir = SerializeDreamValue(value);
foreach(var key in CurrentDir.Keys) {
newCurrentDir[key] = CurrentDir[key];
}

if(CurrentDir != _rootNode) {
SFDreamJsonValue parentDir = SeekTo("..");
parentDir[CurrentPath.Split("/").Last()] = newCurrentDir;
} else {
CurrentDir = _rootNode = newCurrentDir;
}
_savefilesToFlush.Add(this);
return;
}
Expand Down
3 changes: 1 addition & 2 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeSavefile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ private static string ExportTextInternal(DreamObjectSavefile savefile, int inden
var value = savefile.CurrentDir;
var key = savefile.CurrentPath.Split('/').Last();
if(indent == int.MinValue){
if(!string.IsNullOrEmpty(key)) //if this is is the start and not root dir, use . = value syntax
key = ".";
key = ".";
indent = 0; //either way, set indent to 0 so we know we're not at the start anymore
}
switch(value) {
Expand Down

0 comments on commit baecb4b

Please sign in to comment.