Skip to content

Commit 737c759

Browse files
committed
vpslot_terrain_transform optional/mandatory
optional/mandatory have better support for extended JSON features, and this cleans up the loading code. As with the other slots, this slot doesn't really need a flag to specify it, it could just use the existance of a transform_terrain member.
1 parent 27d23d9 commit 737c759

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/veh_type.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,7 @@ void vpart_info::load( const JsonObject &jo, const std::string &src )
400400
if( !transform_terrain_info ) {
401401
transform_terrain_info.emplace();
402402
}
403-
JsonObject jttd = jo.get_object( "transform_terrain" );
404-
vpslot_terrain_transform &vtt = *transform_terrain_info;
405-
optional( jttd, was_loaded, "pre_flags", vtt.pre_flags, {} );
406-
optional( jttd, was_loaded, "post_terrain", vtt.post_terrain );
407-
optional( jttd, was_loaded, "post_furniture", vtt.post_furniture );
408-
if( jttd.has_string( "post_field" ) ) {
409-
mandatory( jttd, was_loaded, "post_field", vtt.post_field );
410-
mandatory( jttd, was_loaded, "post_field_intensity", vtt.post_field_intensity );
411-
mandatory( jttd, was_loaded, "post_field_age", vtt.post_field_age );
412-
}
403+
mandatory( jo, was_loaded, "transform_terrain", transform_terrain_info );
413404
}
414405
}
415406

@@ -473,6 +464,18 @@ void vpslot_toolkit::deserialize( const JsonObject &jo )
473464
was_loaded = true;
474465
}
475466

467+
void vpslot_terrain_transform::deserialize( const JsonObject &jo )
468+
{
469+
optional( jo, false, "pre_flags", pre_flags, {} );
470+
optional( jo, false, "post_terrain", post_terrain );
471+
optional( jo, false, "post_furniture", post_furniture );
472+
if( jo.has_string( "post_field" ) ) {
473+
mandatory( jo, false, "post_field", post_field );
474+
mandatory( jo, false, "post_field_intensity", post_field_intensity );
475+
mandatory( jo, false, "post_field_age", post_field_age );
476+
}
477+
}
478+
476479
void vpart_info::set_flag( const std::string &flag )
477480
{
478481
flags.insert( flag );

src/veh_type.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ struct vpslot_terrain_transform {
194194
//Both only defined if(post_field)
195195
int post_field_intensity;
196196
time_duration post_field_age;
197+
198+
void deserialize( const JsonObject &jo );
197199
};
198200

199201
struct vp_control_req {

0 commit comments

Comments
 (0)