8
8
#include < sstream>
9
9
#include < unordered_map>
10
10
11
- #include " assign.h"
12
11
#include " cached_options.h"
13
12
#include " calendar.h"
14
13
#include " cartesian_product.h"
@@ -55,8 +54,6 @@ static const itype_id itype_hotplate( "hotplate" );
55
54
static const std::string flag_FULL_MAGAZINE ( " FULL_MAGAZINE" );
56
55
57
56
58
- recipe::recipe () : skill_used( skill_id::NULL_ID() ) {}
59
-
60
57
int recipe::get_difficulty ( const Character &crafter ) const
61
58
{
62
59
if ( is_practice () && skill_used ) {
@@ -155,10 +152,8 @@ bool recipe::has_flag( const std::string &flag_name ) const
155
152
return flags.count ( flag_name );
156
153
}
157
154
158
- void recipe::load ( const JsonObject &jo, const std::string & src )
155
+ void recipe::load ( const JsonObject &jo, const std::string_view src )
159
156
{
160
- bool strict = src == " dda" ;
161
-
162
157
abstract = jo.has_string ( " abstract" );
163
158
164
159
const std::string type = jo.get_string ( " type" );
@@ -218,7 +213,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
218
213
}
219
214
220
215
if ( jo.has_bool ( " obsolete" ) ) {
221
- assign ( jo, " obsolete" , obsolete );
216
+ mandatory ( jo, was_loaded , " obsolete" , obsolete );
222
217
}
223
218
224
219
// If it's an obsolete recipe, we don't need any more data, skip loading
@@ -230,25 +225,28 @@ void recipe::load( const JsonObject &jo, const std::string &src )
230
225
time = to_moves<int >( read_from_json_string<time_duration>( jo.get_member ( " time" ),
231
226
time_duration::units ) );
232
227
}
233
- assign ( jo, " difficulty" , difficulty, strict, 0 , MAX_SKILL );
234
- assign ( jo, " flags" , flags );
228
+ optional ( jo, was_loaded, " difficulty" , difficulty, numeric_bound_reader< int > { 0 , MAX_SKILL} );
229
+ optional ( jo, was_loaded , " flags" , flags );
235
230
236
231
// automatically set contained if we specify as container
237
- assign ( jo, " contained" , contained, strict );
238
- contained |= assign ( jo, " container" , container, strict );
232
+ optional ( jo, was_loaded, " contained" , contained, false );
233
+ if ( jo.has_member ( " container" ) ) {
234
+ contained = true ;
235
+ optional ( jo, was_loaded, " container" , container, itype_id::NULL_ID () );
236
+ }
239
237
optional ( jo, false , " container_variant" , container_variant );
240
- assign ( jo, " sealed" , sealed, strict );
238
+ optional ( jo, was_loaded, " sealed" , sealed, true );
241
239
242
240
if ( jo.has_array ( " batch_time_factors" ) ) {
243
241
JsonArray batch = jo.get_array ( " batch_time_factors" );
244
242
batch_rscale = batch.get_int ( 0 ) / 100.0 ;
245
243
batch_rsize = batch.get_int ( 1 );
246
244
}
247
245
248
- assign ( jo, " charges" , charges );
249
- assign ( jo, " result_mult" , result_mult );
246
+ optional ( jo, was_loaded , " charges" , charges );
247
+ optional ( jo, was_loaded, " result_mult" , result_mult, 1 );
250
248
251
- assign ( jo, " skill_used" , skill_used, strict );
249
+ optional ( jo, was_loaded, " skill_used" , skill_used, skill_id::NULL_ID () );
252
250
253
251
if ( jo.has_member ( " skills_required" ) ) {
254
252
JsonArray sk = jo.get_array ( " skills_required" );
@@ -273,7 +271,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
273
271
274
272
// simplified autolearn sets requirements equal to required skills at finalization
275
273
if ( jo.has_bool ( " autolearn" ) ) {
276
- assign ( jo, " autolearn" , autolearn );
274
+ optional ( jo, was_loaded, " autolearn" , autolearn, false );
277
275
278
276
} else if ( jo.has_array ( " autolearn" ) ) {
279
277
autolearn = true ;
@@ -286,9 +284,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
286
284
mandatory ( jo, was_loaded, " activity_level" , exertion, activity_level_reader{} );
287
285
288
286
// Never let the player have a debug or NPC recipe
289
- if ( jo.has_bool ( " never_learn" ) ) {
290
- assign ( jo, " never_learn" , never_learn );
291
- }
287
+ optional ( jo, was_loaded, " never_learn" , never_learn, false );
292
288
293
289
if ( jo.has_member ( " decomp_learn" ) ) {
294
290
learn_by_disassembly.clear ();
@@ -297,7 +293,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
297
293
if ( !skill_used ) {
298
294
jo.throw_error ( " decomp_learn specified with no skill_used" );
299
295
}
300
- assign ( jo, " decomp_learn" , learn_by_disassembly[skill_used] );
296
+ optional ( jo, false , " decomp_learn" , learn_by_disassembly[skill_used] );
301
297
302
298
} else if ( jo.has_array ( " decomp_learn" ) ) {
303
299
for ( JsonArray arr : jo.get_array ( " decomp_learn" ) ) {
@@ -335,10 +331,10 @@ void recipe::load( const JsonObject &jo, const std::string &src )
335
331
336
332
mandatory ( jo, was_loaded, " category" , category );
337
333
mandatory ( jo, was_loaded, " subcategory" , subcategory );
338
- assign ( jo, " description" , description, strict );
334
+ optional ( jo, was_loaded, " description" , description );
339
335
340
336
if ( jo.has_bool ( " reversible" ) ) {
341
- assign ( jo, " reversible" , reversible, strict );
337
+ mandatory ( jo, was_loaded, " reversible" , reversible );
342
338
} else if ( jo.has_object ( " reversible" ) ) {
343
339
reversible = true ;
344
340
// Convert duration to time in moves
@@ -363,10 +359,10 @@ void recipe::load( const JsonObject &jo, const std::string &src )
363
359
byproduct_group = item_group::load_item_group ( jo.get_member ( " byproduct_group" ),
364
360
" collection" , " byproducts of recipe " + id.str () );
365
361
}
366
- assign ( jo, " construction_blueprint" , blueprint );
362
+ optional ( jo, was_loaded , " construction_blueprint" , blueprint );
367
363
if ( !blueprint.is_empty () ) {
368
- assign ( jo, " blueprint_name" , bp_name );
369
- assign ( jo, " blueprint_parameter_names" , bp_parameter_names );
364
+ optional ( jo, was_loaded , " blueprint_name" , bp_name );
365
+ optional ( jo, was_loaded , " blueprint_parameter_names" , bp_parameter_names );
370
366
bp_resources.clear ();
371
367
for ( const std::string resource : jo.get_array ( " blueprint_resources" ) ) {
372
368
bp_resources.emplace_back ( resource );
@@ -423,7 +419,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
423
419
mandatory ( jo, false , " name" , name_ );
424
420
mandatory ( jo, was_loaded, " category" , category );
425
421
mandatory ( jo, was_loaded, " subcategory" , subcategory );
426
- assign ( jo, " description" , description, strict );
422
+ optional ( jo, was_loaded, " description" , description );
427
423
mandatory ( jo, was_loaded, " practice_data" , practice_data );
428
424
429
425
if ( jo.has_member ( " byproducts" ) ) {
@@ -446,7 +442,7 @@ void recipe::load( const JsonObject &jo, const std::string &src )
446
442
mandatory ( jo, false , " name" , name_ );
447
443
mandatory ( jo, was_loaded, " category" , category );
448
444
mandatory ( jo, was_loaded, " subcategory" , subcategory );
449
- assign ( jo, " description" , description, strict );
445
+ optional ( jo, was_loaded, " description" , description );
450
446
mandatory ( jo, was_loaded, " nested_category_data" , nested_category_data );
451
447
452
448
} else {
0 commit comments