diff --git a/src/item_factory.cpp b/src/item_factory.cpp index 330e06294a70b..46001d688232f 100644 --- a/src/item_factory.cpp +++ b/src/item_factory.cpp @@ -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 ) @@ -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 ); diff --git a/src/item_factory.h b/src/item_factory.h index 71799c09e1ac1..ad5c858e6fc5a 100644 --- a/src/item_factory.h +++ b/src/item_factory.h @@ -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 ); diff --git a/src/itype.h b/src/itype.h index e509e49824620..0eebe18271791 100644 --- a/src/itype.h +++ b/src/itype.h @@ -723,7 +723,7 @@ struct islot_ammo : common_ranged_data { */ cata::optional force_stat_display; - bool was_loaded; + bool was_loaded = false; void load( const JsonObject &jo ); void deserialize( JsonIn &jsin ); @@ -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). */