Skip to content

Commit 27d23d9

Browse files
committed
vpslot_workbench vpslot_toolkit optional/mandatory
optional/mandatory have better support for extended features than assign, and this cleans up the slot loading codes to match the other slots. The `WORKBENCH` flag feels really redundant, but cleaning that up would be a larger project.
1 parent fd3a4b2 commit 27d23d9

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/veh_type.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,21 +386,14 @@ void vpart_info::load( const JsonObject &jo, const std::string &src )
386386
}
387387

388388
if( has_flag( "WORKBENCH" ) ) {
389-
if( !workbench_info ) {
390-
workbench_info.emplace();
391-
}
392-
393-
JsonObject wb_jo = jo.get_object( "workbench" );
394-
assign( wb_jo, "multiplier", workbench_info->multiplier, strict );
395-
assign( wb_jo, "mass", workbench_info->allowed_mass, strict );
396-
assign( wb_jo, "volume", workbench_info->allowed_volume, strict );
389+
mandatory( jo, was_loaded, "workbench", workbench_info );
397390
}
398391

399392
if( has_flag( "VEH_TOOLS" ) ) {
400393
if( !toolkit_info ) {
401394
toolkit_info.emplace();
402395
}
403-
assign( jo, "allowed_tools", toolkit_info->allowed_types, strict );
396+
toolkit_info->deserialize( jo );
404397
}
405398

406399
if( has_flag( "TRANSFORM_TERRAIN" ) || has_flag( "CRASH_TERRAIN_AROUND" ) ) {
@@ -466,6 +459,20 @@ void vpslot_rotor::deserialize( const JsonObject &jo )
466459
was_loaded = true;
467460
}
468461

462+
void vpslot_workbench::deserialize( const JsonObject &jo )
463+
{
464+
optional( jo, false, "multiplier", multiplier, 1.f );
465+
optional( jo, false, "mass", allowed_mass, 0_gram );
466+
optional( jo, false, "volume", allowed_volume, 0_ml );
467+
}
468+
469+
void vpslot_toolkit::deserialize( const JsonObject &jo )
470+
{
471+
optional( jo, was_loaded, "allowed_tools", allowed_types, string_id_reader<itype> {} );
472+
473+
was_loaded = true;
474+
}
475+
469476
void vpart_info::set_flag( const std::string &flag )
470477
{
471478
flags.insert( flag );

src/veh_type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,16 @@ struct vpslot_workbench {
174174
// Mass/volume allowed before a crafting speed penalty is applied
175175
units::mass allowed_mass = 0_gram;
176176
units::volume allowed_volume = 0_ml;
177+
178+
void deserialize( const JsonObject &jo );
177179
};
178180

179181
struct vpslot_toolkit {
182+
bool was_loaded = false;
183+
180184
std::set<itype_id> allowed_types;
185+
186+
void deserialize( const JsonObject &jo );
181187
};
182188

183189
struct vpslot_terrain_transform {

0 commit comments

Comments
 (0)