diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 11:59:24 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-23 11:59:24 +0200 |
commit | a62bd981c2a973952f3f5e22ca768dd961991d21 (patch) | |
tree | 5f4bd867de7982247a913a4d3cee44c44f2c5248 /serialize/tile-atlas.cpp | |
parent | 9dec9084e80987749c698b9ff0bcd39df5c8a988 (diff) |
allow serializing empty shared_ptr
Diffstat (limited to 'serialize/tile-atlas.cpp')
-rw-r--r-- | serialize/tile-atlas.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index d5350851..fcbb371d 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -15,16 +15,23 @@ using proxy_atlas = std::tuple<std::string, Vector2ub>; void adl_serializer<std::shared_ptr<tile_atlas>>::to_json(json& j, const std::shared_ptr<const tile_atlas>& x) { - fm_assert(x); using nlohmann::to_json; - to_json(j, proxy_atlas{x->name(), x->num_tiles2()}); + if (!x) + j = nullptr; + else + to_json(j, proxy_atlas{x->name(), x->num_tiles2()}); } void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std::shared_ptr<tile_atlas>& x) { - proxy_atlas proxy = j; - const auto& [name, num_tiles] = proxy; - x = loader.tile_atlas(name, num_tiles); + if (j.is_null()) + x = nullptr; + else + { + proxy_atlas proxy = j; + const auto& [name, num_tiles] = proxy; + x = loader.tile_atlas(name, num_tiles); + } } } // namespace nlohmann |