Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] implement datum saving #1546

Closed
wants to merge 19 commits into from
Closed
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
15 changes: 15 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,13 +8,27 @@
// 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)

// 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")
Expand Down
62 changes: 62 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/ExportAndImportText.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/obj/savetest
var/obj/savetest/recurse = null
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/obj/savetest/O = new() //create a test object
O.name = "test"
O.recurse = O

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()

ASSERT(F.ExportText("dir6/subdir6") == ". = 321\n")
ASSERT(F.ExportText("dir6/subdir6/") == ". = 321\n")
ASSERT(F.ExportText("dir6") == "\nsubdir6 = 321\n")


var/import_test = @{"
dir1 = 1080
dir2 = "object(\".0\")"
dir4 = "the afternoon of the 3rd"
dir6
subdir6 = 321
subsubdir
key = "value"
dir7 = null
"}

var/savefile/F2 = new()
F2.ImportText("/",import_test)
world.log << F2.ExportText()
ASSERT(F2["dir1"] == 1080)
ASSERT(F2["dir2"] == "object(\".0\")")
ASSERT(F2["dir4"] == "the afternoon of the 3rd")
ASSERT(F2["dir6/subdir6"] == 321)
ASSERT(F2["dir6/subdir6/subsubdir/key"] == "value")
ASSERT(F2["dir7"] == null)
43 changes: 43 additions & 0 deletions Content.Tests/DMProject/Tests/Savefile/datum_saving.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/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

/datum/foo/Write(savefile/F)
. = ..(F)
ASSERT(F["type"] == /datum/foo)
ASSERT(F["current_map"] == null)
ASSERT(F["default_cube"] == null)

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

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 = new()
S["mapdata"] >> W

// load test
ASSERT(istype(W))
ASSERT(W.best_map == "pl_pier")
ASSERT(W.worst_map == null)
ASSERT(W.null_me == null)

fdel("delme.sav")
return TRUE

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
Loading