Skip to content

Commit

Permalink
Remove constructor item(JsonObject&)
Browse files Browse the repository at this point in the history
It forwards to `item:deserialize`, so one can call it directly.
This is now done in `inventory::json_load_items`. The loop there is also simpler.
Exceptions will now go up the stack automatically. This is fine because all JSON related code needs to expect exceptions from malformed JSON.
  • Loading branch information
BevapDin committed Dec 3, 2017
1 parent 7c5b13b commit aa63623
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
5 changes: 0 additions & 5 deletions src/item.cpp
Expand Up @@ -201,11 +201,6 @@ item item::make_corpse( const mtype_id& mt, int turn, const std::string &name )
return result;
}

item::item(JsonObject &jo)
{
deserialize(jo);
}

item& item::convert( const itype_id& new_type )
{
type = find_type( new_type );
Expand Down
2 changes: 0 additions & 2 deletions src/item.h
Expand Up @@ -210,8 +210,6 @@ class item : public JsonSerializer, public JsonDeserializer, public visitable<it
item( const itype_id& id, int turn, solitary_tag );
item( const itype *type, int turn, solitary_tag );

item( JsonObject &jo );

/**
* Filter converting this instance to another type preserving all other aspects
* @param new_type the type id to convert to
Expand Down
13 changes: 5 additions & 8 deletions src/savegame_json.cpp
Expand Up @@ -1287,14 +1287,11 @@ void inventory::json_save_items(JsonOut &json) const

void inventory::json_load_items(JsonIn &jsin)
{
try {
JsonArray ja = jsin.get_array();
while ( ja.has_more() ) {
JsonObject jo = ja.next_object();
add_item(item( jo ), true, false);
}
} catch( const JsonError &jsonerr ) {
debugmsg("bad inventory json:\n%s", jsonerr.c_str() );
jsin.start_array();
while( !jsin.end_array() ) {
item tmp;
tmp.deserialize( jsin );
add_item( tmp );
}
}

Expand Down

0 comments on commit aa63623

Please sign in to comment.