|
50 | 50 | #include "wcwidth.h"
|
51 | 51 |
|
52 | 52 | class emit;
|
| 53 | +class proficiency; |
53 | 54 |
|
54 | 55 | namespace
|
55 | 56 | {
|
@@ -204,28 +205,10 @@ static void parse_vp_reqs( const JsonObject &obj, const vpart_id &id, const std:
|
204 | 205 | }
|
205 | 206 | }
|
206 | 207 |
|
207 |
| -static void parse_vp_control_reqs( const JsonObject &obj, const vpart_id &id, |
208 |
| - std::string_view key, |
209 |
| - vp_control_req &req ) |
| 208 | +void vp_control_req::deserialize( const JsonObject &jo ) |
210 | 209 | {
|
211 |
| - if( !obj.has_object( key ) ) { |
212 |
| - return; |
213 |
| - } |
214 |
| - JsonObject src = obj.get_object( key ); |
215 |
| - |
216 |
| - JsonArray sk = src.get_array( "skills" ); |
217 |
| - if( !sk.empty() ) { |
218 |
| - req.skills.clear(); |
219 |
| - for( JsonArray cur : sk ) { |
220 |
| - if( cur.size() != 2 ) { |
221 |
| - debugmsg( "vpart '%s' has requirement with invalid skill entry", id.str() ); |
222 |
| - continue; |
223 |
| - } |
224 |
| - req.skills.emplace( skill_id( cur.get_string( 0 ) ), cur.get_int( 1 ) ); |
225 |
| - } |
226 |
| - } |
227 |
| - |
228 |
| - optional( src, false, "proficiencies", req.proficiencies ); |
| 210 | + optional( jo, false, "skills", skills, weighted_string_id_reader<skill_id, int> { std::nullopt} ); |
| 211 | + optional( jo, false, "proficiencies", proficiencies, string_id_reader<proficiency> {} ); |
229 | 212 | }
|
230 | 213 |
|
231 | 214 | void vehicles::parts::load( const JsonObject &jo, const std::string &src )
|
@@ -327,8 +310,8 @@ void vpart_info::load( const JsonObject &jo, const std::string &src )
|
327 | 310 | if( jo.has_member( "control_requirements" ) ) {
|
328 | 311 | JsonObject reqs = jo.get_object( "control_requirements" );
|
329 | 312 |
|
330 |
| - parse_vp_control_reqs( reqs, id, "air", control_air ); |
331 |
| - parse_vp_control_reqs( reqs, id, "land", control_land ); |
| 313 | + optional( reqs, false, "air", control_air ); |
| 314 | + optional( reqs, false, "land", control_land ); |
332 | 315 | }
|
333 | 316 |
|
334 | 317 | optional( jo, was_loaded, "looks_like", looks_like, looks_like );
|
|
0 commit comments