Skip to content

Commit

Permalink
Fully implement /savefile (except ImportText() because fuck it) (#…
Browse files Browse the repository at this point in the history
…1554)

Co-authored-by: LetterN <[email protected]>
Co-authored-by: wixoa <[email protected]>
Co-authored-by: amylizzle <[email protected]>
  • Loading branch information
4 people authored Mar 2, 2024
1 parent e2a403f commit 39f99ac
Show file tree
Hide file tree
Showing 16 changed files with 929 additions and 125 deletions.
60 changes: 60 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/BasicReadAndWrite.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/datum/foobar

/proc/RunTest()
var/savefile/S = new("savefile.sav")
Expand All @@ -7,15 +8,74 @@
// Indexing the object to write/read the savefile
S["ABC"] = 5
ASSERT(V == null)
ASSERT(S["ABC"] == 5)
V = S["ABC"]
ASSERT(V == 5)

// << and >> can do the same thing
S["DEF"] << 10
S["DEF"] >> V
ASSERT(S["DEF"] == 10)
ASSERT(V == 10)
S["notakey"] >> V
ASSERT(V == null)

// test path
S["pathymcpathface"] << /datum/foobar
ASSERT(S["pathymcpathface"] == /datum/foobar)

// test list()
var/list/array = list("3.14159", "pizza")
S["pie"] << array
ASSERT(S["pie"] ~= array)
var/list/assoc = list("6.28" = "pizza", "aaaaa" = "bbbbbbb")
S["pie2"] << assoc
ASSERT(S["pie2"] ~= assoc)

// Shouldn't evaluate CRASH
S2?["ABC"] << CRASH("rhs should not evaluate due to null-conditional")

// Test EOF
S.cd = "DEF"
var/out
ASSERT(S.eof == 0)
S >> out
ASSERT(out == 10)
ASSERT(S.eof == 1)
S.eof = -1
S.cd = "/"
ASSERT(S["DEF"] == null)

//Test dir
S.cd = "/"
var/dir = S.dir
ASSERT(dir ~= list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2"))

//test add
dir += "test/beep"
ASSERT(dir ~= list("ABC", "DEF", "notakey", "pathymcpathface", "pie", "pie2", "test"))
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"))

//test rename and null
dir[1] = "CBA"
ASSERT(dir ~= list("CBA", "DEF", "notakey", "pathymcpathface", "pie", "pie2"))
ASSERT(S["CBA"] == null)

fdel("savefile.sav")

file("badsavefile.sav") << "hey wait, this isn't json! oh well, better fail miserably and die"

var/savefile/fail
try
fail = new("badsavefile.sav")
catch(var/exception/e)
ASSERT(isnull(fail))
ASSERT(fail == null)
fdel("badsavefile.sav")
52 changes: 52 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/DatumSaving.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/datum/foo
var/best_map = "pl_upward" // mutated by RunTest(), should save
var/worst_map = "pl_badwater" // same as, should not be saved
var/null_me = "ok" // should save as null

var/tmp/current_map = "yeah" // tmp, should not save
var/const/default_cube = "delete it" // const, should not save

New(args)
proc_call_order_check += list("New")
..()

Read(savefile/F)
proc_call_order_check += list("Read")
..()

Write(savefile/F)
proc_call_order_check += list("Write")
..()

/var/static/proc_call_order_check = list()


/proc/RunTest()
var/savefile/S = new()

var/datum/foo/F = new()
F.best_map = "pl_pier"
F.null_me = null

S["mapdata"] << F

// test the savefile's contents
ASSERT(S["mapdata/.0/type"] == /datum/foo)
ASSERT(S["mapdata/.0/best_map"] == "pl_pier")
ASSERT(S["mapdata/.0/null_me"] == null)
ASSERT(S["mapdata/.0/worst_map"] == null)
ASSERT(S["mapdata/.0/current_map"] == null)
ASSERT(S["mapdata/.0/default_cube"] == null)

var/datum/foo/W
S["mapdata"] >> W

// load test
ASSERT(istype(W))
ASSERT(W != F) //they are equivalent, but not the same datum
ASSERT(W.best_map == "pl_pier")
ASSERT(W.worst_map == "pl_badwater")
ASSERT(W.null_me == null)

ASSERT(proc_call_order_check ~= list("New","Write","New","Read"))

37 changes: 37 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/ExportText.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/obj/savetest
var/obj/savetest/recurse = null

/proc/RunTest()
var/obj/savetest/O = new() //create a test object
O.name = "test"
//O.recurse = O //TODO

var/savefile/F = new() //create a temporary savefile

F["dir"] = O
F["dir2"] = "object(\".0\")"
F["dir3"] = 1080
F["dir4"] = "the afternoon of the 3rd"
var/savefile/P = new() //nested savefile
P["subsavedir1"] = O
P["subsavedir2"] = "butts"
P["subsavedir3"] = 123

F["dir5"] = P
F["dir6/subdir6"] = 321
F["dir7"] = null
F["dirIcon"] = new /icon()
F["list"] << list("1",2,"three"=3,4, new /datum(), new /datum(), list(1,2,3, new /datum()))

ASSERT(F.dir ~= list("dir","dir2","dir3","dir4","dir5","dir6","dir7","dirIcon","list"))
ASSERT(F.ExportText("dir6/subdir6") == ". = 321\n")
ASSERT(F.ExportText("dir6/subdir6/") == ". = 321\n")
ASSERT(F.ExportText("dir6") == "\nsubdir6 = 321\n")
var/list_match = {". = list("1",2,"three" = 3,4,object(".0"),object(".1"),list(1,2,3,object(".2")))\n.0\n\ttype = /datum\n.1\n\ttype = /datum\n.2\n\ttype = /datum\n"}
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")
44 changes: 44 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/SaveAndLoad.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/datum/foobar

/proc/RunTest()
var/savefile/S = new("savefile.sav")
var/savefile/S2 = null


// Indexing the object to write/read the savefile
S["ABC"] = 5
ASSERT(S["ABC"] == 5)

S["DEF"] = 10
ASSERT(S["DEF"] == 10)

// test path
S["pathymcpathface"] << /datum/foobar
ASSERT(S["pathymcpathface"] == /datum/foobar)

// test list()
var/list/array = list("3.14159", "pizza")
S["pie"] << array
ASSERT(S["pie"] ~= array)

// test assoc list()
var/list/assoc = list("6.28" = "pizza", "aaaaa" = "bbbbbbb")
S["pie2"] << assoc
ASSERT(S["pie2"] ~= assoc)

S.Flush()

// test loading
//gotta copy it because otherwise we're accessing the cache
fcopy("savefile.sav", "savefile2.sav")
ASSERT(fexists("savefile2.sav"))
S2 = new("savefile2.sav")
ASSERT(S2["ABC"] == 5)
ASSERT(S2["DEF"] == 10)
ASSERT(S2["pathymcpathface"] == /datum/foobar)
ASSERT(S2["pie"] ~= array)
ASSERT(S2["pie2"] ~= assoc)


fdel("savefile.sav")
fdel("savefile2.sav")
30 changes: 30 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/SequenceRead.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/datum/test_holder
var/test1
var/test2
var/test3
var/test4

/proc/RunTest()
var/savefile/F = new("savtest.sav")
F["savtest1"] = "beep"
F["savtest2"] = "boop"
F["savtest3"] = "berp"
F["savtest4"] = "borp"
del(F)
fcopy("savtest.sav", "savtest2.sav")
var/savefile/F2 = new("savtest2.sav")
var/datum/test_holder/T = new()
T.test1 = F2["savtest1"]
T.test2 = F2["savtest2"]

F2["savtest1"] >> T.test1
F2["savtest2"] >> T.test2
F2["savtest3"] >> T.test3
F2["savtest4"] >> T.test4

ASSERT(T.test1 == "beep")
ASSERT(T.test2 == "boop")
ASSERT(T.test3 == "berp")
ASSERT(T.test4 == "borp")
fdel("savtest.sav")
fdel("savtest2.sav")
10 changes: 0 additions & 10 deletions Content.Tests/DMProject/Tests/Savefile/override_datum.dm

This file was deleted.

1 change: 0 additions & 1 deletion DMCompiler/DM/Builders/DMProcBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,6 @@ public void ProcessStatementInput(DMASTProcStatementInput statementInput) {
_proc.Input(leftRef, rightRef);

_proc.AddLabel(leftEndLabel);
_proc.PopReference(rightRef);
_proc.AddLabel(rightEndLabel);
}

Expand Down
4 changes: 2 additions & 2 deletions DMCompiler/DMStandard/Types/Atoms/Mob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

var/client/client
var/key
var/ckey
var/tmp/ckey

var/list/group as opendream_unimplemented
var/tmp/list/group as opendream_unimplemented

var/see_invisible = 0
var/see_infrared = 0 as opendream_unimplemented
Expand Down
10 changes: 5 additions & 5 deletions DMCompiler/DMStandard/Types/Atoms/Movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

var/animate_movement = FORWARD_STEPS as opendream_unimplemented
var/list/locs = null as opendream_unimplemented
var/glide_size
var/glide_size = 0
var/step_size as opendream_unimplemented
var/bound_x as opendream_unimplemented
var/bound_y as opendream_unimplemented
var/bound_width as opendream_unimplemented
var/bound_height as opendream_unimplemented
var/tmp/bound_x as opendream_unimplemented
var/tmp/bound_y as opendream_unimplemented
var/tmp/bound_width as opendream_unimplemented
var/tmp/bound_height as opendream_unimplemented

//Undocumented var. "[x],[y]" or "[x],[y] to [x2],[y2]" based on bound_* vars
var/bounds as opendream_unimplemented
Expand Down
18 changes: 9 additions & 9 deletions DMCompiler/DMStandard/Types/Atoms/_Atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
var/suffix = null as opendream_unimplemented

// The initialization/usage of these lists is handled internally by the runtime
var/list/verbs = null
var/tmp/list/verbs = null
var/list/contents = null
var/list/overlays = null
var/list/underlays = null
var/list/vis_locs = null as opendream_unimplemented
var/tmp/list/vis_locs = null as opendream_unimplemented
var/list/vis_contents = null

var/atom/loc
var/tmp/atom/loc
var/dir = SOUTH
var/x = 0
var/y = 0
var/z = 0
var/tmp/x = 0
var/tmp/y = 0
var/tmp/z = 0
var/pixel_x = 0
var/pixel_y = 0
var/pixel_z = 0 as opendream_unimplemented
Expand Down Expand Up @@ -53,9 +53,9 @@
var/step_x as opendream_unimplemented
var/step_y as opendream_unimplemented
var/render_source
var/mouse_drag_pointer as opendream_unimplemented
var/mouse_drop_pointer as opendream_unimplemented
var/mouse_over_pointer as opendream_unimplemented
var/tmp/mouse_drag_pointer as opendream_unimplemented
var/tmp/mouse_drop_pointer as opendream_unimplemented
var/tmp/mouse_over_pointer as opendream_unimplemented
var/render_target
var/vis_flags as opendream_unimplemented

Expand Down
2 changes: 0 additions & 2 deletions DMCompiler/DMStandard/Types/Datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@
proc/Topic(href, href_list)

proc/Read(savefile/F)
set opendream_unimplemented = TRUE

proc/Write(savefile/F)
set opendream_unimplemented = TRUE
Loading

0 comments on commit 39f99ac

Please sign in to comment.