|
8 | 8 | #include <utility>
|
9 | 9 | #include <vector>
|
10 | 10 |
|
11 |
| -#include "assign.h" |
12 | 11 | #include "body_part_set.h"
|
13 | 12 | #include "creature.h"
|
14 | 13 | #include "debug.h"
|
@@ -285,6 +284,21 @@ const std::vector<body_part_type> &body_part_type::get_all()
|
285 | 284 | return body_part_factory.get_all();
|
286 | 285 | }
|
287 | 286 |
|
| 287 | +class encumbrance_per_weight_reader : public generic_typed_reader<encumbrance_per_weight_reader> |
| 288 | +{ |
| 289 | + public: |
| 290 | + std::pair<units::mass, int> get_next( const JsonValue &jv ) const { |
| 291 | + std::pair<units::mass, int> ret; |
| 292 | + if( !jv.test_object() ) { |
| 293 | + jv.throw_error( "Invalid format" ); |
| 294 | + } |
| 295 | + JsonObject entry = jv.get_object(); |
| 296 | + entry.read( "weight", ret.first, true ); |
| 297 | + entry.read( "encumbrance", ret.second, true ); |
| 298 | + return ret; |
| 299 | + } |
| 300 | +}; |
| 301 | + |
288 | 302 | void body_part_type::load( const JsonObject &jo, std::string_view )
|
289 | 303 | {
|
290 | 304 | mandatory( jo, was_loaded, "id", id );
|
@@ -459,18 +473,8 @@ void body_part_type::load( const JsonObject &jo, std::string_view )
|
459 | 473 |
|
460 | 474 | mandatory( jo, was_loaded, "sub_parts", sub_parts );
|
461 | 475 |
|
462 |
| - if( jo.has_array( "encumbrance_per_weight" ) ) { |
463 |
| - const JsonArray &jarr = jo.get_array( "encumbrance_per_weight" ); |
464 |
| - for( const JsonObject jval : jarr ) { |
465 |
| - units::mass weight = 0_gram; |
466 |
| - int encumbrance = 0; |
467 |
| - |
468 |
| - assign( jval, "weight", weight, true ); |
469 |
| - mandatory( jval, was_loaded, "encumbrance", encumbrance ); |
470 |
| - |
471 |
| - encumbrance_per_weight.insert( std::pair<units::mass, int>( weight, encumbrance ) ); |
472 |
| - } |
473 |
| - } |
| 476 | + optional( jo, was_loaded, "encumbrance_per_weight", encumbrance_per_weight, |
| 477 | + encumbrance_per_weight_reader{} ); |
474 | 478 | }
|
475 | 479 |
|
476 | 480 | void bp_onhit_effect::load( const JsonObject &jo )
|
|
0 commit comments