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

Fix item_location (de)serialization handling #35593

Merged
merged 1 commit into from
Nov 18, 2019
Merged
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
12 changes: 11 additions & 1 deletion src/item_location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ class item_location::impl::item_on_person : public item_location::impl

void serialize( JsonOut &js ) const override {
if( !ensure_who_unpacked() ) {
// Write an invalid item_location to avoid invalid json
js.start_object();
js.member( "type", "null" );
js.end_object();
return;
}
js.start_object();
Expand Down Expand Up @@ -541,7 +545,13 @@ void item_location::deserialize( JsonIn &js )

if( type == "character" ) {
character_id who_id;
obj.read( "character", who_id );
if( obj.has_member( "character" ) ) {
obj.read( "character", who_id );
} else {
// This is for migrating saves before npc item locations were supported and all
// character item locations were assumed to be on g->u
who_id = g->u.getID();
}
ptr.reset( new impl::item_on_person( who_id, idx ) );

} else if( type == "map" ) {
Expand Down