Skip to content

Commit

Permalink
Actually read JSON object member instead of only checking their exist…
Browse files Browse the repository at this point in the history
…ence.

This ensures the member type is checked and reported if it does not fit the expected type.

It also means `"foo": false` is properly recognized as such (instead of being interpreted the same as `"foo": true`).
  • Loading branch information
BevapDin committed Dec 25, 2019
1 parent 1db2da5 commit 8a944ce
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ conditional_t<T>::conditional_t( const JsonObject &jo )
set_npc_role_nearby( jo );
} else if( jo.has_int( "npc_allies" ) ) {
set_npc_allies( jo );
} else if( jo.has_int( "npc_service" ) ) {
} else if( jo.get_bool( "npc_service", false ) ) {
set_npc_available();
} else if( jo.has_int( "u_has_cash" ) ) {
set_u_has_cash( jo );
Expand Down
2 changes: 1 addition & 1 deletion src/flag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void json_flag::load( const JsonObject &jo )

// FIXME: most flags have a "context" field that isn't used for anything
// Test for it here to avoid errors about unvisited members
jo.has_member( "context" );
jo.get_member( "context" );
}

void json_flag::check_consistency()
Expand Down
2 changes: 1 addition & 1 deletion src/mission_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ mission_target_params mission_util::parse_mission_om_target( const JsonObject &j
if( jo.has_string( "om_terrain_match_type" ) ) {
p.overmap_terrain_match_type = jo.get_enum_value<ot_match_type>( "om_terrain_match_type" );
}
if( jo.has_bool( "origin_npc" ) ) {
if( jo.get_bool( "origin_npc", false ) ) {
p.origin_u = false;
}
if( jo.has_string( "om_terrain_replace" ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2886,11 +2886,11 @@ dynamic_line_t::dynamic_line_t( const JsonObject &jo )
}
return all_lines;
};
} else if( jo.has_member( "give_hint" ) ) {
} else if( jo.get_bool( "give_hint", false ) ) {
function = [&]( const dialogue & ) {
return get_hint();
};
} else if( jo.has_member( "use_reason" ) ) {
} else if( jo.get_bool( "use_reason", false ) ) {
function = [&]( const dialogue & d ) {
std::string tmp = d.reason;
d.reason.clear();
Expand Down

0 comments on commit 8a944ce

Please sign in to comment.