Skip to content

Commit 793b978

Browse files
authored
update serialize docs (#81)
1 parent 7212cca commit 793b978

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

mods/savedata.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ struct MyCustomSaveData {
2323

2424
template<>
2525
struct matjson::Serialize<MyCustomSaveData> {
26-
static MyCustomSaveData from_json(matjson::Value const& value) {
27-
return MyCustomSaveData {
28-
.x = value["x"].as_int(),
29-
.y = value["y"].as_int()
30-
};
26+
static Result<MyCustomSaveData> fromJson(matjson::Value const& value) {
27+
GEODE_UNWRAP_INTO(int x, value["x"].asInt());
28+
GEODE_UNWRAP_INTO(int y, value["y"].asInt());
29+
return Ok(MyCustomSaveData{x, y});
3130
}
3231

33-
static matjson::Value to_json(MyCustomSaveData const& value) {
34-
auto obj = matjson::Object();
32+
static matjson::Value toJson(MyCustomSaveData const& value) {
33+
auto obj = matjson::Value();
3534
obj["x"] = value.x;
3635
obj["y"] = value.y;
3736
return obj;
@@ -69,3 +68,4 @@ Mods should save other data (files, backups, etc.) to their specific save direct
6968
It should be noted that a mod can have a good reason to save data elsewhere - for example a mod that saves created levels as individual files instead of CCLocalLevels would be justified in saving directly under the GD save folder instead of the mod save folder, since the data its saving is not related to the mod.
7069
7170
If you have data that the user should be able to edit (for example config files), these should go in the directory provided by `Mod::get()->getConfigDir()`. **Do not flood the main GD folder with config files or save data** - this will almost certainly get your mod rejected from the index unless you have a _very_ good reason for doing so!
71+

0 commit comments

Comments
 (0)