Skip to content

Commit

Permalink
Convert islot_seed to generic_factory
Browse files Browse the repository at this point in the history
  • Loading branch information
anothersimulacrum authored and kevingranade committed May 11, 2020
1 parent 6913049 commit 22331cc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
22 changes: 14 additions & 8 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1955,14 +1955,20 @@ void Item_factory::load_comestible( const JsonObject &jo, const std::string &src
}
}

void Item_factory::load( islot_seed &slot, const JsonObject &jo, const std::string & )
void islot_seed::load( const JsonObject &jo )
{
assign( jo, "grow", slot.grow, false, 1_days );
slot.fruit_div = jo.get_int( "fruit_div", 1 );
jo.read( "plant_name", slot.plant_name );
slot.fruit_id = jo.get_string( "fruit" );
slot.spawn_seeds = jo.get_bool( "seeds", true );
slot.byproducts = jo.get_string_array( "byproducts" );
assign( jo, "grow", grow, false, 1_days );
optional( jo, was_loaded, "fruit_div", fruit_div, 1 );
mandatory( jo, was_loaded, "plant_name", plant_name );
mandatory( jo, was_loaded, "fruit", fruit_id );
optional( jo, was_loaded, "seeds", spawn_seeds, true );
optional( jo, was_loaded, "byproducts", byproducts );
}

void islot_seed::deserialize( JsonIn &jsin )
{
const JsonObject jo = jsin.get_object();
load( jo );
}

void Item_factory::load( islot_gunmod &slot, const JsonObject &jo, const std::string &src )
Expand Down Expand Up @@ -2442,7 +2448,7 @@ void Item_factory::load_basic_info( const JsonObject &jo, itype &def, const std:
load_slot_optional( def.gun, jo, "gun_data", src );
load_slot_optional( def.bionic, jo, "bionic_data", src );
assign( jo, "ammo_data", def.ammo, src == "dda" );
load_slot_optional( def.seed, jo, "seed_data", src );
assign( jo, "seed_data", def.seed, src == "dda" );
load_slot_optional( def.artifact, jo, "artifact_data", src );
load_slot_optional( def.brewable, jo, "brewable", src );
load_slot_optional( def.fuel, jo, "fuel", src );
Expand Down
1 change: 0 additions & 1 deletion src/item_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ class Item_factory
void load( islot_magazine &slot, const JsonObject &jo, const std::string &src );
void load( islot_battery &slot, const JsonObject &jo, const std::string &src );
void load( islot_bionic &slot, const JsonObject &jo, const std::string &src );
void load( islot_seed &slot, const JsonObject &jo, const std::string &src );
void load( islot_artifact &slot, const JsonObject &jo, const std::string &src );
void load( relic &slot, const JsonObject &jo, const std::string &src );

Expand Down
8 changes: 7 additions & 1 deletion src/itype.h
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ struct islot_ammo : common_ranged_data {
*/
cata::optional<bool> force_stat_display;

bool was_loaded;
bool was_loaded = false;

void load( const JsonObject &jo );
void deserialize( JsonIn &jsin );
Expand All @@ -745,6 +745,12 @@ struct islot_bionic {
};

struct islot_seed {
// Generic factory stuff
bool was_loaded = false;

void load( const JsonObject &jo );
void deserialize( JsonIn &jsin );

/**
* Time it takes for a seed to grow (based of off a season length of 91 days).
*/
Expand Down

0 comments on commit 22331cc

Please sign in to comment.