Skip to content

Commit

Permalink
Change load_damage_instance to take a const reference
Browse files Browse the repository at this point in the history
And use a range-based loop.
  • Loading branch information
BevapDin committed Dec 18, 2019
1 parent 10d7ac2 commit 84a53d7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/damage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ void damage_instance::deserialize( JsonIn &jsin )
JsonObject jo = jsin.get_object();
damage_units = load_damage_instance( jo ).damage_units;
} else if( jsin.test_array() ) {
JsonArray ja = jsin.get_array();
damage_units = load_damage_instance( ja ).damage_units;
damage_units = load_damage_instance( jsin.get_array() ).damage_units;
} else {
jsin.error( "Expected object or array for damage_instance" );
}
Expand Down Expand Up @@ -314,11 +313,10 @@ damage_instance load_damage_instance( const JsonObject &jo )
return di;
}

damage_instance load_damage_instance( JsonArray &jarr )
damage_instance load_damage_instance( const JsonArray &jarr )
{
damage_instance di;
while( jarr.has_more() ) {
JsonObject curr = jarr.next_object();
for( const JsonObject &curr : jarr ) {
di.damage_units.push_back( load_damage_unit( curr ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/damage.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ std::string name_by_dt( const damage_type &dt );
const skill_id &skill_by_dt( damage_type dt );

damage_instance load_damage_instance( const JsonObject &jo );
damage_instance load_damage_instance( JsonArray &jarr );
damage_instance load_damage_instance( const JsonArray &jarr );

resistances load_resistances_instance( const JsonObject &jo );

Expand Down
3 changes: 1 addition & 2 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,8 +2035,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
assign( jo, "insulation", def.insulation_factor );

if( jo.has_member( "thrown_damage" ) ) {
JsonArray jarr = jo.get_array( "thrown_damage" );
def.thrown_damage = load_damage_instance( jarr );
def.thrown_damage = load_damage_instance( jo.get_array( "thrown_damage" ) );
} else {
// TODO: Move to finalization
def.thrown_damage.clear();
Expand Down
3 changes: 1 addition & 2 deletions src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ void melee_actor::load_internal( const JsonObject &obj, const std::string & )
{
// Optional:
if( obj.has_array( "damage_max_instance" ) ) {
JsonArray arr = obj.get_array( "damage_max_instance" );
damage_max_instance = load_damage_instance( arr );
damage_max_instance = load_damage_instance( obj.get_array( "damage_max_instance" ) );
} else if( obj.has_object( "damage_max_instance" ) ) {
damage_max_instance = load_damage_instance( obj );
}
Expand Down
3 changes: 1 addition & 2 deletions src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,7 @@ void mtype::load( const JsonObject &jo, const std::string &src )

// TODO: make this work with `was_loaded`
if( jo.has_array( "melee_damage" ) ) {
JsonArray arr = jo.get_array( "melee_damage" );
melee_damage = load_damage_instance( arr );
melee_damage = load_damage_instance( jo.get_array( "melee_damage" ) );
} else if( jo.has_object( "melee_damage" ) ) {
melee_damage = load_damage_instance( jo );
}
Expand Down
6 changes: 2 additions & 4 deletions src/mutation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,14 @@ static mut_attack load_mutation_attack( const JsonObject &jo )
jo.read( "chance", ret.chance );

if( jo.has_array( "base_damage" ) ) {
JsonArray jo_dam = jo.get_array( "base_damage" );
ret.base_damage = load_damage_instance( jo_dam );
ret.base_damage = load_damage_instance( jo.get_array( "base_damage" ) );
} else if( jo.has_object( "base_damage" ) ) {
JsonObject jo_dam = jo.get_object( "base_damage" );
ret.base_damage = load_damage_instance( jo_dam );
}

if( jo.has_array( "strength_damage" ) ) {
JsonArray jo_dam = jo.get_array( "strength_damage" );
ret.strength_damage = load_damage_instance( jo_dam );
ret.strength_damage = load_damage_instance( jo.get_array( "strength_damage" ) );
} else if( jo.has_object( "strength_damage" ) ) {
JsonObject jo_dam = jo.get_object( "strength_damage" );
ret.strength_damage = load_damage_instance( jo_dam );
Expand Down

0 comments on commit 84a53d7

Please sign in to comment.